image_pipeline icon indicating copy to clipboard operation
image_pipeline copied to clipboard

[Fix] RuntimeError: cv_bridge.cvtColorForDisplay() while trying to convert image from '8UC3' to 'bgr8' an exception was thrown ([8UC3] is not a color format. but [bgr8] is. #377

Open zhudaoruyi opened this issue 5 years ago • 4 comments

ubuntu@ubuntu:~/catkin_csi_camera$ rosrun image_view extract_images_sync _inputs:='[/csi_cam/image_raw]'
[ERROR] [1547019957.683194]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f54800390>>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
    self.signalMessage(msg)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
    cb(*(msg + args))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 224, in add
    self.signalMessage(*msgs)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
    cb(*(msg + args))
  File "/home/ubuntu/catkin_csi_camera/src/image_view/scripts/extract_images_sync", line 89, in save
    do_dynamic_scaling=self.do_dynamic_scaling)
RuntimeError: cv_bridge.cvtColorForDisplay() while trying to convert image from '8UC3' to 'bgr8' an exception was thrown ([8UC3] is not a color format. but [bgr8] is. The conversion does not make sense)

zhudaoruyi avatar Jan 09 '19 10:01 zhudaoruyi

@zhudaoruyi - Could you please rebase this on melodic? I will review more closely after that.

JWhitleyWork avatar Apr 25 '19 14:04 JWhitleyWork

@JWhitleyAStuff commenting out probably isnt the best move, its probably there for a reason. Maybe we should handle the condition that causes the issue but not just remove

SteveMacenski avatar Apr 27 '19 21:04 SteveMacenski

@SteveMacenski - I agree. I hadn't looked this over thoroughly. I was waiting until the rebase had been completed.

JWhitleyWork avatar Apr 29 '19 14:04 JWhitleyWork

Commenting out generates a wrong encoding of the frames, I solved modifying the "save" method as follows:

def save(self, *imgmsgs):
   seq = self.seq
   bridge = cv_bridge.CvBridge()
   for i, imgmsg in enumerate(imgmsgs):
      img = bridge.imgmsg_to_cv2(imgmsg)
      img = cv_bridge.cvtColorForDisplay(img, encoding_in=imgmsg.encoding, encoding_out='', do_dynamic_scaling=self.do_dynamic_scaling)
      fname = self.fname_fmt % (seq, i)
      print('Save image as {0}'.format(fname))
      cv2.imwrite(fname, img)
   self.seq = seq + 1

4TINI avatar Feb 01 '22 14:02 4TINI

@zhudaoruyi - Would you mind implementing the changes suggested by @4TINI and targeting this at noetic since melodic is now EoL? If not, I understand and will close the PR.

JWhitleyWork avatar Dec 04 '22 22:12 JWhitleyWork

Closing due to lack of response

mikeferguson avatar Jan 19 '24 20:01 mikeferguson