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 imagebvbdort ( 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 imageMary.Hewitt ( 2017-09-20 20:47:05 -0500 )edit

Here is an example in c++ using convertScaleAbs

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