Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make the subscribe node to receive "/camera/depth/image_rect_raw"? #2731

Closed
kevinDrawn opened this issue May 8, 2023 · 5 comments
Closed
Labels

Comments

@kevinDrawn
Copy link

Hello. I have question about the topic named '/camera/depth/image_rect_raw'
This topic is published when i launch this 'rs_camera.launch'.

I want to receive the topic and transfer to depth_frame for mapping x,y pixel coordinate to the world coordinate (x,y,z).

ex) The mapping function is it. (Depth -> Relative Coordinate). This functon's parameter requires the depth_frame.
def get_relative_xyz(depth_frame, pixel_x, pixel_y, depth_scale=10): depth_intrin = depth_frame.profile.as_video_stream_profile().intrinsics depth_pixel = [pixel_x, pixel_y] depth_image_point = rs.rs2_deproject_pixel_to_point(depth_intrin, depth_pixel, depth_frame.get_distance(pixel_x, pixel_y)) depth_relative_point = np.array([depth_image_point[0]*depth_scale, depth_image_point[1]*depth_scale, depth_image_point[2]*depth_scale]) return depth_relative_point

And This is my code.

`#!/usr/bin/env python
#-- coding:utf-8 --

import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2
import pyrealsense2 as rs
import numpy as np

x = 250
y = 250
i = 0
depth_relative_point=0

bridge = CvBridge()

pipeline = rs.pipeline()
serial_number = "128422271045" # it is the Serial number of my Depth camera.
config = rs.config()
config.enable_device(serial_number)
config.enable_stream(rs.stream.depth, 848, 480, rs.format.z16, 30) #launch file
pipeline.start(config)

def Image_callback(image):
global x, y, depth_relative_point
depth_array = np.array(image.data, dtype=np.uint16)
depth_frame = rs.frame(depth_array)
depth_relative_point = get_relative_xyz(depth_frame,x,y,depth_scale=10)
print(depth_relative_point[0])

def get_relative_xyz(depth_frame, pixel_x, pixel_y, depth_scale=10):
depth_intrin = depth_frame.profile.as_video_stream_profile().intrinsics
depth_pixel = [pixel_x, pixel_y]
depth_image_point = rs.rs2_deproject_pixel_to_point(depth_intrin, depth_pixel, depth_frame.get_distance(pixel_x, pixel_y))
depth_relative_point = np.array([depth_image_point[0]*depth_scale, depth_image_point[1]*depth_scale, depth_image_point[2]*depth_scale])
return depth_relative_point

rospy.init_node('sub')
rospy.Subscriber('/camera/depth/image_rect_raw',Image, Image_callback)

rospy.spin()

pipeline.stop()
cv2.destroyAllWindows()
`

Whenever I run this code, No device error occurred.

Traceback (most recent call last): File "/home/park/catkin_ws/src/robot/src/sub.py", line 27, in <module> pipeline.start(config) RuntimeError: No device connected

Realsense Camera D405.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 8, 2023

Hi @kevinDrawn Hi @kevinDrawn I note that you are using a D405 with the ROS1 wrapper (as you are using rs_camera.launch). The ROS2 wrapper ros2-development supports the D405 camera model but the ROS1 wrapper does not by default. A RealSense ROS user published a custom "forked" version of the ROS1 wrapper at https://github.com/rjwb1/realsense-ros that contains D405 support.

If you want to create your own D405-supporting fork version of the wrapper instead of using the pre-made one at the above link, the edits to make to the file include/realsense2_camera/constants.h are described at #2582 (comment) and #2297 (comment)


The RealSense ROS1 wrapper has an example ROS pyrealsense2 node script called show_center_depth.py that uses the /camera/depth/image_rect_raw to print the real-world distance of the coordinate at the center of the image.

https://github.com/IntelRealSense/realsense-ros/blob/ros1-legacy/realsense2_camera/scripts/show_center_depth.py

It uses intrinsics from the /camera/depth/camera_info topic to calculate the 3D position of a pixel whose range is obtained from the depth image, received from the /camera/depth/image_rect_raw topic.

@kevinDrawn
Copy link
Author

Thank you a lot!

@MartyG-RealSense
Copy link
Collaborator

You are very welcome! :)

@MartyG-RealSense
Copy link
Collaborator

Hi @kevinDrawn Do you require further assistance with this case, please? Thanks!

@MartyG-RealSense
Copy link
Collaborator

Case closed due to no further comments received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants