-
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
How to use Realsense L515 to find the real world (x,y) coordinate of the corner of an object? #10484
Comments
Hi @kennangaibel You could use a RealSense SDK instruction called save_single_frameset() to save a single frame to a file format called a rosbag. This is like a video recording of camera data that can be used instead of a live camera, except in this case the file will only contain one frame. Information about this instruction and a link to an example Python program for it can be found at #9778 (comment) In regard to obtaining the 3D world-space coordinate of a single specific pixel coordinate on an image, this can be done with the instruction rs2_project_color_pixel_to_depth_pixel and information about this instruction is at #5603 (comment) If you plan to use the bag file created by save_single_frameset() for the frame to obtain the pixel coordinate from then you will need to use the instruction cfg.enable_device_from_file to tell your program to retrieve the data from the file instead of a live camera. The RealSense SDK Python example program read_bag_example.py demonstrates how to do this by placing the instruction just before the pipe start line of a script. |
Hi @MartyG-RealSense I've been able to get started thanks to your really helpful guidance but have a few more questions:
Would the bag file name be filt? Or must I pass in the bag file_name another way?
I apologize for all of the questions, it is my first time doing something like this. Thank you! |
Do not worry, there is not a limit on the number of questions that you can ask. :) In regard to those questions:
There should not be a space after the comma that separates commands in the bracket, and specific filenames should be placed within quotation marks. For example:
Or
I researched Python scripts for rs2_project_color_pixel_to_depth_pixel carefully and concluded that the 4-dot script that you are using above is one of the best and most appropriate script for your project. In a long and detailed discussion at #6239 about a RealSense user who wanted to use rs2_project_color_pixel_to_depth_pixel and OpenCV, a RealSense team member also provides a script at #6239 (comment) that includes a line for getting the depth value of a specific pixel. |
I was able to create a function
The resources you have shown me I believe will make it really easy to get the x,y real-world coordinate once I find this pixel. |
|
Thank you for the help! The reason I was asking the third question is because of how I will need to find the corner. From my understanding, I thought to implement an opencv "find_corner" script, I would have to transform the bag file into a .png file. And then work with that file. Is that not necessary? Can I simply just use something like: |
A bag file is treated by the SDK like a live camera except that its data is pre-recorded. So if you can access a particular pixel coordinate such as the corners in real-time with rs2_project_color_pixel_to_depth_pixel then you should also be able to access the corner-pixel coordinate access with that instruction and do a numpy operation on it when using a bag file. It seems that 'find corner' scripts in OpenCV do tend to use PNG instead of bag as the data source, such as the Harris corner detection in various OpenCV tutorials online including the official one in the link below. https://docs.opencv.org/4.x/dc/d0d/tutorial_py_features_harris.html If a RealSense depth frame is saved to a PNG then most of the depth information is lost though, making it inaccurate as a method of storing depth information. |
@MartyG-RealSense For context, when I got this bag file, I did
Additionally, I had to make the depth stream 640, 480 because I was getting an error when it was higher (the commented out config depth stream). Is there a way to get the depth stream to match to 1920 1080? I am unsure why a lower resolution would not cause error and the higher resolution would. |
The L515 does not support a depth resolution of 1920x1080. It can use 320x240, 640x480 or 1024x768. In regard to the black edges, you could try applying a post-processing filter on your L515 called a Temporal Filter, which has a 'persistency index' function for replacing missing pixels. https://dev.intelrealsense.com/docs/post-processing-filters#section-temporal-filter #2851 (comment) provides an example of Python code for implementing the filter. #10078 discusses setting the temporal filter's persistency value with rs.option.holes_fill |
@MartyG-RealSense Or Method 2.
(omitted a lot of Am I transmitting the path the wrong way? |
@MartyG-RealSense
When I print depth_point_ from
I get [230.83444213867188, 282.647705078125].
|
The SDK file rsutil.h describes it in terms of finding a projected pixel with unknown depth. https://github.com/IntelRealSense/librealsense/blob/master/include/librealsense2/rsutil.h#L31-L34 The code in your script that checks for valid depth values for the corner pixels seems to back up this theory.
As you have already defined a numpy depth array, a quick way to check the depth value for accuracy against the value obtained from the PNG may be to save the array's depth data to a Python .npy file as an array of scaled matrices, as demonstrated in a script at #4934 (comment) The simplest way to check actual real-world distance against calculated distance is to use a ruler or tape measure between the camera and the observed object / surface. |
Hi @MartyG-RealSense
Additionally, I have a few questions:
Based off
Does that mean the depth numpy array
|
When depth is aligned to color with align_to, the RealSense SDK's 'align processing block' mechanism will resize the depth's field of view (FOV) size to match the color FOV size. The processing block will also automatically adjust for differences in resolution between the depth and color streams. If the color FOV is smaller than the depth FOV then this may result in the outer edges of the depth image being cut off in the aligned image. If color to depth alignment is performed instead though by using ** align_to = rs.stream.depth** then if the color FOV is smaller than the depth FOV, the image will stretch out to fill the screen instead of having its edges cut off.
|
Hi @MartyG-RealSense,
The image is strangely dark and green tinted. This behavior seems to be random. I am wondering why this is the case and how to fix it? Here is my entire program (seems to work pretty well besides these quirks)
|
If the image is darkening then that makes me think that the RGB exposure may be dropping to a low value. If it was an RGB white-balance problem then the image would not darken like that. If the data is from a bag file and not a live camera then it is difficult to see what might cause such a problem, as there are no physical sensors involved that could be affected. |
If the folder that the script is looking for the bag in will only have one bag file in, a way to automate the process may be to have the file path be any file in the folder that has the .bag extension without having to know the filename. Code for doing so can be found at the link below. As it is the RGB sensor being affected rather than the depth sensor, if the apparent exposure drop is caused by a flash of strong sunlight then there is likely not much that could be done to reduce the likelihood of the sensor being saturated by the sunlight other than purchasing and applying a physical filter product over the lens of the RGB sensor on the outside of the camera to add protection from the light. The L515 is designed for use indoors in controlled lighting conditions and is not suited for outdoor use or indoors in areas with natural light. |
Hi @kennangaibel Do you require further assistance with this case, please? Thanks! |
Hi @MartyG-RealSense |
You are very welcome, @kennangaibel - thanks very much for the update! :) |
Hello |
Hi @Nel1212 As mentioned above, the real-world XYZ for a specific XY pixel coordinate can be obtained with the RealSense SDK instruction rs2_project_color_pixel_to_depth_pixel which converts a color pixel to a depth pixel. The center pixel for any RGB resolution can be found by dividing it by 2 - for example, the center pixel of 1280x720 would be the coordinate 640x360. So the four corner coordinates of resolution 1280x720 on an RGB image will be: Top left: 0,0 On a RealSense 400 Series depth image, the displayed corner coordinates are divided by 2. Top left: 0,0 An L515 camera does not divide the depth coordinates though. So for 640x480 depth: Top left: 0,0 |
Hii @MartyG-RealSense . I'm working on a project using a Realsense D435 camera and I've encountered some issues,
|
Using cv2.VideoWriter fourcc code to save RealSense data to .mp4 format is an appropriate method of export to that format. However, most of the depth information will be lost. To preserve the depth values, the data should be exported to a format that preserves it. An example of such a format in Python is .npy and #4934 (comment) has a script for exporting depth to .npy. You can obtain Z-depth for a color pixel without depth data by converting it to a depth pixel with rs2_project_color_pixel_to_depth_pixel. See #5603 (comment) for a Python example of the instruction's use. rs2_deproject_pixel_to_point requires use of depth information. |
@MartyG-RealSense Is this rs2_project_color_pixel_to_depth_pixel method can be applied for mp4 files recorded using intel realsense d435?(this mp4 file only contains color stream data).Or is it only applicable in real time ? Is there a method to convert these pixel coordinates in mp4 files into real world coordinates? |
Hi @SammaniSandumini The RealSense SDK cannot directly read MP4 files. An indirect approach would be to read the frames using OpenCV and then send them to the SDK's software-device virtual camera interface, as discussed at #2249 More information about software-device can be found at the link below. https://github.com/IntelRealSense/librealsense/tree/master/examples/software-device |
Issue Description
Hi, I am very new to using Realsense and would like some guidance on this problem. I need to take a single picture, then use that image to to convert a single point (the corner of an object), into real world cartesian coordinate system. The depth of the camera from the object will be known and both the camera and the object will be in a fixed position. The idea is that this camera will be used so that a robot knows where an object is and can grab it properly.
Thank you!
The text was updated successfully, but these errors were encountered: