Items with no label
3335 Discussions

I want to save 60 frames per second with png.

지최
Beginner
1,376 Views

I refer to this example https://github.com/IntelRealSense/librealsense/blob/master/examples/save-to-disk/rs-save-to-disk.cpp librealsense/rs-save-to-disk.cpp at master · IntelRealSense/librealsense · GitHub

but this sample captures 30 frames and writes the last frame to disk.

How do I fix this example to save 60 frames per second to disk?

0 Kudos
4 Replies
MartyG
Honored Contributor III
422 Views

I would imagine that on line 30 of the script, you would change i < 30 to i < 60. This tells the 'For Loop' to keep processing until it reaches the 60th frame, and then go no further and return to the start to begin the loop again and check another 60 frames.

From:

for (auto i = 0; i < 30; ++i) pipe.wait_for_frames();

To:

for (auto i = 0; i < 60; ++i) pipe.wait_for_frames();

지최
Beginner
422 Views

I understand

but this example only saves the last frame, but I want to store all the frames to disk (all 60 frames)

Is there anything I need to fix in this code ?

0 Kudos
MartyG
Honored Contributor III
422 Views

Based on what I have heard from other users about saving PNGs, the program is likely to run very slow if you try to save every frame, and will disrupt the playing of the stream because of this processing lag. The notes in the script indicate that it is storing up a collection of frames before saving the final frame to give the auto-exposure time to settle.

If you really want to try to save every frame though .. if I were programming this script, I would try deleting lines 37,38 and 56, which seem to set up the 'If' check for whether it is the last frame of the sequence.

0 Kudos
BMana
Novice
422 Views

Hi,

In your for loop you can just store the frame in a std::vector or a std::map and at the end of your loop browse all your frames in your list to store thel in PGN.

Here is an exemple (I might forgot some include) :

# include

 

# include

 

typedef map<<span style="color: # b9bcd1;">string, cv::Mat> FrameMap;

 

static FrameMap frame_map;

void saveFrame(const cv::Mat &dMat, const string &filename) {

frame_map.emplace(filename, dMat.clone());

 

}

void save_ram() {

auto full_size = frame_map.size();

 

while(!frame_map.empty()){

string filename = frame_map.begin()->first;

 

cv::Mat dMat = frame_map.begin()->second;

 

 

cv::imwrite(filename, dMat);

 

confirmeSave(filename);

 

 

frame_map.erase(filename);

 

 

cout << </span>"Saving images : " << </span>100*(full_size-frame_map.size())/full_size << </span>"%" << </span>endl;

 

}

clear_ram();

 

}

void clear_ram() {

frame_map.clear();

 

}

void export_color(rs2::frameset, std::string filename) {

auto colored_frame = frames.get_color_frame();

 

int width = colored_frame.get_width();

 

int height = colored_frame.get_height();

 

cv::Mat dMat(cv::Size(width, height), CV_8UC3, (void*) colored_frame.get_data());

 

cv::Mat rgb_dMat;

 

cv::cvtColor(dMat, rgb_dMat,CV_BGR2RGB);

 

frame_map.emplace(rgb_dMat, filename));

}

int main(<span style="color: # cc7832; font-we...

Reply