This commit is contained in:
Jan Grewe 2021-02-22 16:43:39 +01:00
parent 1b1068fba7
commit d89ae953ec
3 changed files with 43 additions and 3 deletions

3
.gitignore vendored
View File

@ -6,4 +6,5 @@ moc*
.vscode .vscode
.qmake.stash .qmake.stash
qrc_resources.cpp qrc_resources.cpp
recorder recorder
build/

View File

@ -17,6 +17,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QStatusBar> #include <QStatusBar>
#include <QToolBar> #include <QToolBar>
#include <QSettings>
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
#include <cmath> #include <cmath>
@ -125,6 +126,7 @@ PylonRecorder::~PylonRecorder(){
delete writer; delete writer;
} }
bool PylonRecorder::loadFile(const QString &fileName) { bool PylonRecorder::loadFile(const QString &fileName) {
QImageReader reader(fileName); QImageReader reader(fileName);
reader.setAutoTransform(true); reader.setAutoTransform(true);
@ -146,6 +148,7 @@ bool PylonRecorder::loadFile(const QString &fileName) {
return true; return true;
} }
void PylonRecorder::setImage(const QImage &newImage) { void PylonRecorder::setImage(const QImage &newImage) {
image = newImage; image = newImage;
// (image.colorSpace().isValid()) // (image.colorSpace().isValid())
@ -164,6 +167,7 @@ void PylonRecorder::setImage(const QImage &newImage) {
} }
} }
bool PylonRecorder::saveFile(const QString &fileName) { bool PylonRecorder::saveFile(const QString &fileName) {
QImageWriter writer(fileName); QImageWriter writer(fileName);
@ -178,6 +182,7 @@ bool PylonRecorder::saveFile(const QString &fileName) {
return true; return true;
} }
static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMode acceptMode) { static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMode acceptMode) {
static bool firstDialog = true; static bool firstDialog = true;
@ -199,6 +204,7 @@ static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMo
dialog.setDefaultSuffix("jpg"); dialog.setDefaultSuffix("jpg");
} }
void PylonRecorder::open() { void PylonRecorder::open() {
QFileDialog dialog(this, tr("Open File")); QFileDialog dialog(this, tr("Open File"));
initializeImageFileDialog(dialog, QFileDialog::AcceptOpen); initializeImageFileDialog(dialog, QFileDialog::AcceptOpen);
@ -206,6 +212,7 @@ void PylonRecorder::open() {
while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().first())) {} while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().first())) {}
} }
void PylonRecorder::saveAs() { void PylonRecorder::saveAs() {
QFileDialog dialog(this, tr("Save File As")); QFileDialog dialog(this, tr("Save File As"));
initializeImageFileDialog(dialog, QFileDialog::AcceptSave); initializeImageFileDialog(dialog, QFileDialog::AcceptSave);
@ -213,6 +220,7 @@ void PylonRecorder::saveAs() {
while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().first())) {} while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().first())) {}
} }
void PylonRecorder::print() { void PylonRecorder::print() {
Q_ASSERT(imageLabel->pixmap()); Q_ASSERT(imageLabel->pixmap());
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog)
@ -231,12 +239,14 @@ void PylonRecorder::print() {
#endif #endif
} }
void PylonRecorder::copy() { void PylonRecorder::copy() {
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
QGuiApplication::clipboard()->setImage(image); QGuiApplication::clipboard()->setImage(image);
#endif // !QT_NO_CLIPBOARD #endif // !QT_NO_CLIPBOARD
} }
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
static QImage clipboardImage() { static QImage clipboardImage() {
if (const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData()) { if (const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData()) {
@ -250,6 +260,7 @@ static QImage clipboardImage() {
} }
#endif // !QT_NO_CLIPBOARD #endif // !QT_NO_CLIPBOARD
void PylonRecorder::paste() { void PylonRecorder::paste() {
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
const QImage newImage = clipboardImage(); const QImage newImage = clipboardImage();
@ -265,20 +276,24 @@ void PylonRecorder::paste() {
#endif // !QT_NO_CLIPBOARD #endif // !QT_NO_CLIPBOARD
} }
void PylonRecorder::zoomIn() { void PylonRecorder::zoomIn() {
scaleImage(1.25); scaleImage(1.25);
} }
void PylonRecorder::zoomOut() void PylonRecorder::zoomOut()
{ {
scaleImage(0.8); scaleImage(0.8);
} }
void PylonRecorder::normalSize() { void PylonRecorder::normalSize() {
imageLabel->adjustSize(); imageLabel->adjustSize();
scaleFactor = 1.0; scaleFactor = 1.0;
} }
void PylonRecorder::fitToWindow() { void PylonRecorder::fitToWindow() {
bool fitToWindow = fitToWindowAct->isChecked(); bool fitToWindow = fitToWindowAct->isChecked();
scrollArea->setWidgetResizable(fitToWindow); scrollArea->setWidgetResizable(fitToWindow);
@ -287,6 +302,7 @@ void PylonRecorder::fitToWindow() {
updateActions(); updateActions();
} }
void PylonRecorder::about() { void PylonRecorder::about() {
QMessageBox::about(this, tr("About Pylon Recorder"), QMessageBox::about(this, tr("About Pylon Recorder"),
tr("<p><b>Pylon Recorder</b><br> Simple recorder for video grabbing from pylon USB3 monochrome camera." tr("<p><b>Pylon Recorder</b><br> Simple recorder for video grabbing from pylon USB3 monochrome camera."
@ -298,6 +314,7 @@ void PylonRecorder::about() {
"<p>by Jan Grewe, <a href='http://www.neuroetho.uni-tuebingen.de'>Neuroethology Lab</a>, University of Tuebingen.</p>")); "<p>by Jan Grewe, <a href='http://www.neuroetho.uni-tuebingen.de'>Neuroethology Lab</a>, University of Tuebingen.</p>"));
} }
void PylonRecorder::createActions() { void PylonRecorder::createActions() {
const QIcon connect_icon(":/images/connect.png"); const QIcon connect_icon(":/images/connect.png");
const QIcon disconnect_icon(":/images/disconnect.png"); const QIcon disconnect_icon(":/images/disconnect.png");
@ -367,6 +384,9 @@ void PylonRecorder::createActions() {
grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording); grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter")); grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter"));
QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings"));
settingsMenu->addAction(tr("Storage location"), this, &PylonRecorder::selectStorageLocation);
QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
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);
@ -430,6 +450,7 @@ void PylonRecorder::createActions() {
toolbar->addWidget(dryRunCheckBox); toolbar->addWidget(dryRunCheckBox);
} }
void PylonRecorder::updateActions() { void PylonRecorder::updateActions() {
saveAsAct->setEnabled(!image.isNull()); saveAsAct->setEnabled(!image.isNull());
copyAct->setEnabled(!image.isNull()); copyAct->setEnabled(!image.isNull());
@ -443,6 +464,7 @@ void PylonRecorder::updateActions() {
grab_stop_action->setEnabled(grabbing); grab_stop_action->setEnabled(grabbing);
} }
void PylonRecorder::scaleImage(double factor) { void PylonRecorder::scaleImage(double factor) {
Q_ASSERT(imageLabel->pixmap()); Q_ASSERT(imageLabel->pixmap());
scaleFactor *= factor; scaleFactor *= factor;
@ -455,10 +477,12 @@ void PylonRecorder::scaleImage(double factor) {
zoomOutAct->setEnabled(scaleFactor > 0.333); zoomOutAct->setEnabled(scaleFactor > 0.333);
} }
void PylonRecorder::applyScaling(){ void PylonRecorder::applyScaling(){
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size()); imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
} }
void PylonRecorder::quitApplication() { void PylonRecorder::quitApplication() {
if (pylon->isOpen()) { if (pylon->isOpen()) {
if (grabbing) { if (grabbing) {
@ -469,11 +493,13 @@ void PylonRecorder::quitApplication() {
this->close(); this->close();
} }
void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) { void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) {
scrollBar->setValue(int(factor * scrollBar->value() scrollBar->setValue(int(factor * scrollBar->value()
+ ((factor - 1) * scrollBar->pageStep()/2))); + ((factor - 1) * scrollBar->pageStep()/2)));
} }
void PylonRecorder::connectCamera() { void PylonRecorder::connectCamera() {
std::string message; std::string message;
bool success = pylon->openCamera(message); bool success = pylon->openCamera(message);
@ -491,6 +517,7 @@ void PylonRecorder::connectCamera() {
updateActions(); updateActions();
} }
void PylonRecorder::disconnectCamera() { void PylonRecorder::disconnectCamera() {
pylon->closeCamera(); pylon->closeCamera();
statusBar()->showMessage(tr("Camera closed!")); statusBar()->showMessage(tr("Camera closed!"));
@ -499,6 +526,7 @@ void PylonRecorder::disconnectCamera() {
updateActions(); updateActions();
} }
void PylonRecorder::startRecording() { void PylonRecorder::startRecording() {
std::string filename = createFilename(); std::string filename = createFilename();
fileLabel->setText(QString::fromStdString(filename)); fileLabel->setText(QString::fromStdString(filename));
@ -541,6 +569,7 @@ void PylonRecorder::startRecording() {
updateActions(); updateActions();
} }
void PylonRecorder::stopRecording() { void PylonRecorder::stopRecording() {
if (!stopRequest) { if (!stopRequest) {
frameTimer->stop(); frameTimer->stop();
@ -556,6 +585,7 @@ void PylonRecorder::stopRecording() {
} }
} }
void PylonRecorder::writerDone() { void PylonRecorder::writerDone() {
preassureTimer->stop(); preassureTimer->stop();
preassureBar->reset(); preassureBar->reset();
@ -569,12 +599,14 @@ void PylonRecorder::writerDone() {
updateActions(); updateActions();
} }
void PylonRecorder::displayActivity() { void PylonRecorder::displayActivity() {
grabbingLabel->setStyleSheet((labelSwitch && grabbing) ? activeLabelStyleHigh : activeLabelStyleLow); grabbingLabel->setStyleSheet((labelSwitch && grabbing) ? activeLabelStyleHigh : activeLabelStyleLow);
writingLabel->setStyleSheet((labelSwitch && writing) ? activeLabelStyleHigh : activeLabelStyleLow); writingLabel->setStyleSheet((labelSwitch && writing) ? activeLabelStyleHigh : activeLabelStyleLow);
labelSwitch = !labelSwitch; labelSwitch = !labelSwitch;
} }
void PylonRecorder::displaySingleFrame() { void PylonRecorder::displaySingleFrame() {
MyImage img; MyImage img;
bool valid = buffer->readLast(img); bool valid = buffer->readLast(img);
@ -587,6 +619,7 @@ void PylonRecorder::displaySingleFrame() {
}*/ }*/
} }
QColor PylonRecorder::progressColor(int value) { QColor PylonRecorder::progressColor(int value) {
int c, m, k = 0, y = 255; int c, m, k = 0, y = 255;
c = 255 - 255 * value/100; c = 255 - 255 * value/100;
@ -598,6 +631,7 @@ QColor PylonRecorder::progressColor(int value) {
return QColor::fromCmyk(c, m, y, k); return QColor::fromCmyk(c, m, y, k);
} }
std::string PylonRecorder::createFilename() { std::string PylonRecorder::createFilename() {
QDateTime dt(QDateTime::currentDateTimeUtc()); QDateTime dt(QDateTime::currentDateTimeUtc());
QDate date = dt.date(); QDate date = dt.date();
@ -612,6 +646,7 @@ std::string PylonRecorder::createFilename() {
return fname; return fname;
} }
void PylonRecorder::displayBufferPreassure() { void PylonRecorder::displayBufferPreassure() {
int value = static_cast<int>(round(buffer->bufferPreassure())); int value = static_cast<int>(round(buffer->bufferPreassure()));
preassureBar->setValue(value); preassureBar->setValue(value);
@ -623,6 +658,7 @@ void PylonRecorder::displayBufferPreassure() {
loadBar->setValue(load); loadBar->setValue(load);
} }
void PylonRecorder::grabStillFromPylon() { void PylonRecorder::grabStillFromPylon() {
if (pylon->isOpen()) { if (pylon->isOpen()) {
MyImage img; MyImage img;
@ -636,3 +672,7 @@ void PylonRecorder::grabStillFromPylon() {
statusBar()->showMessage(tr("Camera is not open! Connect to camera first!")); statusBar()->showMessage(tr("Camera is not open! Connect to camera first!"));
} }
} }
void PylonRecorder::selectStorageLocation() {
std::cerr << "Select folder!!! " << std::endl;
}

View File

@ -61,11 +61,10 @@ private slots:
void displayBufferPreassure(); void displayBufferPreassure();
void displayActivity(); void displayActivity();
void writerDone(); void writerDone();
void selectStorageLocation();
private: private:
void createActions(); void createActions();
void createMenus();
void createToolBar();
void updateActions(); void updateActions();
QColor progressColor(int value); QColor progressColor(int value);
std::string createFilename(); std::string createFilename();