Ask Your Question

hermanoid's profile - activity

2021-10-28 09:18:24 -0600 commented answer "cv_bridge" throws boost import error in Python 3 and ROS Melodic

I havent used PyTorch, but in my experience with Tensorflow, convincing the framework to use old python just isn't going

2021-07-31 15:45:01 -0600 received badge  Great Answer (source)
2021-07-31 15:45:01 -0600 received badge  Guru (source)
2021-07-28 02:55:58 -0600 received badge  Student (source)
2021-07-28 02:52:23 -0600 marked best answer "cv_bridge" throws boost import error in Python 3 and ROS Melodic

I'm running a script that uses cv_bridge with OpenCV 4, on Python 3, on ROS Melodic, on Raspbian, on a Raspberry Pi 4, and I'm running into errors trying to dynamically import cv_bridge.boost and failing.

I built ROS from source following these instructions, and installed opencv with sudo pip3 install opencv-contrib-python==4.1.0.25. I've had to do a bit of a hack to get it to import properly (I run sys.path.append('/usr/lib/python2.7/dist-packages') before I import cv2) but beyond these hacks, OpenCV 4 seems to be playing nice with Python 3, and Python 3 seems to be playing nice with ROS.

I from cv_bridge import CvBridge, CvBridgeError without issue, then run:

self.bridge = CvBridge()
image_opencv = self.bridge.imgmsg_to_cv2(data, desired_encoding="passthrough")

on a helper class, where data (as the function suggests) is a standard ROS Image message. (In my case, I'm getting these messages from the cv_camera topic /cv_camera/image_raw)

when I try to run that, I get this error:

[ERROR] [1588106367.612936]: bad callback: <bound method tpu_detector.callback of <__main__.tpu_detector object at 0xa7061df0>>
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/pi/catkin_ws/src/edge_tpu/scripts/detect_ros.py", line 91, in callback
    data, desired_encoding="passthrough")
  File "/home/pi/catkin_build_ws/install/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 "/home/pi/catkin_build_ws/install/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 "/home/pi/catkin_build_ws/install/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)

every time an image message arrives. Which, to put it lightly, really sucks. I've googled the snot out of it, and come up with a few pages, all of which tell me to build cv_bridge for Python 3 - but I already have. Multiple times. Following the instructions in this Medium post line by line, the error persists. The error traceback above prooves that this custom-built package is being imported like it's supposed to.

It's worth noting that I had to use catkin_make to build cv_bridge properly; catkin build cv_bridge(with all the extra flags of https://stackoverflow.com/questions/4..., plus an extra -DPYTHON3=1 I added to placate NumPy) fails for no apparent reason (I've pasted the output into this gist if anyone believes it to be related to the issue)

I have been stuck on this issue for a multitude of hours and have gotten no closer to a solution - any help will be much appreciated!

2021-07-28 02:52:23 -0600 received badge  Enlightened (source)
2021-07-27 18:41:27 -0600 received badge  Good Answer (source)
2021-07-08 04:58:54 -0600 received badge  Nice Answer (source)
2021-04-10 15:39:38 -0600 received badge  Necromancer (source)
2021-04-10 15:39:38 -0600 received badge  Self-Learner (source)
2021-04-10 15:39:38 -0600 received badge  Teacher (source)
2021-03-29 08:05:24 -0600 commented question "cv_bridge" throws boost import error in Python 3 and ROS Melodic

@Onurcan Thanks for the reminder! See my new answer on this thread.

2021-03-29 08:04:53 -0600 answered a question "cv_bridge" throws boost import error in Python 3 and ROS Melodic

While this is probably not the best solution, the way I eventually solved this was to remove any reference to dysfunctio

2020-06-02 20:59:36 -0600 received badge  Famous Question (source)
2020-06-02 20:59:36 -0600 received badge  Notable Question (source)
2020-05-07 11:06:17 -0600 received badge  Enthusiast
2020-05-04 09:01:35 -0600 received badge  Popular Question (source)
2020-04-28 16:32:42 -0600 asked a question "cv_bridge" throws boost import error in Python 3 and ROS Melodic

"cv_bridge" throws boost import error in Python 3 and ROS Melodic I'm running a script that uses cv_bridge with OpenCV 4