I am developing an application, the main goal is to capture images from the frame invader, do some processing, and then show the images in a graphical interface. The cooling tower is connected to PCIe. And I use the SDK to capture frames. Image flow is rather slow from 10 to 100 images / s. I am here to get some tips about my code and how to optimize it. Firstly, there is my run () function from a class inherited from Qthread. I grab the image and put it in the queuecv :: Mat> buffer.
void ImageIn::run(){ _cam->allocMemory(); _cam->startAquisition(); _runningThread = true; while(_runningThread) { Mat image(_cam.getSizeX(), _cam.getSizeY(), CV_16U, _cam->getImageDMA0()); _ctrl->getMutexIn()->lock();
Images are stored in a buffer, and then the processing thread does some work ...
void ImageProcessing::run(){ while(_runningThread){ if (_ctrl->getMutexIn()->tryLock()){ while(!_ctrl->getBufferIn()->empty()){ _ctrl->getBufferIn()->front().convertTo(tempConvert, CV_32F); _bufferLocalIn.push(tempConvert); _ctrl->getBufferIn()->pop(); } _ctrl->getMutexIn()->unlock(); }
So, I have a few questions: - Stream 1 receives images thanks to the lock function, so the processor consumption is low, but stream 2 runs continuously and consumes a lot of processor reevaluation, what can I do to fix it? - Is this the correct code?
So I tried:
QThread* thread = new QThread; ImageWriter* worker = new ImageWriter(); worker->moveToThread(thread); QTimer* timer = new QTimer(); int msec = 100; timer->setInterval(msec); QObject::connect(thread, SIGNAL(started()), worker, SLOT(process())); QObject::connect(worker, SIGNAL(finished()), thread, SLOT(quit())); QObject::connect(timer, SIGNAL(timeout()), thread, SLOT(start())); timer->start();
this is normal?