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

Opencv 3 compatibility #564

Merged
merged 4 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion image_proc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ find_package(rcutils REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_transport REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(OpenCV 4 REQUIRED)
find_package(OpenCV REQUIRED)
if(OpenCV_VERSION VERSION_LESS "3.2.0")
message(FATAL "Minimum OpenCV version is 3.2.0 (found version ${OpenCV_VERSION})")
endif()
find_package(image_geometry REQUIRED)

include_directories(
Expand Down
8 changes: 7 additions & 1 deletion image_proc/src/crop_decimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ void debayer2x2toBGR(
int R, int G1, int G2, int B)
{
typedef cv::Vec<T, 3> DstPixel; // 8- or 16-bit BGR
dst.create(src.rows / 2, src.cols / 2, cv::traits::Type<DstPixel>::value);
#if CV_VERSION_MAJOR >= 3 && CV_VERSION_MINOR >= 2
Copy link
Contributor

@dirk-thomas dirk-thomas Jul 15, 2020

Choose a reason for hiding this comment

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

This condition looks wrong. Version 4.0 / 4.1 would evaluate to FALSE and 4.2 would evaluate to TRUE.

Since on a CMake level we already assert 3.2 or higher I would swap the blocks and just check for CV_VERSION_MAJOR >= 4.

// Use OpenCV 3 API
dst.create(src.rows / 2, src.cols / 2, cv::DataType<DstPixel>::type);
#else
// Assume OpenCV 4
dst.create(src.rows / 2, src.cols / 2, cv::traits::DataType<DstPixel>::type);
#endif

int src_row_step = src.step1();
int dst_row_step = dst.step1();
Expand Down
3 changes: 1 addition & 2 deletions image_publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ set( DEPENDENCIES
cv_bridge
)

find_package(OpenCV REQUIRED COMPONENTS core)
find_package(OpenCV REQUIRED COMPONENTS core imgcodecs videoio)
message(STATUS "opencv version ${OpenCV_VERSION}")
find_package(OpenCV 4 REQUIRED COMPONENTS ${opencv_4_components})

include_directories(include)

Expand Down
5 changes: 0 additions & 5 deletions image_view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ if(ANDROID)
return()
endif()

find_package(GTK3)
add_definitions(-DHAVE_GTK)
include_directories(${GTK3_INCLUDE_DIRS})

add_library(image_view_nodes SHARED
src/disparity_view_node.cpp
src/extract_images_node.cpp
Expand All @@ -56,7 +52,6 @@ ament_target_dependencies(image_view_nodes
stereo_msgs
)
target_link_libraries(image_view_nodes
${GTK3_LIBRARIES}
${OpenCV_LIBRARIES}
${Boost_LIBRARIES}
)
Expand Down
1 change: 0 additions & 1 deletion image_view/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<depend>camera_calibration_parsers</depend>
<depend>cv_bridge</depend>
<depend>gtk3</depend>
<depend>image_transport</depend>
<depend>message_filters</depend>
<depend>rclcpp</depend>
Expand Down