Issues in cv_bridge with ros melodic
Hello!
I have an image-based python tool which I am using with ros melodic. I am workingon releasing it's ros package. It uses cv_bridge
.
When I directly run the main file with python2 'python2 file.py' It works perfectly well and I get the desired output!!!
But when I build the codebase in catkin workspace and run rosrun package_name file.py
on one terminal and launch ros usb cam in other terminal I get this error as soon as the tool starts receiving the image.
[ERROR] [1591520144.752339]: bad callback: <bound method ListenerCamera.__callback of <comm.ros.listenerCamera.ListenerCamera object at 0x7fe9838de6a0>>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/home/pankhuri/colortuner-ws/src/jderobot_color_tuner/comm/ros/listenerCamera.py", line 98, in __callback
image = imageMsg2Image(img, self.bridge)
File "/home/pankhuri/colortuner-ws/src/jderobot_color_tuner/comm/ros/listenerCamera.py", line 64, in imageMsg2Image
cv_image = bridge.imgmsg_to_cv2(img, "rgb8")
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 163, in imgmsg_to_cv2
dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 99, in encoding_to_dtype_with_channels
return self.cvtype2_to_dtype_with_channels(self.encoding_to_cvtype2(encoding))
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
When I try the code with 'python3 file.py' I get the same error, so I understood the reason is version problem in python2 , python2 and opencv versions. I further read cv_bridge doesn't work for ros melodic and it is supposed to use opencv 3. My codebase uses opencv2.
What would be the best solution in this case? Can we somehow set the variables in Cmakelist.txt to use opencv2 for ros melodic? The way I tried, gave me errors while building the package
CMake Error at jderobot_color_tuner/CMakeLists.txt:17 (find_package):
Could not find a configuration file for package "OpenCV" that is compatible
with requested version "2".
The following configuration files were considered but not accepted:
/usr/local/share/OpenCV/OpenCVConfig.cmake, version: 3.2.0
/usr/share/OpenCV/OpenCVConfig.cmake, version: 3.2.0
Thanks,
AskBot (the technology used by ROS Answers) does not support Markdown. I've replaced the three consecutive backticks with proper codeblocks.