Skip to content

Commit

Permalink
Fix module_opencv for opencv4.
Browse files Browse the repository at this point in the history
  • Loading branch information
hgaiser committed Apr 26, 2019
1 parent b66ee6c commit 8037bbf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 275 deletions.
14 changes: 13 additions & 1 deletion cv_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ else()
find_package(Boost REQUIRED)
endif()

find_package(OpenCV REQUIRED
find_package(OpenCV 3
COMPONENTS
opencv_core
opencv_imgproc
opencv_imgcodecs
CONFIG
)

if(NOT ${OpenCV_FOUND})
# Require to find OpenCV4 if OpenCV3 cannot be found.
find_package(OpenCV 4 REQUIRED
COMPONENTS
opencv_core
opencv_imgproc
opencv_imgcodecs
CONFIG
)
endif()


catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
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,11 @@ class NumpyAllocator : public MatAllocator
return u;
}

UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const
UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const CV_OVERRIDE
{
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 +130,26 @@ class NumpyAllocator : public MatAllocator
_sizes[i] = sizes[i];
if( cn > 1 )
_sizes[dims++] = cn;
PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
PyObject* o = PyArray_SimpleNew(dims, _sizes.data(), typenum);
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);
}

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

void deallocate(UMatData* u) const
void deallocate(UMatData* u) const CV_OVERRIDE
{
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.

0 comments on commit 8037bbf

Please sign in to comment.