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);
IMWRITE *IMW = new IMWRITE(this);
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);
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--;
}
}
}
, ... , ... - , , .
.