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

depth_image_proc not working with custom depth

asked 2022-08-25 20:34:04 -0600

iHany gravatar image

Hi, I'm trying to modify a depth image from Realsense camera and generate a point cloud with the modified depth.

What I've done is (sorry for the links. I couldn't upload snippets properly):

  1. Launch Realsense camera ros wrapper as roslaunch realsense2_camera rs_camera.launch align_depth:=true image_fps:=5 depth_fps:=5

  2. Write a python code that modifies depth image from camera; see image_converter.py.

  3. Run a launch file based on depth_image_proc; see point_cloud_xyzrgb_depth_converted.launch

In rviz, I couldn't see any point cloud as shown here.

Note that if I change the topic name of depth image that point_clound_xyzrgb_depth_converted.launch subscribes, I can see the point cloud.

Anyone has a comment for this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-08-25 23:03:18 -0600

ravijoshi gravatar image

updated 2022-08-25 23:22:26 -0600

You need to set the header of your image message as shown below. The original code taken from your shared reference.

    ...
    self.depth_sub = rospy.Subscriber("/camera/aligned_depth_to_color/image_raw", Image, self.callback)

def callback(self, depth_data):
    try:
        cv_depth = self.bridge.imgmsg_to_cv2(depth_data, "16UC1")
    except CvBridgeError as e:
        print(e)

    (rows, cols) = cv_depth.shape
    cv_depth[0:int(rows/2), 0:int(cols/2)] = 0

    try:
        updated_depth_msg = self.bridge.cv2_to_imgmsg(cv_depth, "16UC1")
        updated_depth_msg.header = depth_data.header
    except CvBridgeError as e:
        print(e)
    else:
        self.depth_pub.publish(updated_depth_msg)

Once you set the header, please confirm it by executing the following command:

rostopic echo -n 1 /camera/aligned_depth_to_color/image_converted | head

Furthermore, please ensure the header values, such as frame_id, etc., in the converted image are the same as in the raw image. For example, you can use the following command to see the header for the raw image:

rostopic echo -n 1 /camera/aligned_depth_to_color/image_raw | head
edit flag offensive delete link more

Comments

Thank you for answering! However, I found that self.bridge.cv2_to_imgmsg cannot receive header with the following error (also see this).

[ERROR] [1661487463.445747]: bad callback: <bound method DepthConverter.callback of <__main__.DepthConverter object at 0x7fde4de54c88>>
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "depth_converter.py", line 39, in callback
    cv_depth, encoding="passthrough", header=depth_data.header,
TypeError: cv2_to_imgmsg() got an unexpected keyword argument 'header'
iHany gravatar image iHany  ( 2022-08-25 23:18:11 -0600 )edit

You can assign it manually. Please see the updated answer above.

ravijoshi gravatar image ravijoshi  ( 2022-08-25 23:22:52 -0600 )edit

Gotcha. I could update the header as follows.

    depth_data_pub = self.bridge.cv2_to_imgmsg(cv_depth, "passthrough")
    depth_data_pub.header = depth_data.header
    self.depth_pub.publish(depth_data_pub)
iHany gravatar image iHany  ( 2022-08-25 23:23:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-08-25 20:34:04 -0600

Seen: 236 times

Last updated: Aug 25 '22