-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Question] How to use rs2_project_color_pixel_to_depth_pixel in python to convert 1 point from color coordinate into depth coordinate #5603
Comments
Take a look at this post for similar query. |
@kafan1986 Thanks I will try your idea soon |
@kafan1986 |
Yes it will generally be good enough. This is real world dependent, how far are you trying to measure? |
@kafan1986 |
If all your values are supposed to be within that range then you can lower your depthMaxMeters |
@kafan1986 # There values are needed to calculate the mapping
depth_scale = profile.get_device().first_depth_sensor().get_depth_scale()
depth_min = 0.11 #meter
depth_max = 1.0 #meter
depth_intrin = profile.get_stream(rs.stream.depth).as_video_stream_profile().get_intrinsics()
color_intrin = profile.get_stream(rs.stream.color).as_video_stream_profile().get_intrinsics()
depth_to_color_extrin = profile.get_stream(rs.stream.depth).as_video_stream_profile().get_extrinsics_to( profile.get_stream(rs.stream.color))
color_to_depth_extrin = profile.get_stream(rs.stream.color).as_video_stream_profile().get_extrinsics_to( profile.get_stream(rs.stream.depth))
color_points = [
[400.0, 150.0],
[560.0, 150.0],
[560.0, 260.0],
[400.0, 260.0]
]
for color_point in color_points:
depth_point_ = rs.rs2_project_color_pixel_to_depth_pixel(
depth_frame.get_data(), depth_scale,
depth_min, depth_max,
depth_intrin, color_intrin, depth_to_color_extrin, color_to_depth_extrin, color_point) Here's the output. It's quite correct. If the depth value for bottom right point became invalid, then the nearby valid point will be selected. But i think this is the desired behavior of rs2_project_color_pixel_to_depth_pixel method. |
i am getting following error |
@subbhyd You need the realsense version larger than 2.31.0 , so please build re-build your realsense library to match that version See the source code at : pyrsutil.cpp |
@gachiemchiep Your work is great, I would like to ask what is the significance of the first parameter , depth_frame.get_data(). |
@kithib rs2_project_color_pixel_to_depth_pixel(point, static_cast<uint16_t*>depth_frame.get_data(), ....) The cpp api is like this : |
@gachiemchiep Thank you very much, with your help I have solved this problem |
@westpilgrim63 please check whether depth at that point is valid. |
To those who are going to use the provided snip of code, make sure to swap the order of the input of color_to_depth_extrin and depth_to_color_extrin. (see the similar C++ API document) The first image is from the original code and the second one is from the modified one: |
Before opening a new issue, we wanted to provide you with some useful suggestions (Click "Preview" above for a better view):
All users are welcomed to report bugs, ask questions, suggest or request enhancements and generally feel free to open new issue, even if they haven't followed any of the suggestions above :)
Issue Description
Hello guys.
Does anyone know how to use the rs2_project_color_pixel_to_depth_pixel method in python?
My current situation is as followed:
It's similar to this script distance_to_object
Because of the aligment from depth frame into color frame took a long time, the total fps did drop down. I want project only the coordinate of bounding box ( x1, y1) from color frame into depth frame (x2, y2).
I found some c++ method at 2265 and the wrapper for that method at pyrsutil_8cpp_source. But don't know how to use that method.
Please help/
The text was updated successfully, but these errors were encountered: