Rostopic keep publish sensor_msgs/Image with different type of encoding each time.
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()
try:
cv_image = bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
print(e)
cv2.imwrite("face.jpg", cv_image)
print("success")
def listener():
rospy.init_node('image_receiver', anonymous=True)
rospy.Subscriber("/camera/depth/image_raw", Image, callback)
rospy.spin()
if __name__ == '__main__':
listener()