-
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
Cropping aligned depth data #6267
Comments
Intel has a Python tutorial program for RealSense that takes the approach of aligning depth and RGB data stored in a 'bag' format file and then applying "MobileNet-SSD" object detection to the aligned image and defining a 'bounding box' around the identified object so that the identified object's distance from the camera can be calculated. I hope that this tutorial can offer some useful insights for your own project. https://github.com/IntelRealSense/librealsense/blob/jupyter/notebooks/distance_to_object.ipynb The link below suggests Python code for cropping an 'RGB aligned to depth' image to a region of interest (ROI) on a point cloud. |
Many thanks for your suggestions. I need a ply file in order to perform a pose estimation of the detected objects. Maybe it's a issue with my code:
|
Apologies for the delay in responding, as I was carefully considering your code. It looks as though you are applying align before post-processing. It is recommended that align is applied after post-processing, otherwise the image can be affected by a type of distortion called aliasing, which can produce effects such as jagged lines. Also in the original Python ROI script that I linked to, the boundary values are set before depth_frame is defined. |
Many thanks for your response. I´ve applied your suggested changes. Actually, the main issue was that the RGB image data, for reasons that are unknown to me, were captured with a resolution of 1920x1080 instead of 1280x720, and therefore the image data did not match with the depth data. Now my program works like it is supposed to. Thank you very much for your time and support. |
You are really welcome. Awesome news that you found a solution - thanks for the update! :) |
Hey @MartyG-RealSense,
In the rs-measure example, align is done before post-processing. But you would suggest it the other way arround?
By boundary values you mean the bounding box corners? Why did you highlight this? Is there any difference in using the alignment like this Does someone know a handy alternative to this nice python/numpy syntax for cropping in C++? |
@PerceptMD The recommendation is to do align after post-processing in order to avoid distortion effects such as aliasing (jagged lines). I have had a couple of cases though where the only way that the RealSense user's program would work without errors is if they did alignment before post-processing. I don't think that the program will fail if align comes before post-proc, but doing align after is the recommendation if possible. I guess you could think of the boundary box horizontal and vertical min-max values in terms of defining the corners of the box. I don't know enough about boundary box programming to comment on it further than that though, as it isn't something that I have done myself. I believe that align.process() refers to doing alignment with an Align processing block In the C# wrapper, align_to was made obsolete in favor of doing alignment with a processing block. If you are able to make use of OpenCV in your C++ project then this link for defining a bounding box may be helpful: https://stackoverflow.com/questions/14505679/drawing-bounding-box-using-opencv-in-c-enviroment |
Thanks for your quick reply. So if possible the order could be changed in rs-measure because this lead me to align before processing. Okay so align.process() would be the way to go. Thanks for the link but drawing the box is not my concern. I would be interested in some fancy 2-line code for doing this:
in C++, if possible. |
This is the only C++ method that I personally know of for defining the X-Y of a bounding box with C++: |
Thanks a lot. ;) |
Sorry to border you again, but I still have some issues with the correct alignment of the depth and RGB data. As hopefully visible in the image below, the masks (blue) which were perfectly recognized in the RGB image by a CNN, are not aligned with the real objects (in the depth image). There is a slight shift to the right. I would comprehend if this shift would emerge in the other direction, since the origin of the depth image and the RGB sensor are 15mm apart, but the shift emerges in the other direction. I´ve found some hints (e.g. #2445) to overcome this issue by switching on “Heuristic” in the RealSense-Viewer and using occlusion filters, but I haven´t found any functions in the pyrealsense2 library. Do you have any hints to overcome this? |
@sch1eicher It's no bother at all :) When aligning depth to color, the depth image should be aligned to the FOV size of the color sensor. Aligning to the color FOV is necessary because although the D415 camera models use the same imager component for both RGB and IR, on the D435 the IR imager component has a larger "wide" size (compared to the "standard" IR imager size of D415). Advice about use of the occlusion removal in your own program is provided in the link below: |
Many thanks for your fast response :)
already align the depth image to the FOV size of the color sensor? |
A Python alignment example program in the SDK called align_depth2color.py expresses the alignment like this: align_to = rs.stream.color It would look more like your own script if a variable substitution is not used for align: align = rs.align(rs.stream.color) |
Issue Description
Hi,
I'm quite new to the github comunity, therefore I am sorry if this issue is placed wrongly.
My current program processes the RGB data (from the camera) in a CNN (Mask R-CNN) and returns polygons of the recognized objects. I would like to crop the recognized objects from the depth data (stored in a ply file) for further processing (pose estimation). The problem is that the depth data is not correctly aligned with the RGB data and I haven't found a solution in python to crop only the points from the ply file.
When I use the 3D view in RealSensce Viewer (2.29.0) the depth and RGB data seems like to be aligned perfectly.
If you might got a hint, I would be thankful.
The text was updated successfully, but these errors were encountered: