[ui] add progress bar, add timers for buffer preassure and displaying images
This commit is contained in:
parent
506bb98879
commit
df27794dd5
@ -3,13 +3,14 @@
|
||||
#include <pylon/PylonIncludes.h>
|
||||
|
||||
void Grabber::run() {
|
||||
stop_request = false;
|
||||
int count = 0;
|
||||
if (camera->isOpen()) {
|
||||
Pylon::CGrabResultPtr frame;
|
||||
Pylon::CInstantCamera *cam = camera->getCamera();
|
||||
cam->StartGrabbing();
|
||||
while (!stop_request) {
|
||||
camera->frameRate(75);
|
||||
camera->frameRate(25);
|
||||
MyImage img;
|
||||
cam->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
||||
img.setFrame(frame);
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
//nclude <QColorSpace>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QImageReader>
|
||||
@ -20,6 +19,7 @@
|
||||
#include <QToolBar>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
|
||||
#if defined(QT_PRINTSUPPORT_LIB)
|
||||
# include <QtPrintSupport/qtprintsupportglobal.h>
|
||||
@ -45,8 +45,24 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
||||
grabber = new Grabber(pylon, buffer);
|
||||
createActions();
|
||||
updateActions();
|
||||
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
||||
|
||||
frameTimer = new QTimer(this);
|
||||
connect(frameTimer, &QTimer::timeout, this, &PylonRecorder::displaySingleFrame);
|
||||
preassureTimer = new QTimer(this);
|
||||
connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPreassure);
|
||||
|
||||
preassureBar = new QProgressBar(this);
|
||||
preassureBar->setRange(0, 100);
|
||||
preassureBar->setTextVisible(true);
|
||||
QColor color = progressColor(0);
|
||||
QPalette progressPalette = preassureBar->palette();
|
||||
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
|
||||
preassureBar->setPalette(progressPalette);
|
||||
QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
|
||||
|
||||
statusBar()->addWidget(preassureLabel);
|
||||
statusBar()->addWidget(preassureBar);
|
||||
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
||||
}
|
||||
|
||||
PylonRecorder::~PylonRecorder(){
|
||||
@ -234,6 +250,10 @@ void PylonRecorder::about() {
|
||||
void PylonRecorder::createActions() {
|
||||
const QIcon connect_icon(":/images/connect.png");
|
||||
const QIcon disconnect_icon(":/images/disconnect.png");
|
||||
const QIcon snapshot_icon(":/images/snapshot.png");
|
||||
const QIcon grab_icon(":/images/record.png");
|
||||
const QIcon stop_icon(":/images/stop.png");
|
||||
const QIcon exit_icon(":/images/exit.png");
|
||||
|
||||
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
|
||||
@ -249,7 +269,7 @@ void PylonRecorder::createActions() {
|
||||
|
||||
fileMenu->addSeparator();
|
||||
|
||||
QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &PylonRecorder::quitApplication);
|
||||
QAction *exitAct = fileMenu->addAction(exit_icon, tr("E&xit"), this, &PylonRecorder::quitApplication);
|
||||
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||
|
||||
QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
|
||||
@ -283,23 +303,24 @@ void PylonRecorder::createActions() {
|
||||
fitToWindowAct->setShortcut(tr("Ctrl+F"));
|
||||
|
||||
QMenu *camera_menu = menuBar()->addMenu(tr("&Camera"));
|
||||
connect_camera_action = camera_menu->addAction(connect_icon, tr("&Connect"), this, &PylonRecorder::connectCamera);
|
||||
connect_camera_action = camera_menu->addAction(connect_icon, tr("&connect"), this, &PylonRecorder::connectCamera);
|
||||
connect_camera_action->setStatusTip(tr("Connect to to camera and open device"));
|
||||
disconnect_camera_action = camera_menu->addAction(disconnect_icon, tr("&Disconnect"), this, &PylonRecorder::disconnectCamera);
|
||||
disconnect_camera_action = camera_menu->addAction(disconnect_icon, tr("&disconnect"), this, &PylonRecorder::disconnectCamera);
|
||||
disconnect_camera_action->setStatusTip(tr("Disconnect from the camera device"));
|
||||
camera_menu->addSeparator();
|
||||
grab_still_action = camera_menu->addAction(tr("&Grab still"), this, &PylonRecorder::grabStillFromPylon);
|
||||
grab_still_action = camera_menu->addAction(snapshot_icon, tr("&grab still"), this, &PylonRecorder::grabStillFromPylon);
|
||||
grab_still_action->setStatusTip(tr("Grab single image from Pylon camera"));
|
||||
grab_still_action->setShortcut(tr("Ctrl+ "));
|
||||
grab_continuous_action = camera_menu->addAction(tr("&grab continuous"), this, &PylonRecorder::startRecording);
|
||||
grab_continuous_action = camera_menu->addAction(grab_icon, tr("&grab continuous"), this, &PylonRecorder::startRecording);
|
||||
grab_continuous_action->setShortcut(tr("Ctrl+Enter"));
|
||||
grab_stop_action = camera_menu->addAction(tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
|
||||
grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
|
||||
|
||||
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
helpMenu->addAction(tr("&About"), this, &PylonRecorder::about);
|
||||
helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt);
|
||||
|
||||
QToolBar *toolbar = addToolBar("main toolbar");
|
||||
toolbar->addAction(exitAct);
|
||||
toolbar->addSeparator();
|
||||
toolbar->addAction(connect_camera_action);
|
||||
toolbar->addAction(disconnect_camera_action);
|
||||
@ -318,8 +339,8 @@ 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(pylon->isOpen());
|
||||
|
||||
grab_continuous_action->setEnabled(pylon->isOpen() && !grabbing);
|
||||
grab_stop_action->setEnabled(grabbing);
|
||||
}
|
||||
|
||||
void PylonRecorder::scaleImage(double factor) {
|
||||
@ -336,9 +357,11 @@ void PylonRecorder::scaleImage(double factor) {
|
||||
|
||||
void PylonRecorder::quitApplication() {
|
||||
if (pylon->isOpen()) {
|
||||
if (grabbing) {
|
||||
stopRecording();
|
||||
}
|
||||
pylon->closeCamera();
|
||||
}
|
||||
//pylon->terminate();
|
||||
this->close();
|
||||
}
|
||||
|
||||
@ -352,10 +375,8 @@ void PylonRecorder::connectCamera() {
|
||||
pylon->openCamera(message);
|
||||
statusBar()->showMessage(QString::fromStdString(message));
|
||||
updateActions();
|
||||
std::cerr << pylon->maxFrameRate() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void PylonRecorder::disconnectCamera() {
|
||||
pylon->closeCamera();
|
||||
statusBar()->showMessage(tr("Camera closed!"));
|
||||
@ -363,13 +384,53 @@ void PylonRecorder::disconnectCamera() {
|
||||
}
|
||||
|
||||
void PylonRecorder::startRecording() {
|
||||
int framecount = 500;
|
||||
buffer->clear();
|
||||
grabber->start();
|
||||
grabbing = true;
|
||||
updateActions();
|
||||
preassureTimer->start(25);
|
||||
frameTimer->start(100);
|
||||
}
|
||||
|
||||
void PylonRecorder::stopRecording() {
|
||||
grabber->requestStop();
|
||||
grabber->wait(10000);
|
||||
grabbing = false;
|
||||
frameTimer->stop();
|
||||
preassureTimer->stop();
|
||||
preassureBar->reset();
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void PylonRecorder::displaySingleFrame() {
|
||||
MyImage img;
|
||||
bool valid = buffer->readLast(img);
|
||||
if (valid) {
|
||||
QImage qimg(static_cast<uchar *>(img.data()), img.width(), img.height(),
|
||||
QImage::Format::Format_Grayscale8);
|
||||
setImage(qimg);
|
||||
} else {
|
||||
std::cerr << "Error reading last image" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
QColor PylonRecorder::progressColor(int value) {
|
||||
int c, m, k = 0, y = 255;
|
||||
c = 255 - 255 * value/100;
|
||||
if (value < 50) {
|
||||
m = 127 - 127 * value/50;
|
||||
} else {
|
||||
m = 255 * (value-50)/50;
|
||||
}
|
||||
return QColor::fromCmyk(c, m, y, k);
|
||||
}
|
||||
|
||||
void PylonRecorder::displayBufferPreassure() {
|
||||
int value = static_cast<int>(round(buffer->bufferPreassure()));
|
||||
preassureBar->setValue(value);
|
||||
QColor color = progressColor(value);
|
||||
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
|
||||
preassureBar->setPalette(progressPalette);
|
||||
}
|
||||
|
||||
void PylonRecorder::grabStillFromPylon() {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define IMAGEVIEWER_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTimer>
|
||||
#include "pylonwrapper.h"
|
||||
#include "imagebuffer.h"
|
||||
#include "grabber.h"
|
||||
@ -12,6 +13,7 @@
|
||||
|
||||
# if QT_CONFIG(printer)
|
||||
# include <QPrinter>
|
||||
#include <QProgressBar>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@ -51,12 +53,15 @@ private slots:
|
||||
void startRecording();
|
||||
void stopRecording();
|
||||
void quitApplication();
|
||||
void displaySingleFrame();
|
||||
void displayBufferPreassure();
|
||||
|
||||
private:
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void createToolBar();
|
||||
void updateActions();
|
||||
QColor progressColor(int value);
|
||||
|
||||
bool saveFile(const QString &fileName);
|
||||
void setImage(const QImage &newImage);
|
||||
@ -64,13 +69,17 @@ private:
|
||||
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
||||
|
||||
QImage image;
|
||||
QTimer *frameTimer;
|
||||
QTimer *preassureTimer;
|
||||
QLabel *imageLabel;
|
||||
QProgressBar *preassureBar;
|
||||
QScrollArea *scrollArea;
|
||||
double scaleFactor = 1;
|
||||
PylonWrapper *pylon;
|
||||
ImageBuffer *buffer;
|
||||
Grabber *grabber;
|
||||
bool grabbing;
|
||||
QPalette progressPalette;
|
||||
|
||||
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
|
||||
QPrinter printer;
|
||||
|
Loading…
Reference in New Issue
Block a user