[grabber] add grabber thread
This commit is contained in:
parent
3071c0bc3b
commit
c41d4ed035
13
grabber.cpp
Normal file
13
grabber.cpp
Normal 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
28
grabber.h
Normal 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
|
@ -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() {}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user