-
Notifications
You must be signed in to change notification settings - Fork 606
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
fail to use function in cv_bridge #207
Comments
i am having the same problem did you find the solution? |
@walid19 In my try, cv_bridge is available for python2 and cannot be used in py3. You can try running in python2. |
Was anyone able to use python3 and solve this issue? |
Found a way around. This helped http://www.programmersought.com/article/4908420840/ |
You could use import numpy as np
im = np.frombuffer(image_data.data, dtype=np.uint8).reshape(image_data.height, image_data.width, -1) |
↑↑↑ A real MVP, just like in the legends If you're missing the
|
Is there anyway to implement the same thing as |
A different solution worked for me. I'm also trying to use Python 3 with CVBridge. I'm using conda as my environment manager. For me the solution was to configure catkin like so:
After adding these CMake Args, I no longer get the error. Note if you're using a different version of conda / conda-python, you may have to adjust your |
I was having the same error message but not with this repository. |
Beautiful solution is to use ros_numpy. It is similar to the function of cv_bridge, but without the dependency on cv2: import ros_numpy
np_img = ros_numpy.numpify(ros_img_msg) |
If you are trying to not use cv_bridge when publishing an image to ROS (the other direction as the one of this issue): ndarray (or cv2) --> ROS, here is a snippet of code that does the job using the methods mentionned just above. Assuming that ros_image = Image(encoding="mono8")
# Create the header
ros_image.header.stamp = rospy.Time.from_sec(t)
ros_image.header.frame_id = id
# Fill the image data
ros_image.height, ros_image.width = img.shape
ros_image.data = img.ravel().tobytes() # or .tostring()
ros_image.step=ros_image.width |
@qgallouedec where are you getting |
When I use some function in cv_bridge, I receive an importerror:
Traceback (most recent call last):
File "/home/yixiangw/gym-gazebo/gym_gazebo/envs/turtlebot/gazebo_circuit2c_turtlebot_camera_nn.py", line 217, in _reset
cv_image = CvBridge().imgmsg_to_cv2(image_data, "bgr8")
File "/home/yixiangw/gym-gazebo/gym_gazebo/envs/installation/catkin_ws/src/vision_opencv/cv_bridge/python/cv_bridge/core.py", line 163, in imgmsg_to_cv2
dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
File "/home/yixiangw/gym-gazebo/gym_gazebo/envs/installation/catkin_ws/src/vision_opencv/cv_bridge/python/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/yixiangw/gym-gazebo/gym_gazebo/envs/installation/catkin_ws/src/vision_opencv/cv_bridge/python/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)
so how can I solve it ?
The text was updated successfully, but these errors were encountered: