rs-measure.cpp funcrion dist_3d()
Is there alternate faster code available that measures the 3d distance?
Is get_distance and rs2_deproject_pixel_to_point fast or should I be digging into the code?
Thanks.
// Query the frame for distance
// Note: this can be optimized
// It is not recommended to issue an API call for each pixel
// (since the compiler can't inline these)
// However, in this example it is not one of the bottlenecks
auto udist = frame.get_distance(upixel[0], upixel[1]);
auto vdist = frame.get_distance(vpixel[0], vpixel[1]);
// Deproject from pixel to point in 3D
rs2_intrinsics intr = frame.get_profile().as<rs2::video_stream_profile>().get_intrinsics(); // Calibration data
rs2_deproject_pixel_to_point(upoint, &intr, upixel, udist);
rs2_deproject_pixel_to_point(vpoint, &intr, vpixel, vdist);
-
There is a simple sample script in the documentation for using get_distance to measure the distance from camera to object without deprojection.
https://github.com/IntelRealSense/librealsense#ready-to-hack
You can also speed up processing by offloading work from the CPU to a GPU.
https://github.com/IntelRealSense/librealsense/issues/5440#issuecomment-565124976
-
So I'm seeing that using the depth_frame I don't need to bother with the deprojection process in rs-measure. Is that right?
I am NVIDIA so I'll also l look at the CUDA support and try and figure out what that means.
Are "aligned" frames where color and depth data are aligned? I only need depth data so I'll want to use "unalignd" frames. Is there something specific I have to do to have the frames unaligned or is that implied when using the depth_frame?
-
My understanding is that deprojection is of use when converting 2D to 3D (such as a 2D image to a 3D point cloud) but may be unnecessary if measuring the distance from camera to object in a 3D real-world scene, or if you do not need to get the XYZ coordinates of points in a scene.
Alignment between depth and color frames is something that has to be specifically programmed. It would be unaligned by default.
-
You can override the default configuration of the camera and define your own, with only a depth stream, by placing 'cfg' (config) instructions directly before the pipe.start instruction.
The link below has example code for defining a cfg for the depth stream (leave out the line that defines a color stream).
https://github.com/IntelRealSense/librealsense/issues/5194#issuecomment-550297207
-
With a cfg definition, the only streams that get defined are the ones you specify. If there is no cfg defined then the camera automatically uses the default settings for that particular RealSense model.
You're very welcome. Feel free to ask questions any time you need to. Good luck!
-
last post on this - the 3d distance code makes sense. It's uses the same get_distance function as in the link you posted.
I was confused by the comments in the function.
// Note: this can be optimized
// It is not recommended to issue an API call for each pixel
// (since the compiler can't inline these)
// However, in this example it is not one of the bottlenecksit's not important though. I'm sure it will all make more sense as I use the product.
-
I wonder if using sub-sampling post processing might help. A quote of documentation is below.
****************
We usually recommend doing a non-zero mean for a pixel and its neighbors. All stereo algorithms do involve some convolution operations, so reducing the (X, Y) resolution after capture is usually very beneficial for reducing the required compute for higher-level apps. A factor of 2 reduction in resolution will speed subsequent processing up by 4x, and a scale factor of 4 will decrease compute by 16x.
Moreover, the subsampling can be used to do some rudimentary hole filling and smoothing of data using either a non-zero mean or non-zero median function. Finally, sub-sampling actually tends to help with the visualization of the point-cloud as well.
***************
Section 1. Sub-Sampling in the post-processing documentation in the link below expands upon this information.
-
As the post-processing guide mentions, the Decimation Filter does sub-sampling, and Intel have a sample program tutorial in the link below.
https://github.com/IntelRealSense/librealsense/tree/master/examples/post-processing
A look through the source code of the SDK's Decimation Filter found that it already has use of medians built in. The "Measure" program that you looked at earlier has Decimation Filter code that you should be able to adapt for your own program.
Please sign in to leave a comment.
Comments
13 comments