[grabber] add grabber thread

This commit is contained in:
Jan Grewe 2020-03-12 17:49:01 +01:00
parent 3071c0bc3b
commit c41d4ed035
5 changed files with 74 additions and 2 deletions

13
grabber.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "grabber.h"
#include <iostream>
void Grabber::run() {
int count = 0;
while (!stop_request) {
std::cerr << "running: " << count << std::endl;
count += 1;
msleep(500);
}
std::cerr << "terminated: " << count << std::endl;
//emit terminated();
}

28
grabber.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef GRABBER_H
#define GRABBER_H
#include <QObject>
#include <QThread>
class Grabber : public QThread
{
Q_OBJECT
public:
Grabber(QObject *parent = nullptr) : QThread(parent) {}
void run() override;
void stop();
private:
bool stop_request = false;
public slots:
void requestStop() {
stop_request=true;
}
signals:
void terminated();
};
#endif // GRABBER_H

View File

@ -19,6 +19,8 @@
#include <QStatusBar>
#include <QToolBar>
#include <iostream>
#include <chrono>
#include "grabber.h"
#if defined(QT_PRINTSUPPORT_LIB)
# include <QtPrintSupport/qtprintsupportglobal.h>
@ -310,7 +312,7 @@ void PylonRecorder::updateActions() {
disconnect_camera_action->setEnabled(pylon->isOpen());
connect_camera_action->setEnabled(!pylon->isOpen());
grab_still_action->setEnabled(pylon->isOpen());
grab_continuous_action->setEnabled(false);
grab_continuous_action->setEnabled(pylon->isOpen());
}
void PylonRecorder::scaleImage(double factor) {
@ -343,6 +345,7 @@ void PylonRecorder::connectCamera() {
pylon->openCamera(message);
statusBar()->showMessage(QString::fromStdString(message));
updateActions();
std::cerr << pylon->maxFrameRate() << std::endl;
}
@ -352,7 +355,31 @@ void PylonRecorder::disconnectCamera() {
updateActions();
}
void PylonRecorder::startRecording() {}
void PylonRecorder::startRecording() {
int framecount = 500;
Grabber grabber;
grabber.start();
Pylon::CGrabResultPtr frame;
if (pylon->isOpen()) {
pylon->frameRate(75);
Pylon::CInstantCamera *cam = pylon->getCamera();
cam->StartGrabbing();
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < framecount; ++i) {
MyImage img;
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
img.setFrame(frame);
buffer.push(img);
std::cerr << i << ": Buffer stats: capacity: " << buffer.capacity() << "\tload: " << buffer.bufferLoad() << "\t pressure: " << buffer.bufferPreassure() << "frameid: " << frame->GetID() << std::endl;
}
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
cam->StopGrabbing();
std::cerr << "elapsed time: " << elapsed.count() << " s\n";
}
grabber.requestStop();
grabber.wait(10000);
}
void PylonRecorder::stopRecording() {}

View File

@ -3,6 +3,7 @@
#include <QMainWindow>
#include "pylonwrapper.h"
#include "imagebuffer.h"
#include <QImage>
#if defined(QT_PRINTSUPPORT_LIB)
# include <QtPrintSupport/qtprintsupportglobal.h>
@ -65,6 +66,7 @@ private:
QScrollArea *scrollArea;
double scaleFactor = 1;
PylonWrapper *pylon;
ImageBuffer buffer;
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printer;

View File

@ -3,11 +3,13 @@ requires(qtConfig(filedialog))
qtHaveModule(printsupport): QT += gui printsupport
HEADERS = \
grabber.h \
imagebuffer.h \
myimage.h \
pylonrecorder.h \
pylonwrapper.h
SOURCES = \
grabber.cpp \
imagebuffer.cpp \
myimage.cpp \
pylonrecorder.cpp \