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

Error when trying to use CvBridge

asked 2019-05-17 18:47:38 -0600

paul_shuvo gravatar image

When I run this code:

cv_image = self.bridge.imgmsg_to_cv2(image, "bgr8")

I get this error:

dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
AttributeError: 'Subscriber' object has no attribute 'encoding'

I'd appreciate any help. Thanks!

edit retag flag offensive close merge delete

Comments

Did you solve this? posting your hole node or at least the part where you are setting the image variable will be of much help.

Jasmin gravatar image Jasmin  ( 2019-05-25 03:04:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-05-25 03:03:11 -0600

Jasmin gravatar image

I think that the problem is in the image variable, the error message says that it is of type "Subscriber". cvbridge takes the sensor_msgs/Image.msg as input not the subscriber.

Your callback should be something like: (where data is your image message)

  def callback(self,data):
      cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")

You may add try and except to raise any related exceptions. Review the cvbridge tutorial for more details.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2019-05-17 18:47:38 -0600

Seen: 3,127 times

Last updated: May 25 '19