image_pipeline
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
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 - Could you please rebase this on melodic
? I will review more closely after that.
@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 - I agree. I hadn't looked this over thoroughly. I was waiting until the rebase had been completed.
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
@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.
Closing due to lack of response