-
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
Save Left Right camera videos and then construct depth from it later #13346
Comments
Hi @Hasnain1997-ai Intel's Depth from Stereo beginner guide at the link below provides Python code for using rectified left and right images with block-matching to create a depth map. https://github.com/IntelRealSense/librealsense/blob/master/doc/depth-from-stereo.md Alternatively, you could use OpenCV's StereoBM depth engine to create the depth image from left and right images, as described at #5950 (comment) https://docs.opencv.org/4.x/dd/d53/tutorial_py_depthmap.html |
I used both methods mentioned, but I am not getting the same results as when I save the depth as a frame from the RealSense D415 |
When a RealSense 400 Series camera constructs a depth frame from raw left and right images, it does so in a piece of hardware inside the camera called the Vision Processor D4 Board that applies a distortion model and rectification to the depth image. If you construct the depth frame manually yourself then this may account for the differences between a RealSense depth frame and your self-constructed depth frame (which will not have been processed on the Vision Processor D4 board). |
Suppose I have deployed the camera in an operational environment and saved the left and right camera videos (as they are lighter than the depth video). After returning from the deployment, I want to run some tests on the depth frames. I currently have:
Is there any code I can use to reconstruct the depth frames using the camera's Vision Processor D4 Board with my saved left and right videos? |
To have that level of control over the camera's raw streams at the point of capture in the camera hardware, you would likely have to make use of RealSense's Low-Level Device API https://dev.intelrealsense.com/docs/api-architecture#low-level-device-api There are very few programs that make use of the Low-Level Device API, so there are not many programming references. An SDK program that does make use of the API is rs-data-collect, as described at IntelRealSense/realsense-ros#1409 |
My goal is to make the Depth Video from the saved Left And Right Camera videos. The Depth Video should be the same as that of when recorded from realSense d415 using the D415 camera How can I achieve |
Whilst it may be possible to combine single left and right image frames into a depth image in OpenCV, I am not aware of a way to do this with a live stream of images, unfortunately. It is not usually something that is attempted with RealSense cameras because the camera creates the depth frame for you automatically. The RealSense SDK does have an interface called software-device that enables you to generate frames in OpenCV and feed them into the RealSense SDK via software-device. It works better with C++ language than it does with Python though. https://github.com/IntelRealSense/librealsense/tree/master/examples/software-device |
Can I replace the camera's left and right frames with the left and right frames from a video? Explanation: |
You could do that if you recorded the frames into a .bag format file, which is like a video recording of camera data. If you insert an enable_device_from_file() config instruction before the pipeline start line then the script can use the data in the bag file as its data source instead of a live camera. |
Hi MartyG, |
Bag files are the best way of storing RealSense data but yes, they are multi-GB files. There is not much that can be done to reduce the size except for using a lower stream resolution or FPS speed. |
So how can I make a workout for it bcs My use case is that I have to deploy the camera in an operational environment and save data there |
I would strongly recommend not creating your own custom depth frame and just using the RealSense depth stream. All the work of combining the left and right frames is done for you, and you only need to have the depth stream enabled when recording and not the left and right infrared streams too. If you need the stored data to be compact and you only need single frames and not to capture continuously like a video then exporting the depth map to a .png image file with Python code might work well for you. This file will have a very small size. A lot of the depth value information of the coordinates is lost when saving to .png, but you should have a visually accurate record of the depth map. |
I My use case is that I have to deploy the camera in an operational environment and save data there(video data). |
#2731 (comment) has a Python script for saving depth and color to .avi video file. You could edit that script to remove the color references so that it only saves depth to .avi video. |
Suppose I save depth to .avi video file |
An .avi video file will play back in a standard video player application and provide a visual record of the depth map. It is not importable back into the RealSense SDK though to perform further calculation on it. You can use Python code to save a single frame of RealSense depth data to a bag file with an instruction called 'save_single_frameset()' and so greatly reduce the file size. A Python example script for this can be found at the link below. A bag file can be imported into a RealSense script and used as the data source by the script as though it were a live camera. If you want to save a continuous video-like stream of camera data that can be imported back into the RealSense SDK and have calculations done on it, a multi-gigabyte .bag file is the only option, unfortunately. |
Apart from.bag there is no other method to save the data and then use it later |
Aside from the bag format, you could generate a depth point cloud and export it to a . ply format file. You can then import a .ply into a 3D tool such as MeshLab to do further work on the data. https://www.andreasjakl.com/capturing-3d-point-cloud-intel-realsense-converting-mesh-meshlab/ You can also save the depth data to a .csv file, which is a text-based representation of the coordinates and their values that can be imported into a database or spreadsheet application. .ply and .csv cannot be imported back into the RealSense SDK though. The SDK does have an interface called software-device for importing data in formats not usually supported for import, such as .png images. The example below demonstrates using a .png images to generate a depth pointcloud image in the SDK. https://github.com/IntelRealSense/librealsense/tree/master/examples/software-device It should also be possible to feed video frames into the software-device interface from OpenCV. |
Any Python code? for software-device? |
Isued this code to store the data images(depth and RGB) in
######################## End of first part - capture images from live device ####################################### I am using this code to load the npys and put the images(depth and RGB) in the camera
But while reconstruction I am getting the depth and RGB frames empty ie |
SO is this the correct method? |
The subject of loading npy files with np.load is outside of my programming knowledge unfortunately, so I do not have commentary to offer about the code's correctness. I do apologize. Another RealSense user's approach to using np.load to load data from an npy file can be found at #10431 (comment) Another approach I found to using np.load for the depth image is shown in the snapshot below. |
I save the depth using
Now Thne I load it using the code
Now I want to find distacne of a pixel ie
I am getting depth ie depth_tl =0 always although while save the data I check and the depth was not zero and I saved those frames and depth for which the depth is not zero then I used the code to load the saved depth and frame npy and then when I found the depth it is zero How can I correct it? any suggestion about what I am doing wrong? |
#13346 (comment) is a good example of a Python script for retrieving a coordinate's real-world distance with the get_distance() instruction. |
my question is that although while saving the data I checked and the depth was not zero I saved those frames and depth for which the depth was not zero then I used the code to load the saved depth and frame .npy and then when I found the depth it was zero How can I correct it? Do you have any suggestion about what I am doing wrong? |
I do not have any advice to offer about what the problem may be, unfortunately, as I do not have knowledge of software-device or .npy programming. I do apologize. |
So what method I should use to save the depth data |
An alternative way to get the real-world depth value of a coordinate without using rs2_deproject_pixel_to_point or depth-color alignment is to convert a color pixel into a depth pixel using rs2_project_color_pixel_to_depth_pixel. A Python script at #5603 (comment) demonstrates this principle. |
Hi @Hasnain1997-ai Do you require further assistance with this case, please? Thanks! |
So I saved the data using the code below:
Then I estimted the dimension using these saved data for which I used the code:
SO using this code I estimated the dimensions of the object. but there was a discrepancy b/w the original and the estiamed dimension |
A possible cause of error could be that you are multiplying depth_image by the depth scale to calculate the scaled_depth_image value.
There are two main ways of calculating the real-world distance in meters: (1) multiply the raw pixel depth value by the camera's depth scale value; or (2) use the get_distance() instruction. One method or the other should be used, but not both methods in the same script, as get_distance() already automatically takes account of the camera's depth scale without you having to provide it. |
So you are suggesting that |
If depth_image represents the pixel depth value then multiplying it by the D415's depth scale (which is 0.001) will give the coordinate's real-world distance in meters. For example, if the pixel depth value was '4000' then 4000 x 0.001 = 4 (real-world meters). |
I save the depth image as above So what should I do now, to get the correct distance |
Are you aiming to get the distance from a saved .npy file? If you are then gdlg/panoramic-depth-estimation#3 - whilst not a librealsense case - advises loading an .npy file containing depth data with the numpy instruction np.load (an instruction you are already using) to retrieve the depth value for each pixel from an array. |
Hi,
I’m new to using RealSense cameras and don’t know much about them, so I need some help.
I have a RealSense D415 camera connected to my Xavier, and I’m working with it using Python.
I want to save the left and right camera videos along with all the necessary configurations. Later, when I need to (since I’ll have the left and right videos and the configuration saved), I want to reconstruct the depth frames using the left and right videos and the saved configurations with the camera connected to the Xavier.
How can I achieve this using Python?
If you can provide any code, that would be great.
Thanks.
Details:
The text was updated successfully, but these errors were encountered: