allow user to set buffer size and framerate
This commit is contained in:
parent
3a93ae2b37
commit
a6b6d0e889
@ -10,7 +10,7 @@ void Grabber::run() {
|
|||||||
Pylon::CInstantCamera *cam = camera->getCamera();
|
Pylon::CInstantCamera *cam = camera->getCamera();
|
||||||
cam->StartGrabbing();
|
cam->StartGrabbing();
|
||||||
while (!stop_request) {
|
while (!stop_request) {
|
||||||
camera->frameRate(50);
|
camera->frameRate(static_cast<uint>(framerate));
|
||||||
MyImage img;
|
MyImage img;
|
||||||
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
||||||
img.setFrame(frame);
|
img.setFrame(frame);
|
||||||
|
12
grabber.h
12
grabber.h
@ -10,22 +10,28 @@ class Grabber : public QThread
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Grabber(PylonWrapper *camera, ImageBuffer*buffer, QObject *parent = nullptr) :
|
Grabber(PylonWrapper *camera, ImageBuffer*buffer, int framerate, QObject *parent = nullptr) :
|
||||||
QThread(parent), camera(camera), buffer(buffer) {}
|
QThread(parent), camera(camera), buffer(buffer), framerate(framerate) {}
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
void stop();
|
void stop();
|
||||||
|
int currentFramerate() {
|
||||||
|
return framerate;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool stop_request = false;
|
bool stop_request = false;
|
||||||
PylonWrapper *camera;
|
PylonWrapper *camera;
|
||||||
ImageBuffer *buffer;
|
ImageBuffer *buffer;
|
||||||
|
int framerate;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void requestStop() {
|
void requestStop() {
|
||||||
stop_request=true;
|
stop_request=true;
|
||||||
}
|
}
|
||||||
|
void setFrameRate(int newFramerate) {
|
||||||
|
framerate = newFramerate;
|
||||||
|
}
|
||||||
signals:
|
signals:
|
||||||
void terminated();
|
void terminated();
|
||||||
};
|
};
|
||||||
|
@ -42,8 +42,8 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|||||||
setCentralWidget(scrollArea);
|
setCentralWidget(scrollArea);
|
||||||
|
|
||||||
pylon = new PylonWrapper();
|
pylon = new PylonWrapper();
|
||||||
buffer = new ImageBuffer(1000);
|
buffer = new ImageBuffer(defaultBufferSize);
|
||||||
grabber = new Grabber(pylon, buffer);
|
grabber = new Grabber(pylon, buffer, defaultFrameRate);
|
||||||
writer = new Writer(buffer);
|
writer = new Writer(buffer);
|
||||||
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
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"), this, &PylonRecorder::about);
|
||||||
helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt);
|
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");
|
QToolBar *toolbar = addToolBar("main toolbar");
|
||||||
toolbar->addAction(exitAct);
|
toolbar->addAction(exitAct);
|
||||||
toolbar->addSeparator();
|
toolbar->addSeparator();
|
||||||
@ -365,6 +382,11 @@ void PylonRecorder::createActions() {
|
|||||||
toolbar->addAction(grab_still_action);
|
toolbar->addAction(grab_still_action);
|
||||||
toolbar->addAction(grab_continuous_action);
|
toolbar->addAction(grab_continuous_action);
|
||||||
toolbar->addAction(grab_stop_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() {
|
void PylonRecorder::updateActions() {
|
||||||
@ -440,6 +462,10 @@ void PylonRecorder::startRecording() {
|
|||||||
specs.pixelType = settings.pixelType;
|
specs.pixelType = settings.pixelType;
|
||||||
specs.orientation = settings.orientation;
|
specs.orientation = settings.orientation;
|
||||||
specs.quality = 95;
|
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);
|
writer->setVideoSpecs(specs);
|
||||||
buffer->clear();
|
buffer->clear();
|
||||||
grabber->start();
|
grabber->start();
|
||||||
@ -450,7 +476,7 @@ void PylonRecorder::startRecording() {
|
|||||||
|
|
||||||
preassureTimer->start(50);
|
preassureTimer->start(50);
|
||||||
frameTimer->start(50);
|
frameTimer->start(50);
|
||||||
labelTimer->start(333);
|
labelTimer->start(650);
|
||||||
updateActions();
|
updateActions();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -470,8 +496,8 @@ void PylonRecorder::writerDone() {
|
|||||||
preassureBar->reset();
|
preassureBar->reset();
|
||||||
loadBar->reset();
|
loadBar->reset();
|
||||||
labelTimer->stop();
|
labelTimer->stop();
|
||||||
writingLabel->setEnabled(false);
|
writingLabel->setStyleSheet(inactiveLabelStyle);
|
||||||
grabbingLabel->setEnabled(false);
|
grabbingLabel->setStyleSheet(inactiveLabelStyle);
|
||||||
grabber->wait(10000);
|
grabber->wait(10000);
|
||||||
writer->wait(10000);
|
writer->wait(10000);
|
||||||
writing = false;
|
writing = false;
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QSpinBox>
|
||||||
|
|
||||||
#include "pylonwrapper.h"
|
#include "pylonwrapper.h"
|
||||||
#include "imagebuffer.h"
|
#include "imagebuffer.h"
|
||||||
#include "grabber.h"
|
#include "grabber.h"
|
||||||
@ -72,6 +74,7 @@ private:
|
|||||||
void applyScaling();
|
void applyScaling();
|
||||||
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
||||||
|
|
||||||
|
int defaultBufferSize = 1000, defaultFrameRate = 50;
|
||||||
QImage image;
|
QImage image;
|
||||||
QTimer *frameTimer, *preassureTimer, *labelTimer;
|
QTimer *frameTimer, *preassureTimer, *labelTimer;
|
||||||
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel;
|
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel;
|
||||||
@ -88,6 +91,7 @@ private:
|
|||||||
QString activeLabelStyleHigh = "QLabel { color : red; }";
|
QString activeLabelStyleHigh = "QLabel { color : red; }";
|
||||||
QString activeLabelStyleLow = "QLabel { color : cmyk(0, 255, 255, 0, 50); }";
|
QString activeLabelStyleLow = "QLabel { color : cmyk(0, 255, 255, 0, 50); }";
|
||||||
QString inactiveLabelStyle = ("QLabel { color :gray; }");
|
QString inactiveLabelStyle = ("QLabel { color :gray; }");
|
||||||
|
QSpinBox *framerateSpinner, *buffersizeSpinner;
|
||||||
|
|
||||||
|
|
||||||
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
|
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
|
||||||
|
Loading…
Reference in New Issue
Block a user