Ask Your Question

Error when trying to use CvBridge

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

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


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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


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

Seen: 762 times

Last updated: May 25 '19