ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your question: Is it possible to convert depth messages as Ipl image using CvBridge? Yes, definitely! But: for the rest of your question: It depends! ;)

In the first place the resulting IplImage (or better to use cv::Mat) will have the same color space as the incoming image, i. e. if you call cv_bridge::toCvShare(msg) or toCVCopy without encoding a published "32FC1" image will result in an "32FC1" (32bit floating point, one channel). For some color spaces cv_bridge can handle the color transformation, i. e. your can call cv_bridge::toCvShare(msg, your_encoding ) where your encoding must not necessarily be the encoding of the original image message ( e. g. rgb8 <---> bgr8 ); However, this does not work for all encoding combinations!

Apparently, if you get an error it does not work for the transformation you desired! Therefore, you should read your the image first without specifying an encoding (cv_bridge::toCvShare(msg)) and that do your desired transformation yourself. The image callback of rqt_image_view gives a good example of how to do this, see: https://github.com/ros-visualization/rqt_common_plugins/blob/groovy-devel/rqt_image_view/src/rqt_image_view/image_view.cpp#L265

Your question: Is it possible to convert depth messages as Ipl image using CvBridge? Yes, definitely! But: for the rest of your question: It depends! ;)

In the first place the resulting IplImage (or better to use cv::Mat) will have the same color space as the incoming image, i. e. if you call cv_bridge::toCvShare(msg) or toCVCopy without encoding a published "32FC1" image will result in an "32FC1" (32bit floating point, one channel). For some color spaces cv_bridge can handle the color transformation, i. e. your can call cv_bridge::toCvShare(msg, your_encoding ) where your encoding must not necessarily be the encoding of the original image message ( e. g. rgb8 <---> bgr8 ); However, this does not work for all encoding combinations!

Apparently, if you get an error it does not work for the transformation you desired! Therefore, you should read your the image first without specifying an encoding (cv_bridge::toCvShare(msg)) and that do your desired transformation yourself. The image callback of rqt_image_view gives a good example of how to do this, see: https://github.com/ros-visualization/rqt_common_plugins/blob/groovy-devel/rqt_image_view/src/rqt_image_view/image_view.cpp#L265

Commenting on your edit: I am not familiar with opencv python but I commented your code where it seams unclear:

        cv_image = CvBridge().imgmsg_to_cv2(data, "16UC1")  ## was your image not 32 float? 
                                                            ## this means 16 unsigned integer
 except CvBridgeError, e:
        print e 
 global i
 cv_image1 = np.array(cv_image, dtype=np.float)  ## type float again? 
                                                 ## up there you converted to unsigned int 16!