Open andsmith opened 9 years ago
The o3d3xx-ros
camera node uses the image_transport
package to publish the OpenCV images. I just read this on the ROS wiki:
image_transport does not yet support Python, though it is on the Roadmap. If you need to interface a Python node with some compressed image transport, try interposing a republish node.
If you must use Python, to get around this, the suggestion is to use republish. I'm not sure if that fits your use case, but that seems to be the official suggestion as of Indigo (and Jade). Do you get this behavior using C++ as well?
You are converting to uint8 here: np.fromstring(msg.data,np.uint8. Did you try np.fromstring(msg.data,np.uint16?
It doesn't seem to matter what kind of integer np.fromstring converts it to; the imdecode converts it back to uint8.
If you must use Python, to get around this, the suggestion is to use republish.
Running a republish node (rosrun image_transport republish compressed in:=/o3d3xx/camera/depth raw out:=/depth
) and then subscribing to /depth
gets me an sensor_msgs.msg.Image message, that looks like this:
msg.width: 176
msg.height: 132
len(msg.data): 23232
msg.encoding: 'mono16'
The data array is exactly half the length it should be if it were really encoding a uint16 image. The CV bridge fails to decode this message, as expected:
pic = cvb.imgmsg_to_cv2(msg)
...
TypeError: buffer is too small for requested array
Casting to uint8 and reshaping to a 176 x 132 image, I see something that looks exactly like the incorrect uint8 image I described in my original comment.
The feeling I'm getting is that the compressed depth image does not contain all the info it should (i.e. all the info in the raw depth image).
Do you get this behavior using C++ as well?
I haven't tried it yet. This will be my next step before biting the bullet and using the raw topic.
is it possible to convert a mono16 depth image back to the raw depth data?
Looking at the raw depth values, I see 16-bit integers measuring what I assume are milimeters. Looking at the compressed topic (i.e. from a rosbag), I decompress with cv2, something like this: pic = cv2.imdecode(np.fromstring(msg.data,np.uint8),cv2.CV_LOAD_IMAGE_UNCHANGED) But what comes out is an array of uint8, mostly equal to 255, and looking vaguely like the raw depth image.
Is there a different way I'm supposed to be decompressing the depth image?