Robotics StackExchange | Archived questions

Error when trying to use CvBridge

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!

Asked by paul_shuvo on 2019-05-17 18:47:38 UTC

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.

Asked by Jasmin on 2019-05-25 03:04:36 UTC

Answers

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.

Asked by Jasmin on 2019-05-25 03:03:11 UTC

Comments