Unable to store the depth map in 32FC1 format?
Hello!
I want to get the depth data from Creative 3d Senz camera. I am not able to store the depth map in its correct format. Please see the snippet below.
1 #!/usr/bin/env python
2
3 import sys
4 import cv2
5 import rospy
6 from std_msgs.msg import String
7 from sensor_msgs.msg import Image
8 from sensor_msgs.msg import PointCloud2
9 from cv_bridge import CvBridge, CvBridgeError
10
11 class ImgCapture:
12 def __init__(self):
13 self.CvImg = CvBridge()
14 skImg = rospy.Subscriber("/softkinetic_camera/rgb/image_color",Image, self.callbackImg)
15 skDep = rospy.Subscriber("/softkinetic_camera/depth/image_raw",Image, self.callbackDepth)
16
17 def callbackImg(self, data):
18 #print "Processing RGB"
19 try:
20 NewImg = self.CvImg.imgmsg_to_cv2(data,"bgr8")
21 print data.encoding
22 print
23 cv2.imwrite("rgb.png", NewImg)
24 except CvBridgeError as e:
25 print(e)
26
27 def callbackDepth(self, data):
28 #print "Depth"
29 try:
# THIS LINE GIVES ME THE FOLLOWING ERROR
30 NewImg = self.CvImg.imgmsg_to_cv2(data,"32FC1")
31 print data.encoding
32 print
33 cv2.imwrite("depth.png", NewImg)
34 except CvBridgeError as e:
35 print(e)
36
In the above code snippet, callbackDepth() gives me the following error:
[ERROR] [WallTime: 1487855299.273887] bad callback: <bound method ImgCapture.callbackDepth of <__main__.ImgCapture instance at 0x7fc64712e320>>
Traceback (most recent call last):
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 720, in _invoke_callback
cb(msg)
File "/home/lerrel/ros_ws/src/baxter_examples/scripts/image_capture.py", line 33, in callbackDepth
cv2.imwrite("depth.png", NewImg)
TypeError: img data type = 14 is not supported
If I change line 30. to 30 NewImg = self.CvImg.imgmsg_to_cv2(data,"passthrough")
, here is no error but the image saved is just black with no depth information.
Can you please help me understand what is going wrong here?