ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Depth Value Extraction from Image Encoding for ASUS Cameras - 32FC1?

asked 2017-09-19 20:15:08 -0500

Mary.Hewitt gravatar image

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

edit retag flag offensive close merge delete

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.

bvbdort gravatar image bvbdort  ( 2017-09-20 03:45:49 -0500 )edit

Hello @bvbdort - Do you have an example or idea of how I'd go about normalising the image correctly?

Mary.Hewitt gravatar image Mary.Hewitt  ( 2017-09-20 20:47:05 -0500 )edit

Here is an example in c++ using convertScaleAbs

bvbdort gravatar image bvbdort  ( 2017-09-21 03:36:20 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-09-09 11:48:40 -0500

lucasw gravatar image

self.bridge.imgmsg_to_cv2(data, "32FC1") is correct if the source image encoding is 32FC1, the nans 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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-19 20:15:08 -0500

Seen: 1,244 times

Last updated: Sep 09 '21