Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add opencv4 into the dependency list for ROS2 #324

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cv_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else()
endif()

find_package(sensor_msgs REQUIRED)
find_package(OpenCV 3 REQUIRED
find_package(OpenCV 4 REQUIRED
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line force to OpenCV4 , there is no option for version 3.

You should do something like:

find_package(OpenCV 4 QUIET opencv_core opencv_core)
if(NOT OpenCV_FOUND)
  find_package(OpenCV 3 REQUIRED opencv_core opencv_core)
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really works, I checked it and uploaded one new patch.
@ahcorde

COMPONENTS
opencv_core
opencv_imgproc
Expand Down
10 changes: 7 additions & 3 deletions cv_bridge/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ if(PYTHON_VERSION_MAJOR VERSION_EQUAL 3)
add_definitions(-DPYTHON3)
endif()

if(OpenCV_VERSION_MAJOR VERSION_EQUAL 3)
add_library(${PROJECT_NAME}_boost module.cpp module_opencv3.cpp)
else()
if(OpenCV_VERSION_MAJOR VERSION_EQUAL 4)
add_definitions(-DOPENCV_VERSION_4)
endif()

if(OpenCV_VERSION_MAJOR VERSION_LESS 3)
add_library(${PROJECT_NAME}_boost module.cpp module_opencv2.cpp)
else()
add_library(${PROJECT_NAME}_boost module.cpp module_opencv3.cpp)
endif()
target_link_libraries(${PROJECT_NAME}_boost
${PYTHON_LIBRARIES}
Expand Down
9 changes: 7 additions & 2 deletions cv_bridge/src/module_opencv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class NumpyAllocator : public MatAllocator
NumpyAllocator() {stdAllocator = Mat::getStdAllocator();}
~NumpyAllocator() {}

// To compile openCV3 with OpenCV4 APIs.
#ifndef OPENCV_VERSION_4
#define AccessFlag int
#endif

UMatData * allocate(PyObject * o, int dims, const int * sizes, int type, size_t * step) const
{
UMatData * u = new UMatData(this);
Expand All @@ -115,7 +120,7 @@ class NumpyAllocator : public MatAllocator
}

UMatData * allocate(
int dims0, const int * sizes, int type, void * data, size_t * step, int flags,
int dims0, const int * sizes, int type, void * data, size_t * step, AccessFlag flags,
UMatUsageFlags usageFlags) const
{
if (data != 0) {
Expand Down Expand Up @@ -148,7 +153,7 @@ class NumpyAllocator : public MatAllocator
return allocate(o, dims0, sizes, type, step);
}

bool allocate(UMatData * u, int accessFlags, UMatUsageFlags usageFlags) const
bool allocate(UMatData * u, AccessFlag accessFlags, UMatUsageFlags usageFlags) const
{
return stdAllocator->allocate(u, accessFlags, usageFlags);
}
Expand Down