Rostopic keep publish sensor_msgs/Image with different type of encoding each time.

asked 2019-06-18 06:07:05 -0500

baxmay gravatar image

Well, I'm using ROS Kinetic and gazebo to get image from kinect sensor in gazebo. I write a subscriber to get sensor_msgs/Image and convert it to image using Cv_Bridge

Somehow, the first sensor_msgs/Image have encoding of '32FC1' and the next one is 'rgb8' and the next one is changed back to '32FC1' and This keep going on.

I just wonder why is it behave like that?

this is my code in python:

#!/usr/bin/env python

import roslib
import rospy
from sensor_msgs.msg import Image
from PIL import Image as im
import numpy as np
import cv2
from cv_bridge import CvBridge, CvBridgeError

def callback(data):
    bridge = CvBridge()
        cv_image = bridge.imgmsg_to_cv2(data, "bgr8")
    except CvBridgeError as e:

    cv2.imwrite("face.jpg", cv_image)

def listener():
    rospy.init_node('image_receiver', anonymous=True)
    rospy.Subscriber("/camera/depth/image_raw", Image, callback)


if __name__ == '__main__':
edit retag flag offensive close merge delete