Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions cv_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,6 @@ if(ANDROID)
set(CV_BRIDGE_DISABLE_PYTHON ON)
endif()

if(CV_BRIDGE_DISABLE_PYTHON)
find_package(Boost REQUIRED)
set(boost_python_target "")
else()
find_package(Python3 REQUIRED COMPONENTS Development NumPy)
find_package(Boost QUIET)
if(Boost_VERSION_STRING VERSION_LESS "1.67")
# This is a bit of a hack to suppress a warning
# No header defined for python3; skipping header check
# Which should only affect Boost versions < 1.67
# Resolution for newer versions:
# https://gitlab.kitware.com/cmake/cmake/issues/16391
set(_Boost_PYTHON3_HEADERS "boost/python.hpp")
find_package(Boost REQUIRED COMPONENTS python3)
set(boost_python_target "Boost::python3")
else()
find_package(Boost REQUIRED COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})
set(boost_python_target "Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
endif()
endif()

find_package(rclcpp REQUIRED)
find_package(rcpputils REQUIRED)
find_package(sensor_msgs REQUIRED)
Expand Down
4 changes: 0 additions & 4 deletions cv_bridge/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<buildtool_depend>ament_cmake_ros</buildtool_depend>
<buildtool_depend>python_cmake_module</buildtool_depend>

<build_depend>libboost-dev</build_depend>
<build_depend>libboost-python-dev</build_depend>

<depend>libopencv-dev</depend>
<depend>python3-numpy</depend>
<depend>rclcpp</depend>
Expand All @@ -30,7 +27,6 @@
<depend>python3-opencv</depend>

<exec_depend>ament_index_python</exec_depend>
<exec_depend>libboost-python</exec_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
Expand Down
2 changes: 1 addition & 1 deletion cv_bridge/python/cv_bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# python bindings
# This try is just to satisfy doc jobs that are built differently.
try:
from cv_bridge.boost.cv_bridge_boost import cvtColorForDisplay, getCvType
from cv_bridge.nanobind.cv_bridge_nanobind import cvtColorForDisplay, getCvType
except ImportError:
pass
10 changes: 5 additions & 5 deletions cv_bridge/python/cv_bridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def dtype_with_channels_to_cvtype2(self, dtype, n_channels):
return '%sC%d' % (self.numpy_type_to_cvtype[dtype.name], n_channels)

def cvtype2_to_dtype_with_channels(self, cvtype):
from cv_bridge.boost.cv_bridge_boost import CV_MAT_CNWrap, CV_MAT_DEPTHWrap
from cv_bridge.nanobind.cv_bridge_nanobind import CV_MAT_CNWrap, CV_MAT_DEPTHWrap
return self.cvdepth_to_numpy_depth[CV_MAT_DEPTHWrap(cvtype)], CV_MAT_CNWrap(cvtype)

def encoding_to_cvtype2(self, encoding):
from cv_bridge.boost.cv_bridge_boost import getCvType
from cv_bridge.nanobind.cv_bridge_nanobind import getCvType

try:
return getCvType(encoding)
Expand Down Expand Up @@ -135,7 +135,7 @@ def compressed_imgmsg_to_cv2(self, cmprs_img_msg, desired_encoding='passthrough'
if desired_encoding == 'passthrough':
return im

from cv_bridge.boost.cv_bridge_boost import cvtColor2
from cv_bridge.nanobind.cv_bridge_nanobind import cvtColor2

try:
res = cvtColor2(im, 'bgr8', desired_encoding)
Expand Down Expand Up @@ -183,12 +183,12 @@ def imgmsg_to_cv2(self, img_msg, desired_encoding='passthrough'):

# If the byte order is different between the message and the system.
if img_msg.is_bigendian == (sys.byteorder == 'little'):
im = im.byteswap().newbyteorder()
im = im.byteswap().view(im.dtype.newbyteorder())

if desired_encoding == 'passthrough':
Comment thread
Benjamin-Tan marked this conversation as resolved.
return im

from cv_bridge.boost.cv_bridge_boost import cvtColor2
from cv_bridge.nanobind.cv_bridge_nanobind import cvtColor2

try:
res = cvtColor2(im, img_msg.encoding, desired_encoding)
Expand Down
27 changes: 17 additions & 10 deletions cv_bridge/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
rclcpp::rclcpp
)
target_link_libraries(${PROJECT_NAME} PRIVATE
Boost::headers
rcpputils::rcpputils)

install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME}
Expand All @@ -32,20 +31,28 @@ install(FILES
DESTINATION include/${PROJECT_NAME}/${PROJECT_NAME})

if(NOT CV_BRIDGE_DISABLE_PYTHON)
Python3_add_library(${PROJECT_NAME}_boost MODULE module.cpp module_opencv4.cpp)
target_link_libraries(${PROJECT_NAME}_boost PRIVATE
find_package(Python 3 COMPONENTS Interpreter Development REQUIRED)
include(FetchContent)
FetchContent_Declare(
nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
GIT_TAG v2.9.2
)

FetchContent_MakeAvailable(nanobind)
nanobind_add_module(${PROJECT_NAME}_nanobind MODULE module.cpp)
target_link_libraries(${PROJECT_NAME}_nanobind PRIVATE
${PROJECT_NAME}
${boost_python_target}
Python3::NumPy)
target_compile_definitions(${PROJECT_NAME}_boost PRIVATE PYTHON3)
)
target_compile_definitions(${PROJECT_NAME}_nanobind PRIVATE PYTHON3)

if(OpenCV_VERSION_MAJOR VERSION_EQUAL 4)
target_compile_definitions(${PROJECT_NAME}_boost PRIVATE OPENCV_VERSION_4)
target_compile_definitions(${PROJECT_NAME}_nanobind PRIVATE OPENCV_VERSION_4)
endif()

set_target_properties(${PROJECT_NAME}_boost PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost/
set_target_properties(${PROJECT_NAME}_nanobind PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/nanobind/
PREFIX ""
)
install(TARGETS ${PROJECT_NAME}_boost DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}/boost/)
install(TARGETS ${PROJECT_NAME}_nanobind DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}/nanobind/)
endif()
1 change: 0 additions & 1 deletion cv_bridge/src/cv_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include <cv_bridge/cv_bridge.hpp>
#include <cv_bridge/rgb_colors.hpp>
#include <boost/endian/conversion.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <sensor_msgs/image_encodings.hpp>
Expand Down
Loading