ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

question on Converting between ROS images and OpenCV images (C++)

asked 2021-12-06 14:13:53 -0600

v.leto gravatar image

Hi! I copied the code provided in the official page in a immage_converter.cpp file.

I modified the Cmake like this:

cmake_minimum_required(VERSION 2.8.3)
project(prova)
 find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  sensor_msgs
  cv_bridge
  image_transport
)
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES prova
CATKIN_DEPENDS roscpp rospy std_msgs sensor_msgs  cv_bridge  image_transport
#  DEPENDS system_lib
)
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

add_executable(immage_converter src/immage_converter.cpp)

target_link_libraries(immage_converter ${catkin_LIBRARIES})

but I get this error

CMakeFiles/immage_converter.dir/src/immage_converter.cpp.o: nella funzione "ImageConverter::ImageConverter()":
immage_converter.cpp:(.text._ZN14ImageConverterC2Ev[_ZN14ImageConverterC5Ev]+0x4bc): riferimento non definito a "cv::namedWindow(cv::String const[ 89%] Built target wmcs_lib_generate_messages_py
&, int)"
CMakeFiles/immage_converter.dir/src/immage_converter.cpp.o: nella funzione "ImageConverter::~ImageConverter()":
immage_converter.cpp:(.text._ZN14ImageConverterD2Ev[_ZN14ImageConverterD5Ev]+0x36): riferimento non definito a "cv::destroyWindow(cv::String const&)"
CMakeFiles/immage_converter.dir/src/immage_converter.cpp.o: nella funzione "ImageConverter::imageCb(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)":
immage_converter.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1bf): riferimento non definito a "cv::imshow(cv::String const&, cv::_InputArray const&)"
immage_converter.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1e4): riferimento non definito a "cv::waitKey(int)"
collect2: error: ld returned 1 exit status
auv/prova/CMakeFiles/immage_converter.dir/build.make:127: recipe for target '/home/valeria/catkin_ws/devel/lib/prova/immage_converter' failed
make[2]: *** [/home/valeria/catkin_ws/devel/lib/prova/immage_converter] Error 1
CMakeFiles/Makefile2:7667: recipe for target 'auv/prova/CMakeFiles/immage_converter.dir/all' failed

If I type

pkg-config --modversion opencv

I get 3.2.0 which I suppose it's opencv 3, right?

what am I doing wrong? thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-12-07 15:58:09 -0600

GeorgNo gravatar image

You also need to include the OpenCV library in your CMakeLists.txt and link it.

The following should do the trick.

cmake_minimum_required(VERSION 2.8.3)
project(prova)
 find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  sensor_msgs
  cv_bridge
  image_transport
)
find_package(OpenCV REQUIRED)
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES prova
CATKIN_DEPENDS roscpp rospy std_msgs sensor_msgs  cv_bridge  image_transport
#  DEPENDS system_lib
)
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

add_executable(immage_converter src/immage_converter.cpp)

target_link_libraries(immage_converter ${catkin_LIBRARIES} ${OpenCV_LIBS})
edit flag offensive delete link more

Comments

Hi @GeorgNo the catkin_make doesn't give any erros now! Anyway I did

rosrun prova immage_converter

but nothing happens. I tried to run rqt and rviz but I don't see the immage

v.leto gravatar image v.leto  ( 2021-12-08 09:36:18 -0600 )edit

Hi, you probably have errors in your c++ files.

GeorgNo gravatar image GeorgNo  ( 2021-12-27 01:54:02 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-12-06 14:13:53 -0600

Seen: 253 times

Last updated: Dec 07 '21