Speed ​​up writing images to your hard drive in OpenCV

I work with a camera at a frequency of 50 frames per second (in the Ubuntu environment and Qt framework), and every 20 ms I get a frame for processing.

I wrote code to read images from the camera, and then saved them to my hard drive.

while(3.14)
{
 cv::Mat Camera_Image = Capture_Image();
 double T1 = (double)cv::getTickCount();
 cv::imwrite (STORE_ADDRESS,Camera_Image);
 T1 = (((double)cv::getTickCount() -T1)*1000)/cv::getTickFrequency();
 print(T1);
}

when I see the output, the time to write one image to the hard drive is about 30 ms for the image size of 2048 * 1080. Each image is single-channel (gray scale), but I write them in .jpg format on the hard drive. the size of each image on the hard disk is approximately 500 KB.

Since I have been taking pictures in about 20 ms, I cannot write them to the hard disk in real time. I wrote my code using Qthread and created a queue to see if there were any improvements, but the results were the same, and that was just the memory overhead.

Is it possible to change this situation or use another library to write these images to the hard drive much faster? I would also prefer a Qt solution if it is available ...

Plus, I need to write every single frame to the hard drive, so please do not suggest using Motion compression algorithms, since they do not apply to my situation ....

code: Mainwindow.cpp

 Qlist<cv::Mat> FINAL_IM_VEC;
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
{
  ui->setupUi(this);

  IMREAD *IMR = new IMREAD(this);   // an instance of IMREAD Class which reads camera frames
  IMWRITE *IMW = new IMWRITE(this);  // an instance of IMWRITE Class which Writes camera frames into hard disk
  QThread *IMAGE_READ_Thread = new QThread(this);
  QThread *Image_Store_Thread = new QThread(this);
  connect(IMAGE_READ_Thread,SIGNAL(started()),IMR,SLOT(IMREAD_Process()));
  connect(Image_Store_Thread,SIGNAL(started()),IMW,SLOT(IMWrite_Process()));
  IMR.moveToThread(IMAGE_READ_Thread);
  IMW.moveToThread(Image_Store_Thread);
  IMAGE_READ_Thread->start();
  Image_Store_Thread->start();
}

imread.hpp

class IMREAD : public QObject
{
    Q_OBJECT
public:
    explicit IMREAD(QObject *parent = 0);

signals:

public slots:
    void IMREAD_Process();
private:
    bool Stop;
};

imread.cpp

IMREAD::IMREAD(QObject *parent) :
    QObject(parent)
{
  this->Stop = false;
}

void IMREAD::IMREAD_Process()
{

  while(!Stop)
    {
          cv::Mat Image = CAM::Campture_F(25);//wait a maximum of 25 milisecond to grab a new frame
          if(Image.data())
            {
          FINAL_IM_VEC.push_back(Image);
            }
      }
    }

}

imwrite.hpp

#ifndef IMWRITE_H
#define IMWRITE_H
#pragma once
#include <QObject>
class IMWRITE : public QObject
{
    Q_OBJECT
public:
    explicit IMWRITE(QObject *parent = 0);
signals:

public slots:
    void IMWrite_Process();
private:
    bool Stop;
};

imwrite.cpp

IMWRITE::IMWRITE(QObject *parent) :
    QObject(parent)
{
  this->Stop =false;
}
void IMWRITE::IMWrite_Process()
{
    static int counter = 0;
    while(!Stop)
      {
        for(int i = 0 ; i < FINAL_IM_VEC.size() ; i++)
            {
                QString address = "/home/Provisioner/ThreadT/Results/" + QString::number(counter++) + ".jpg";
                cv::imwrite(address.toUtf8().constData(),FINAL_IM_VEC[i]);
                FINAL_IM_VEC.erase(FINAL_IM_VEC.begin() + i);
                i--;
            }
      }

}

, ... , ... - , , .

.

+4
5

: 2048 * 1080 * 3 ( ) * 50 fps ~ = 316MB/s, . JPEG, , , 1/5-, , 5400 / .

:

  • , .
  • , . , .
  • , . , .
+3

, - , ? 8 ? 12 ? 16 ?

, , : , -, , .

, , ?. , , , . , 50 + / 5- 0,25 , , " " . , 1MByte, , .

  • , , . , 8 , 2 /, 50 , 100 /. RAID 0 .

  • - , , JPEG2000 . GPU-, . , 2x, RAID 0 . - , , ( , ).

  • , jpeg . , 4 , 12,5 / , .

: , . , - . , . GPU , , . CPU , , .

, JPEG2k , 2x ( 4x), . Buch , . , , - .

, 1: 5 1:50 . , 1s , - 24 , 25 .

+3

.

JPEG (CV_IMWRITE_JPEG_QUALITY) 0 100 ( , ). - 95.

PNG (CV_IMWRITE_PNG_COMPRESSION) 0 9. A . 3.

PPM, PGM PBM ( CV_IMWRITE_PXM_BINARY), 0 1. - 1..

.bmp , .

: png > jpg > bmp

, , .bmp, 10 , png 6 , jpg.

+1

. , . /, / .

- , .

, , , , . , .

. , , . , , , 30 , , 30 . , . , 30 / . , .

0

QtMultimedia, , , MPEG.

This will not affect every pixel all the time, since only pixel differences will be processed. This can potentially improve performance for processing.

You could, of course, also look at more sophisticated compression algorithms, but that goes beyond Qt, and the Qt deal is likely to just interact with the algorithms.

0
source

All Articles