Depth Image is very dark.

asked 2020-07-14 17:58:50 -0600

Anonymous gravatar image


I am working on a project where I would like to use the depth map for object tracking and distance retrieval. I subscribed to the /camera/depth/image_rect_raw topic and published it using opencv function imshow which shows a dark image. Also how do you retrieve/calculate the distance an object is from the camera using the same topic?

The following is the code and image retrieved.

#!/usr/bin/env python

import rospy import numpy as np import pyrealsense2 as rs import cv2

from sensor_msgs.msg import Image from sensor_msgs.msg import CameraInfo from cv_bridge import CvBridge, CvBridgeError

class DepthRetriever():

def __init__(self):

    self.bridge = CvBridge()

    #self.sub = rospy.Subscriber('/camera/color/image_raw',Image,self.col_callback)
    self.depth_sub = rospy.Subscriber('/camera/depth/image_rect_raw',Image,self.dep_callback)
    #self.cam_data = rospy.Subscriber('/camera/depth/camera_info',CameraInfo,self.info_callback) 

def dep_callback(self, ros_img):
        dep_image = self.bridge.imgmsg_to_cv2(ros_img,"passthrough")

    except CvBridgeError as e: 
        rospy.logerr("Could not convert ros depth camera to opencv")

    #depth_array = np.array(dep_image, dtype = np.dtype('f8'))
    #norm_depth = cv2.normalize(depth_array, depth_array, 0, 1, cv2.NORM_MINMAX)

    cv2.imshow("depth image",dep_image)

def main(): rospy.init_node("Depth",anonymous = True)

distance_ret = DepthRetriever()
except KeyboardInterrupt():
    print("Error code not spinning")

if __name__ == '__main__':

edit retag flag offensive close merge delete


FYI. The depth image is using 11 bit to store the depth info. If you save it as a normal image, it is dark.

tianb03 gravatar image tianb03  ( 2020-07-14 21:58:28 -0600 )edit

I found that my image output for my depth info after bridging was "uint16". I am not sure if this needs to be converted to mono16 datatype for opencv.

I am using the intel realsense camera d435. I don't know to display the left imager and right imager. All I can see is a single window. Depth can be calculated using Z=fb/d where f is focal point, b is the baseline and d is the disparity. How do I calculate/ retrieve the depth information of an object given a coordinate (x,y)?


Anonymous gravatar image Anonymous  ( 2020-07-24 16:47:23 -0600 )edit

Realsense using stereo vision outdoor and infrared structure light indoor, so you may not be able to know right or left image. Uint16 data is in millimeter I remember, it represents distance directly. I will double-check.

tianb03 gravatar image tianb03  ( 2020-07-29 20:59:33 -0600 )edit