From 4011a17f13445d18e97ea3c61ae4075698f755eb Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 16 Mar 2020 14:45:29 +0100 Subject: [PATCH] nicer font sizes, message box for error messaging! --- pylonrecorder.cpp | 90 +++++++++++++++++++++++++++++++++-------------- pylonrecorder.h | 11 +++--- 2 files changed, 70 insertions(+), 31 deletions(-) diff --git a/pylonrecorder.cpp b/pylonrecorder.cpp index f8904f4..b9715c0 100644 --- a/pylonrecorder.cpp +++ b/pylonrecorder.cpp @@ -25,6 +25,7 @@ # include # if QT_CONFIG(printdialog) +#include # include # endif #endif @@ -60,34 +61,51 @@ PylonRecorder::PylonRecorder(QWidget *parent) preassureBar = new QProgressBar(this); preassureBar->setRange(0, 100); preassureBar->setTextVisible(true); + preassureBar->setFixedSize(200, 25); QColor color = progressColor(0); QPalette progressPalette = preassureBar->palette(); progressPalette.setBrush(QPalette::Highlight, QBrush(color)); preassureBar->setPalette(progressPalette); QLabel *preassureLabel = new QLabel("Buffer preassure:", this); - + preassureLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;font-weight: Bold}"); loadBar = new QProgressBar(this); - loadBar->setRange(0, 1000); + loadBar->setRange(0, defaultBufferSize); + loadBar->setFixedSize(200, 25); QLabel *loadLabel = new QLabel("Load:", this); + loadLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;font-weight: Bold}"); writingLabel = new QLabel("writing"); writingLabel->setEnabled(false); + writingLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}"); grabbingLabel = new QLabel("grabbing"); - //grabbingLabel->setStyleSheet("QLabel { color : gray; }"); grabbingLabel->setEnabled(false); + grabbingLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}"); labelSwitch = false; cameraConnectedLabel = new QLabel("not connected"); cameraConnectedLabel->setStyleSheet("QLabel { color : red; }"); + cameraConnectedLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}"); + + fileLabel = new QLabel(); + fileLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}"); + + QLabel *camHeader = new QLabel("Camera:"); + camHeader->setStyleSheet("QLabel{font-size: 11px;font-family: Arial; font-weight: Bold}"); + QLabel *statusHeader = new QLabel("Status:"); + statusHeader->setStyleSheet("QLabel{font-size: 11px;font-family: Arial; font-weight: Bold}"); + QLabel *fileHeader = new QLabel("Output file:"); + fileHeader->setStyleSheet("QLabel{font-size: 11px;font-family: Arial; font-weight: Bold}"); - statusBar()->addWidget(new QLabel("Camera:")); + statusBar()->addWidget(camHeader); statusBar()->addWidget(cameraConnectedLabel); statusBar()->addWidget(preassureLabel); statusBar()->addWidget(preassureBar); statusBar()->addWidget(loadLabel); statusBar()->addWidget(loadBar); + statusBar()->addWidget(statusHeader); statusBar()->addWidget(grabbingLabel); statusBar()->addWidget(writingLabel); - + statusBar()->addWidget(fileHeader); + statusBar()->addWidget(fileLabel); resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); } @@ -269,19 +287,14 @@ void PylonRecorder::fitToWindow() { } void PylonRecorder::about() { - QMessageBox::about(this, tr("About Image Viewer"), - tr("

The Image Viewer example shows how to combine QLabel " - "and QScrollArea to display an image. QLabel is typically used " - "for displaying a text, but it can also display an image. " - "QScrollArea provides a scrolling view around another widget. " - "If the child widget exceeds the size of the frame, QScrollArea " - "automatically provides scroll bars.

The example " - "demonstrates how QLabel's ability to scale its contents " - "(QLabel::scaledContents), and QScrollArea's ability to " - "automatically resize its contents " - "(QScrollArea::widgetResizable), can be used to implement " - "zooming and scaling features.

In addition the example " - "shows how to use QPainter to print an image.

")); + QMessageBox::about(this, tr("About Pylon Recorder"), + tr("

Pylon Recorder
Simple recorder for video grabbing from pylon USB3 monochrome camera." + "Usage: In order to grab image, a camera device needs to be opened, press the connect button to do so. Push the reord button to record conituously.

" + "

videos are stored in the same folder as the tool is. Videos are compressed to mp4." + " As the buffer preassure reaches 100% frames will be lost! You may want to increase the buffer size" + " or reduce the framerate.

In order to run you need to install the pylon libraries" + " and the mp4 video codec avalable for download at Basler website

" + "

by Jan Grewe, Neuroethology Lab, University of Tuebingen.

")); } void PylonRecorder::createActions() { @@ -351,17 +364,16 @@ void PylonRecorder::createActions() { 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(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording); + grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter")); QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); 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->setFixedSize(120, 25); 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);}"); @@ -370,7 +382,7 @@ void PylonRecorder::createActions() { buffersizeSpinner->setRange(100, 5000); buffersizeSpinner->setSingleStep(25); buffersizeSpinner->setValue(defaultBufferSize); - buffersizeSpinner->setFixedSize(120, 30); + buffersizeSpinner->setFixedSize(120, 25); 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"); @@ -385,6 +397,7 @@ void PylonRecorder::createActions() { toolbar->addSeparator(); toolbar->addWidget(new QLabel("frame rate:")); toolbar->addWidget(framerateSpinner); + toolbar->addSeparator(); toolbar->addWidget(new QLabel("buffer size:")); toolbar->addWidget(buffersizeSpinner); } @@ -438,7 +451,13 @@ void PylonRecorder::connectCamera() { bool success = pylon->openCamera(message); if (success) { cameraConnectedLabel->setText("connected"); - cameraConnectedLabel->setStyleSheet("QLabel { color : green; }"); + cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}"); + } + else { + QMessageBox msgBox; + QString msg = "

Could not open camera device!

" + QString::fromStdString(message) + "

"; + msgBox.setText(msg); + msgBox.exec(); } statusBar()->showMessage(QString::fromStdString(message)); updateActions(); @@ -448,22 +467,27 @@ void PylonRecorder::disconnectCamera() { pylon->closeCamera(); statusBar()->showMessage(tr("Camera closed!")); cameraConnectedLabel->setText("not connected"); - cameraConnectedLabel->setStyleSheet("QLabel { color : red; }"); + cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: red;}"); updateActions(); } void PylonRecorder::startRecording() { + std::string filename = createFilename(); + std::cerr << filename << std::endl; + fileLabel->setText(QString::fromStdString(filename)); VideoSpecs specs; specs.fps = 25; - specs.filename = "Test.mp4"; + specs.filename = filename; ImageSettings settings = pylon->getImageSettings(); specs.width = static_cast(settings.width); specs.height= static_cast(settings.height); specs.pixelType = settings.pixelType; specs.orientation = settings.orientation; specs.quality = 95; - if (buffersizeSpinner->value() != static_cast(buffer->capacity())) + if (buffersizeSpinner->value() != static_cast(buffer->capacity())) { buffer->resize(static_cast(buffersizeSpinner->value())); + loadBar->setRange(0, buffersizeSpinner->value()); + } if (framerateSpinner->value() != grabber->currentFramerate()) grabber->setFrameRate(framerateSpinner->value()); writer->setVideoSpecs(specs); @@ -533,6 +557,20 @@ QColor PylonRecorder::progressColor(int value) { return QColor::fromCmyk(c, m, y, k); } +std::string PylonRecorder::createFilename() { + QDateTime dt(QDateTime::currentDateTimeUtc()); + QDate date = dt.date(); + std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString(); + std::string extension = ".mp4"; + QString idx = QString::number(movieCount); + std::string fname = base + idx.toStdString() + extension; + while (QFile::exists(QString::fromStdString(fname))) { + movieCount++; + fname = base + QString::number(movieCount).toStdString() + extension; + } + return fname; +} + void PylonRecorder::displayBufferPreassure() { int value = static_cast(round(buffer->bufferPreassure())); preassureBar->setValue(value); diff --git a/pylonrecorder.h b/pylonrecorder.h index 5e1b56a..d8109e6 100644 --- a/pylonrecorder.h +++ b/pylonrecorder.h @@ -67,6 +67,7 @@ private: void createToolBar(); void updateActions(); QColor progressColor(int value); + std::string createFilename(); bool saveFile(const QString &fileName); void setImage(const QImage &newImage); @@ -74,10 +75,10 @@ private: void applyScaling(); void adjustScrollBar(QScrollBar *scrollBar, double factor); - int defaultBufferSize = 1000, defaultFrameRate = 50; + int defaultBufferSize = 1000, defaultFrameRate = 30, movieCount = 0; QImage image; QTimer *frameTimer, *preassureTimer, *labelTimer; - QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel; + QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel; QProgressBar *preassureBar; QProgressBar *loadBar; QScrollArea *scrollArea; @@ -88,9 +89,9 @@ private: Writer *writer; bool grabbing, stopRequest, writing, labelSwitch; QPalette progressPalette; - QString activeLabelStyleHigh = "QLabel { color : red; }"; - QString activeLabelStyleLow = "QLabel { color : cmyk(0, 255, 255, 0, 50); }"; - QString inactiveLabelStyle = ("QLabel { color :gray; }"); + QString activeLabelStyleHigh = "QLabel { font-size: 10px;font-family: Arial; color : red; }"; + QString activeLabelStyleLow = "QLabel { font-size: 10px;font-family: Arial; color : cmyk(0, 255, 255, 0, 50); }"; + QString inactiveLabelStyle = ("QLabel { font-size: 10px;font-family: Arial; color :gray; }"); QSpinBox *framerateSpinner, *buffersizeSpinner;