Depth Value Extraction from Image Encoding for ASUS Cameras - 32FC1?
Hello,
I'm trying to extract the depth value from the Depth Image generated by various RGB-D sensors. I've succeeded with a Kinect V1, which is encoded as 16UC1, but the ASUS Xtion Pro and the ASUS Primesense Carmine are encoded in 32FC1.
My code is below, with the callback being made from a standard ROS Subscriber to the depth image topic. Note that I am using the OpenCV and CVBridge modules:
def callback(self,data):
try:
# Kinect V1
cv_image = self.bridge.imgmsg_to_cv2(data, "16UC1")
depth_val = cv_image[0, 0]
# ASUS Cameras
#cv_image = self.bridge.imgmsg_to_cv2(data, "32FC1")
#depth_val = cv_image[0, 0]
print depth_val
print('[0,0] ' + str(float(depth_val)/1000) + ' millimetres.')
except CvBridgeError as e:
print (e)
The Kinect V1 lines operate fine, however when using the same logic with the 32FC1 encoding results in a [nan + nanj] value when printing the variable depth_val.
I've tried to force the encoding through the bridge as 16UC1 for the ASUS cameras, but this results in a 0.0 response, with a few random 0.1s. I'm guessing that I need to update the scale of the image or something along those lines to get a value that makes sense, but am unsure.
Hoping that someone out there has had experience with this,
Regards,
Mary
Asked by Mary.Hewitt on 2017-09-19 20:15:08 UTC
Answers
self.bridge.imgmsg_to_cv2(data, "32FC1")
is correct if the source image encoding is 32FC1, the nan
s are pixels where there was no depth data (which there could be a lot of depending on the sensor and what it is pointed at), you need to skip past those or make up a number like 0.0
to use in place of a legitimate value at that location if downstream processing can't handle nans. rqt_image_view shows the nan values as black.
Asked by lucasw on 2021-09-09 11:48:40 UTC
Comments
32 bit float range is large and the values from depth image are very small compared to this range. You can normalize the image for better visualization.
Asked by bvbdort on 2017-09-20 03:45:49 UTC
Hello @bvbdort - Do you have an example or idea of how I'd go about normalising the image correctly?
Asked by Mary.Hewitt on 2017-09-20 20:47:05 UTC
Here is an example in c++ using
convertScaleAbs
Asked by bvbdort on 2017-09-21 03:36:20 UTC