Robotics StackExchange | Archived questions

CvBridgeError: [8SC1] is not a color format. but [mono8] is. The conversion does not make sense

I'm trying to convert a ROS message of class 'sensormsgs.msg.Image.Image' to an OpenCV image using Python and cvbridge. The ROS message encoding is "8SC1", which is a single-channel 8-bit (grayscale) format. However, when I go to use cvbridge's "imgmsgtocv2", I receive the following CvBridgeError:

[8SC1] is not a color format. but [mono8] is. The conversion does not make sense

First of all, this is wrong because mono8 is NOT a color format. I set desired_encoding to "mono8" as this is my desired encoding.

I also tried having desired encoding = "passthrough", but since this gave negative pixel values, I am attempting the mono8 conversion. It should be known that my ROS message is raw disparity values in pixels. I have used imgmsgtocv2 on another ROS (color) image message with no problems.

Relevant Python code is below:

import numpy as np
import cv2
import rospy
import std_msgs
from sensor_msgs.msg import Image
from cv_bridge import CvBridge

cv_bridge_object = CvBridge()   

def ROS2OpenCV_disp_converter(input):
    output = cv_bridge_object.imgmsg_to_cv2(input, desired_encoding = "mono8")
    cv2.imshow('Disparity', output)
    cv2.waitKey(1)

def stereoCameraSubscriber():
    rospy.init_node("Stereo_Camera_Subscriber")
    rospy.Subscriber("/occam/disparity_image0", Image, ROS2OpenCV_disp_converter)
    rospy.spin()

if __name__ == '__main__':
    try:
        stereoCameraSubscriber()
    except rospy.ROSInterruptException:
        pass

Asked by anonymous25646 on 2016-01-18 12:58:49 UTC

Comments

I had the same issue and fixed it by specifying the desired output format of the conversion to ROS format: cv_bridge.cv2_to_imgmsg(image, 'bgr8')

Asked by artifactz on 2017-05-30 09:17:48 UTC

Answers

Hello, did you find why? I'm interested as well. Thank you!

Asked by Yue on 2016-10-18 19:28:37 UTC

Comments

Did you find reason?My question : cv_bridge exception: [16UC1] is not a color format. but [mono16] is. The conversion does not make sense Very samiliar!

Asked by lixz123007 on 2019-08-27 05:27:40 UTC