allow user to set buffer size and framerate

This commit is contained in:
Jan Grewe 2020-03-16 12:23:15 +01:00
parent 3a93ae2b37
commit a6b6d0e889
4 changed files with 45 additions and 9 deletions

View File

@ -10,7 +10,7 @@ void Grabber::run() {
Pylon::CInstantCamera *cam = camera->getCamera();
cam->StartGrabbing();
while (!stop_request) {
camera->frameRate(50);
camera->frameRate(static_cast<uint>(framerate));
MyImage img;
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
img.setFrame(frame);

View File

@ -10,22 +10,28 @@ class Grabber : public QThread
{
Q_OBJECT
public:
Grabber(PylonWrapper *camera, ImageBuffer*buffer, QObject *parent = nullptr) :
QThread(parent), camera(camera), buffer(buffer) {}
Grabber(PylonWrapper *camera, ImageBuffer*buffer, int framerate, QObject *parent = nullptr) :
QThread(parent), camera(camera), buffer(buffer), framerate(framerate) {}
void run() override;
void stop();
int currentFramerate() {
return framerate;
}
private:
bool stop_request = false;
PylonWrapper *camera;
ImageBuffer *buffer;
int framerate;
public slots:
void requestStop() {
stop_request=true;
}
void setFrameRate(int newFramerate) {
framerate = newFramerate;
}
signals:
void terminated();
};

View File

@ -42,8 +42,8 @@ PylonRecorder::PylonRecorder(QWidget *parent)
setCentralWidget(scrollArea);
pylon = new PylonWrapper();
buffer = new ImageBuffer(1000);
grabber = new Grabber(pylon, buffer);
buffer = new ImageBuffer(defaultBufferSize);
grabber = new Grabber(pylon, buffer, defaultFrameRate);
writer = new Writer(buffer);
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
@ -356,6 +356,23 @@ void PylonRecorder::createActions() {
helpMenu->addAction(tr("&About"), this, &PylonRecorder::about);
helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt);
framerateSpinner = new QSpinBox();
framerateSpinner->setRange(1, 120);
framerateSpinner->setSuffix("Hz");
framerateSpinner->setFixedWidth(120);
framerateSpinner->setFixedHeight(30);
framerateSpinner->setValue(defaultFrameRate);
framerateSpinner->setStyleSheet("QSpinBox{font-size: 10px;font-family: Arial;color: rgb(0, 0, 0);background-color: rgb(255,255,255);}");
//framerateSpinner->setStyleSheet("QSpinBox{font-size: 10px;font-family: Arial;color: rgb(255, 255, 255);background-color: rgb(38,56,76);}");
buffersizeSpinner = new QSpinBox();
buffersizeSpinner->setRange(100, 5000);
buffersizeSpinner->setSingleStep(25);
buffersizeSpinner->setValue(defaultBufferSize);
buffersizeSpinner->setFixedSize(120, 30);
buffersizeSpinner->setStyleSheet("QSpinBox{font-size: 10px;font-family: Arial;color: rgb(0, 0, 0);background-color: rgb(255,255,255);}");
QToolBar *toolbar = addToolBar("main toolbar");
toolbar->addAction(exitAct);
toolbar->addSeparator();
@ -365,6 +382,11 @@ void PylonRecorder::createActions() {
toolbar->addAction(grab_still_action);
toolbar->addAction(grab_continuous_action);
toolbar->addAction(grab_stop_action);
toolbar->addSeparator();
toolbar->addWidget(new QLabel("frame rate:"));
toolbar->addWidget(framerateSpinner);
toolbar->addWidget(new QLabel("buffer size:"));
toolbar->addWidget(buffersizeSpinner);
}
void PylonRecorder::updateActions() {
@ -440,6 +462,10 @@ void PylonRecorder::startRecording() {
specs.pixelType = settings.pixelType;
specs.orientation = settings.orientation;
specs.quality = 95;
if (buffersizeSpinner->value() != static_cast<int>(buffer->capacity()))
buffer->resize(static_cast<size_t>(buffersizeSpinner->value()));
if (framerateSpinner->value() != grabber->currentFramerate())
grabber->setFrameRate(framerateSpinner->value());
writer->setVideoSpecs(specs);
buffer->clear();
grabber->start();
@ -450,7 +476,7 @@ void PylonRecorder::startRecording() {
preassureTimer->start(50);
frameTimer->start(50);
labelTimer->start(333);
labelTimer->start(650);
updateActions();
}
@ -470,8 +496,8 @@ void PylonRecorder::writerDone() {
preassureBar->reset();
loadBar->reset();
labelTimer->stop();
writingLabel->setEnabled(false);
grabbingLabel->setEnabled(false);
writingLabel->setStyleSheet(inactiveLabelStyle);
grabbingLabel->setStyleSheet(inactiveLabelStyle);
grabber->wait(10000);
writer->wait(10000);
writing = false;

View File

@ -3,6 +3,8 @@
#include <QMainWindow>
#include <QTimer>
#include <QSpinBox>
#include "pylonwrapper.h"
#include "imagebuffer.h"
#include "grabber.h"
@ -72,6 +74,7 @@ private:
void applyScaling();
void adjustScrollBar(QScrollBar *scrollBar, double factor);
int defaultBufferSize = 1000, defaultFrameRate = 50;
QImage image;
QTimer *frameTimer, *preassureTimer, *labelTimer;
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel;
@ -88,6 +91,7 @@ private:
QString activeLabelStyleHigh = "QLabel { color : red; }";
QString activeLabelStyleLow = "QLabel { color : cmyk(0, 255, 255, 0, 50); }";
QString inactiveLabelStyle = ("QLabel { color :gray; }");
QSpinBox *framerateSpinner, *buffersizeSpinner;
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)