Items with no label
3335 Discussions

Quickly saving an image sequence from D435

JMage
Beginner
1,804 Views

Hi everyone,

I have taken the rs-save-to-disk approach to capture an image sequence from a D435 camera (on a button click) to be converted into a video file. The only problem is that the stbi_write_png() function is slow. The stream itself runs at a smooth 30fps when this function is not being called; when the function is called, however, everything slows down; frames are saved at a rate of 4 frames per second and the stream's deteriorated framerate reflects this.

Does anyone know of a faster, alternative method to stbi_write_png() for saving an image sequence? If possible, I would like to capture frames at the same rate in which the vid_frames are displayed in the stream.

Thank you,

jmagen

0 Kudos
2 Replies
idata
Employee
497 Views

Hello Jmagen,

 

 

We hope the following suggestions help you.
  1. Offload the save routine to a dedicated thread (using librealsense queus to pass frames around). You may also `frame.keep` API to keep . This should be sufficient to save sequences of (at least) tens of frames
  2. PNG has an built-in compression mechanism. According to `stbi` https://github.com/nothings/stb/blob/master/stb_image_write.h documentation it is enabled by default: PNG allows you to set the deflate compression level by setting the global variable 'stbi_write_png_compression_level' (it defaults to 8)."
We haven't experimented with the feature, but according to https://superuser.com/questions/845394/how-is-png-lossless-given-that-it-has-a-compression-parameter this modifying this value to 0 (0 no compression, 9 – max) should positively affect the performance.

 

 

Regards,

 

Jesus G.

 

Intel Customer Support

 

0 Kudos
LGu4
Beginner
497 Views

Hey jmagen,

Can you try OpenCV? More specifically, using the following:

cv::Mat rgbMat(height, width, CV_8UC3); // Create OpenCV inputArray for saving, CV_8UC3 for color and depth images, CV_8UC1 for INFRARED images

memcpy(rgbMat.data, frame.get_data(), sizeof(unsigned char) * IMAGE_SIZE); // copy from frame, IMAGE_SIZE is the WIDTH * HEIGHT * bytes_per_pixel

cv::imwrite(filename, rgbMat); // save to disk

You can do this either in a dedicated thread or the same thread as the fetching of frames. The latter case will give you around 10Hz frequency.

0 Kudos
Reply