Find depth of a clicked_point(using publish point of rviz) with realsense d435i

asked 2021-08-25 01:07:16 -0500

robot_mage gravatar image

Platform: Jetson Xavier NX (Jetpack 4.5.1) Camera: Intel Realsense d435i ROS version : Melodic (with python support) Environment:

UNITY_DEFAULT_PROFILE=unity COMPIZ_CONFIG_PROFILE=ubuntu ROS_ETC_DIR=/opt/ros/melodic/etc/ros ROS_ROOT=/opt/ros/melodic/share/ros ROS_MASTER_URI=http://localhost:11311 ROS_VERSION=1 ROS_PYTHON_VERSION=2 ROS_PACKAGE_PATH=/home/nvidia/catkin_ws/src:/opt/ros/melodic/share ROSLISP_PACKAGE_DIRECTORIES=/home/nvidia/catkin_ws/devel/share/common-lisp ROS_DISTRO=melodic

Hello everyone, I am trying to use rviz as an interactive UI so that upon clicking on a point (The pointcloud that comes from the camera), it shows the depth output of that particular point. It is similar to the realsense-viewer app provided by Intel (it shows depth on hovering cursor). The launchfile I am using is

roslaunch realsense2_camera rs_d435_camera_with_model.launch align_depth:=true

I have been successful to retrieve the depth of the center point by subscribing to the topic camera/aligned_depth_to_color/image_raw with the help of this snippet

def convert_depth_image(ros_image):
    bridge = CvBridge()
    try:
            depth_image = bridge.imgmsg_to_cv2(ros_image, desired_encoding="passthrough")
        depth_array = np.array(depth_image, dtype=np.float32)
        center_idx = np.array(depth_array.shape) / 2
        print ('center depth:', depth_array[center_idx[0], center_idx[1]])
    except CvBridgeError as e:
        print (e)

where the output 640x480 array and I am picking the center one's value

And I could the point clicked from /clicked_point which gives small floating points like

def pointout(pointc):
    try:
        point = PointStamped()
        point.header.stamp = rospy.Time.now()
        point.header.frame_id = "/base_link"
        point.point.x = pointc.point.x
        point.point.y = pointc.point.y
        point.point.z = pointc.point.z
        print("point",  point.point.x, point.point.y , point.point.z)

('point', 1.4978991746902466, 0.3923662602901459, -0.11269014328718185)

But my target is a mix of those above where using publish point of rviz I want to find out depth of a clicked_point. I tried PinholeCameraModel

and its project3dToPixel but the output is absurd looking

(-10083.965869772232,-2603.8460246850304)

(-7682.975508424789,-1851.3278575777758)

Can anyone point me to the right direction??

edit retag flag offensive close merge delete