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

OpenCV4 compatibility #259

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion cv_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ if(NOT ANDROID)
else()
find_package(Boost REQUIRED)
endif()
find_package(OpenCV 3 REQUIRED

find_package(OpenCV REQUIRED
COMPONENTS
opencv_core
opencv_imgproc
Expand Down
6 changes: 1 addition & 5 deletions cv_bridge/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ 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()
add_library(${PROJECT_NAME}_boost module.cpp module_opencv2.cpp)
endif()
add_library(${PROJECT_NAME}_boost module.cpp module_opencv.cpp)
target_link_libraries(${PROJECT_NAME}_boost ${Boost_LIBRARIES}
${catkin_LIBRARIES}
${PYTHON_LIBRARIES}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ class NumpyAllocator : public MatAllocator
return u;
}

#if CV_MAJOR_VERSION > 3
UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const CV_OVERRIDE
#else
UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const
#endif
{
if( data != 0 )
{
CV_Error(Error::StsAssert, "The data should normally be NULL!");
// issue #6969: CV_Error(Error::StsAssert, "The data should normally be NULL!");
// probably this is safe to do in such extreme case
return stdAllocator->allocate(dims0, sizes, type, data, step, flags, usageFlags);
}
Expand All @@ -130,22 +134,38 @@ class NumpyAllocator : public MatAllocator
_sizes[i] = sizes[i];
if( cn > 1 )
_sizes[dims++] = cn;
#if CV_MAJOR_VERSION > 3
PyObject* o = PyArray_SimpleNew(dims, _sizes.data(), typenum);
#else
PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
#endif
if(!o)
CV_Error_(Error::StsError, ("The numpy array of typenum=%d, ndims=%d can not be created", typenum, dims));
return allocate(o, dims0, sizes, type, step);
}

#if CV_MAJOR_VERSION > 3
bool allocate(UMatData* u, AccessFlag accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE
#else
bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const
#endif
{
return stdAllocator->allocate(u, accessFlags, usageFlags);
}

#if CV_MAJOR_VERSION > 3
void deallocate(UMatData* u) const CV_OVERRIDE
#else
void deallocate(UMatData* u) const
#endif
{
if(u)
if(!u)
return;
PyEnsureGIL gil;
CV_Assert(u->urefcount >= 0);
CV_Assert(u->refcount >= 0);
if(u->refcount == 0)
{
PyEnsureGIL gil;
PyObject* o = (PyObject*)u->userdata;
Py_XDECREF(o);
delete u;
Expand Down
262 changes: 0 additions & 262 deletions cv_bridge/src/module_opencv2.cpp

This file was deleted.