2 Replies Latest reply on Mar 19, 2018 2:47 PM by glc12125

    Quickly saving an image sequence from D435

    jmagen

      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

        • 1. Re: Quickly saving an image sequence from D435
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          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` 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 this modifying this value to 0  (0 no compression, 9 – max) should positively affect the performance.

          Regards,
          Jesus G.
          Intel Customer Support

          • 2. Re: Quickly saving an image sequence from D435
            glc12125

            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.