-
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 depth data into file #1485
Comments
I'm basically trying to do the same thing. I've tried some of these examples https://github.com/IntelRealSense/librealsense/tree/master/examples For rs-save-to-disk.cpp for example, here is what I did (I'm using ubuntu 16.04)
$ g++ -std=c++11 rs-save-to-disk.cpp -lrealsense2 The result is a file called a.out that I see in my home directory (still have no idea what is is). It doesn't seem like anything worked. |
@martijnkusters Sorry I just went to lunch. So the output of the thing I ran above is an a.out file that you can run using: $ ./a.out #just put a ./ in front of the output file and it runs This returns two png files, one depth and one rgb |
I can save the depth and rgb as png files, but what I want to do is to save the Raw depth data in a data file format likes csv or txt. |
bool save_frame_raw_data(const std::string& filename, rs2::frame frame)
{
bool ret = false;
auto image = frame.as<video_frame>();
if (image)
{
std::ofstream outfile(filename.data(), std::ofstream::binary);
outfile.write(static_cast<const char*>(image.get_data()), image.get_height()*image.get_stride_in_bytes());
outfile.close();
ret = true;
}
return ret;
} |
And is there already code to save this depth data in a matlab format? |
@dorodnic can you briefly explain the code and the context in which it has to be inserted? |
Of course. @martijnkusters I'm not sure what is matlab format, however there must be ways to import raw byte array in matlab. Generating giant CSV with depth values in meters is also not very complicated, please let us know if you need help. |
@dorodnic @martijnkusters Ok so just to tie the knot I'm pasting the code I'm using here. First, I started with the rs.capture.cpp and removed all the opengl nonsense because something isnt working there for me (which is fine I don't need to see the video as it's streaming I can do that in the downstream analysis). When I run the code below, the camera simply streams (I can tell that by the ir): #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API // Capture Example demonstrates how to
} NOW, I want to simply save the depth stream as a binary (little endian is preferred but it doesnt really matter) text file. I want each pixel to be a number that represents distance from the camera. You're saying to do that I need to copy and paste the code above like so: #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API // Capture Example demonstrates how to bool save_frame_raw_data(const std::string& filename, rs2::frame frame) //this function
} int main(int argc, char * argv[]) try
} What I'm doing is copying the function on the top and calling the function where you said to insert it. Of course there are errors because I have no idea what I'm doing and I can not follow variables well in c++. Is this totally wrong? Does the function need to be defined somewhere else? Here are the errors below: rockwell@rockwell-asus:~/Behavior_From_Depth_Cameras$ g++ -std=c++11 rs-recorddepth.cpp -lrealsense2 Also thanks for your help. I know I'm a lot of trouble! |
I think To save you some time I modified |
@dorodnic Thanks so much Sergey!! I can't wait to get to my local machine and try it out! I'll let you know how it goes as soon as possible. @martijnkusters once I have this working I can help you with the Matlab part (if you haven't done it already) |
@dorodnic so something is def working! I was able to get multiple depth AND color csv files. I need to look into it more (I only had 5 minutes at my machine and I ran it quickly) and see why it's breaking it up into multiple files (but this may not be a problem). Thanks so much! Here is what it looked like |
I'm appending the frame number to the filename at lines 19 and 44, if you just want to save just the last frame remove the |
Thank you for the work. I will try the code. Currently I also changed the align example with some lines to capture depth and pointclouds and write it into a txt file to read it with matlab. Best Regards, ofstream myfile("c:/tmp/depth" + IntToStr(j) +".txt");
|
Next step is to calibrate the camera. |
@dorodnic something that i noticed when running the rs-capture.cpp script is that a lot of frames were skipped. Is there anything I can do about that? |
I'm basically only saving ~10% of the frames. Does it take too long to open and write and close a file each time? |
There are two simple things you can do:
However, saving data to CSV is extremely not efficient by definition. You can choose a hybrid approach of recording into |
@dorodnic Ok I will try both options. (I really hope the second one works especially since im just using my laptop now). I do have a script for extracting the bagfiles but it’s super slow. In fact, the slowness is one the reason I wanted to try and write to disk. Would it be faster to write a binary file instead? Also, Im not thrilled about doing the bag exteactiin because it requires me to use ROS and thats something I could not download without sudo access. I therefore cannot process it using my universities cluster. Is there a very fast way to extract the bagfiles? If I wantd to do some real time feature detections, would it be too slow to analyze frames in the bag file? |
@dorodnic I was talking with some members of my lab about this issue and it seems like the best solution for us would be to save the depth information as a long string of bytes into one file. If each pixel is 16 bytes, then we can save a really long string of bytes. Since we know the resolution we can do whatever we want afterwards. I guess this brings us back to the original code snippet you suggested, however I tried: #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API #include bool save_frame_raw_data(const std::string& filename, rs2::frame frame)
} // Capture Example demonstrates how to
} and got the following errors: also pasted here as text |
ok im a fool i just needed to change <video_frame> to rs::video_frame |
ok so basically I've gotten it to "work". The script: #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API #include bool save_frame_raw_data(const std::string& filename, rs2::frame frame)
} // Capture Example demonstrates how to
} |
[Realsense Customer Engineering Team Comment] thanks for sharing your experience, do you need more help on this topic? |
[Realsense Customer Engineering Team Comment] |
I have a question about saving data to file. Is it possible to save frameset as whole, as below:
then, in a separate post-processing step, we can simply do the following to retrieve all the data rs2::frameset frameset_r = read_frameset("1.bin"); Note that this is different from recording, since here the user can choose which framesets to save. Thanks. |
You can use, |
I'm using RealSense 2.20 and task is to capture image with D415 and convert that image to rgb-d data and convert that data into xyz for pointcloud 3D demonstration |
i'm actually looking to implement this research http://rgbd.cs.princeton.edu/ |
Here is an example to get RGB data from point how to get XYZ RGB data from RealSense |
I like to save the depth data into a file for the D400 camera.
I work in c++. Is there some example available that I can use.
Best Regards,
Martijn
The text was updated successfully, but these errors were encountered: