|
|
|
|
@@ -17,9 +17,11 @@
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QErrorMessage>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include "camconfig.h"
|
|
|
|
|
|
|
|
|
|
#if defined(QT_PRINTSUPPORT_LIB)
|
|
|
|
|
# include <QtPrintSupport/qtprintsupportglobal.h>
|
|
|
|
|
@@ -42,23 +44,33 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|
|
|
|
scrollArea->setWidget(imageLabel);
|
|
|
|
|
scrollArea->setVisible(false);
|
|
|
|
|
setCentralWidget(scrollArea);
|
|
|
|
|
std::cerr << "PylonRecorder::constructor" << std::endl;
|
|
|
|
|
// Pylon::DeviceInfoList_t deviceList = detectCameras();
|
|
|
|
|
// for (auto dev : deviceList) {
|
|
|
|
|
// std::cout << dev.GetFullName() << " " << dev.GetFriendlyName() << std::endl;
|
|
|
|
|
// }
|
|
|
|
|
// std::cout << "peng\n";
|
|
|
|
|
// std::cout << deviceList.size() << std::endl;
|
|
|
|
|
// std::cout << "peng\n";
|
|
|
|
|
|
|
|
|
|
pylon = new PylonWrapper();
|
|
|
|
|
buffer = new ImageBuffer(defaultBufferSize);
|
|
|
|
|
grabber = new Grabber(pylon, buffer, defaultFrameRate);
|
|
|
|
|
writer = new Writer(buffer);
|
|
|
|
|
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
|
|
|
|
|
|
|
|
|
createActions();
|
|
|
|
|
updateActions();
|
|
|
|
|
|
|
|
|
|
// if (deviceList.size() == 0) {
|
|
|
|
|
// QErrorMessage message(this);
|
|
|
|
|
// message.showMessage("No camera detected!");
|
|
|
|
|
// } else {
|
|
|
|
|
// std::cout << "peng\n";
|
|
|
|
|
// buffer = new ImageBuffer(defaultBufferSize);
|
|
|
|
|
// grabber = new Grabber(pyloncam, buffer, defaultFrameRate);
|
|
|
|
|
// writer = new Writer(buffer);
|
|
|
|
|
// connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
|
|
|
|
// }
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 1" << std::endl;
|
|
|
|
|
frameTimer = new QTimer(this);
|
|
|
|
|
connect(frameTimer, &QTimer::timeout, this, &PylonRecorder::displaySingleFrame);
|
|
|
|
|
preassureTimer = new QTimer(this);
|
|
|
|
|
connect(preassureTimer, &QTimer::timeout, this, &PylonRecorder::displayBufferPreassure);
|
|
|
|
|
labelTimer = new QTimer(this);
|
|
|
|
|
connect(labelTimer, &QTimer::timeout, this, &PylonRecorder::displayActivity);
|
|
|
|
|
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 2" << std::endl;
|
|
|
|
|
preassureBar = new QProgressBar(this);
|
|
|
|
|
preassureBar->setRange(0, 100);
|
|
|
|
|
preassureBar->setTextVisible(true);
|
|
|
|
|
@@ -74,7 +86,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|
|
|
|
loadBar->setFixedSize(200, 25);
|
|
|
|
|
QLabel *loadLabel = new QLabel("Load:", this);
|
|
|
|
|
loadLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;font-weight: Bold}");
|
|
|
|
|
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 3" << std::endl;
|
|
|
|
|
writingLabel = new QLabel("writing");
|
|
|
|
|
writingLabel->setEnabled(false);
|
|
|
|
|
writingLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
|
|
|
|
@@ -85,7 +97,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|
|
|
|
cameraConnectedLabel = new QLabel("not connected");
|
|
|
|
|
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }");
|
|
|
|
|
cameraConnectedLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
|
|
|
|
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 4" << std::endl;
|
|
|
|
|
fileLabel = new QLabel();
|
|
|
|
|
fileLabel->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial;}");
|
|
|
|
|
|
|
|
|
|
@@ -95,7 +107,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|
|
|
|
statusHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
|
|
|
|
|
QLabel *fileHeader = new QLabel("Output file:");
|
|
|
|
|
fileHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
|
|
|
|
|
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 5" << std::endl;
|
|
|
|
|
statusBar()->addWidget(camHeader);
|
|
|
|
|
statusBar()->addWidget(cameraConnectedLabel);
|
|
|
|
|
statusBar()->addWidget(preassureLabel);
|
|
|
|
|
@@ -108,9 +120,45 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
|
|
|
|
statusBar()->addWidget(fileHeader);
|
|
|
|
|
statusBar()->addWidget(fileLabel);
|
|
|
|
|
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 6" << std::endl;
|
|
|
|
|
detectCameras();
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 7" << std::endl;
|
|
|
|
|
createActions();
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 8 " << std::endl;
|
|
|
|
|
updateActions();
|
|
|
|
|
std::cerr << "PylonRecorder::constructor 9" << std::endl;
|
|
|
|
|
applySettings();
|
|
|
|
|
std::cerr << "PylonRecorder::constructor done" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::setupCameras(){
|
|
|
|
|
for (auto dev : deviceList) {
|
|
|
|
|
std::cout << dev.GetFullName() << " " << dev.GetFriendlyName() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "peng\n";
|
|
|
|
|
std::cout << deviceList.size() << std::endl;
|
|
|
|
|
std::cout << "peng\n";
|
|
|
|
|
|
|
|
|
|
if (deviceList.size() == 0) {
|
|
|
|
|
std::cout << "device list is empty!" << std::endl;
|
|
|
|
|
QErrorMessage message(this);
|
|
|
|
|
message.showMessage("No camera detected!");
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "peng\n";
|
|
|
|
|
// std::string cname = (std::string)deviceList[0].GetFullName();
|
|
|
|
|
// pyloncam = new PylonWrapper(cname);
|
|
|
|
|
buffer = new ImageBuffer(defaultBufferSize);
|
|
|
|
|
grabber = new Grabber(pyloncam, buffer, defaultFrameRate);
|
|
|
|
|
writer = new Writer(buffer);
|
|
|
|
|
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::detectCameras() {
|
|
|
|
|
Pylon::PylonAutoInitTerm autoInitTerm;
|
|
|
|
|
Pylon::CTlFactory& TlFactory = Pylon::CTlFactory::GetInstance();
|
|
|
|
|
TlFactory.EnumerateDevices(deviceList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PylonRecorder::~PylonRecorder(){
|
|
|
|
|
if (grabber->isRunning()) {
|
|
|
|
|
@@ -122,8 +170,9 @@ PylonRecorder::~PylonRecorder(){
|
|
|
|
|
writer->wait(1000);
|
|
|
|
|
}
|
|
|
|
|
storeSettings();
|
|
|
|
|
|
|
|
|
|
delete pylon;
|
|
|
|
|
std::cerr << "recorder::destructor" << std::endl;
|
|
|
|
|
delete pyloncam;
|
|
|
|
|
std::cerr << "recorder::destructor" << std::endl;
|
|
|
|
|
delete buffer;
|
|
|
|
|
delete grabber;
|
|
|
|
|
delete writer;
|
|
|
|
|
@@ -504,10 +553,10 @@ void PylonRecorder::updateActions() {
|
|
|
|
|
zoomInAct->setEnabled(!fitToWindowAct->isChecked());
|
|
|
|
|
zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
|
|
|
|
|
normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
|
|
|
|
|
disconnect_camera_action->setEnabled(pylon->isOpen());
|
|
|
|
|
connect_camera_action->setEnabled(!pylon->isOpen());
|
|
|
|
|
grab_still_action->setEnabled(pylon->isOpen());
|
|
|
|
|
grab_continuous_action->setEnabled(pylon->isOpen() && !grabbing);
|
|
|
|
|
disconnect_camera_action->setEnabled(deviceList.size() > 0);
|
|
|
|
|
connect_camera_action->setEnabled(true);
|
|
|
|
|
grab_still_action->setEnabled(deviceList.size() > 0);
|
|
|
|
|
grab_continuous_action->setEnabled(deviceList.size() > 0 && pyloncam->isOpen() && !grabbing);
|
|
|
|
|
grab_stop_action->setEnabled(grabbing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -533,12 +582,14 @@ void PylonRecorder::applyScaling(){
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::quitApplication() {
|
|
|
|
|
std::cerr << "Quit Application!" << std::endl;
|
|
|
|
|
if (pylon->isOpen()) {
|
|
|
|
|
if (pyloncam->isOpen()) {
|
|
|
|
|
std::cerr << "Cam is open!" << std::endl;
|
|
|
|
|
|
|
|
|
|
if (grabbing) {
|
|
|
|
|
stopRecording();
|
|
|
|
|
buffer->clear();
|
|
|
|
|
}
|
|
|
|
|
pylon->closeCamera();
|
|
|
|
|
pyloncam->closeCamera();
|
|
|
|
|
}
|
|
|
|
|
this->close();
|
|
|
|
|
}
|
|
|
|
|
@@ -549,38 +600,57 @@ void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) {
|
|
|
|
|
+ ((factor - 1) * scrollBar->pageStep()/2)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::cameraConfiguration(){
|
|
|
|
|
CamConfigurator d(this);
|
|
|
|
|
// QObject::connect(&d, SIGNAL(recent_file_changed(QStringList)), this, SLOT(recent_file_update(QStringList)));
|
|
|
|
|
// QObject::connect(&d, SIGNAL(column_visibility_changed(QString, QString,bool)), this, SLOT(visible_columns_update(QString, QString,bool)));
|
|
|
|
|
d.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::connectCamera() {
|
|
|
|
|
std::string message;
|
|
|
|
|
bool success = pylon->openCamera(message);
|
|
|
|
|
if (success) {
|
|
|
|
|
cameraConnectedLabel->setText("connected");
|
|
|
|
|
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}");
|
|
|
|
|
if (deviceList.size() == 0) {
|
|
|
|
|
detectCameras();
|
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
QString msg = "<p><b>No camera device found!</b></p><br><p>Connect camera and try again!</p>";
|
|
|
|
|
msgBox.setText(msg);
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
} else if (deviceList.size() == 1) {
|
|
|
|
|
std::string cname = (std::string)deviceList[0].GetFullName();
|
|
|
|
|
pyloncam = new PylonWrapper(cname);
|
|
|
|
|
std::string message;
|
|
|
|
|
bool success = pyloncam->openCamera(message);
|
|
|
|
|
if (success) {
|
|
|
|
|
cameraConnectedLabel->setText("connected");
|
|
|
|
|
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}");
|
|
|
|
|
} else {
|
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
QString msg = "<p><b>Could not open camera device!</b><p><p>" + QString::fromStdString(message) + "</p>";
|
|
|
|
|
msgBox.setText(msg);
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
}
|
|
|
|
|
statusBar()->showMessage(QString::fromStdString(message));
|
|
|
|
|
updateActions();
|
|
|
|
|
} else { // more than 1 camera
|
|
|
|
|
cameraConfiguration();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
QString msg = "<p><b>Could not open camera device!</b><p><p>" + QString::fromStdString(message) + "</p>";
|
|
|
|
|
msgBox.setText(msg);
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
}
|
|
|
|
|
statusBar()->showMessage(QString::fromStdString(message));
|
|
|
|
|
updateActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::disconnectCamera() {
|
|
|
|
|
pylon->closeCamera();
|
|
|
|
|
statusBar()->showMessage(tr("Camera closed!"));
|
|
|
|
|
cameraConnectedLabel->setText("not connected");
|
|
|
|
|
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: red;}");
|
|
|
|
|
updateActions();
|
|
|
|
|
if (pyloncam->isOpen()) {
|
|
|
|
|
pyloncam->closeCamera();
|
|
|
|
|
statusBar()->showMessage(tr("Camera closed!"));
|
|
|
|
|
cameraConnectedLabel->setText("not connected");
|
|
|
|
|
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: red;}");
|
|
|
|
|
updateActions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::startRecording() {
|
|
|
|
|
std::string filename = createFilename();
|
|
|
|
|
fileLabel->setText(QString::fromStdString(filename));
|
|
|
|
|
ImageSettings settings = pylon->getImageSettings();
|
|
|
|
|
ImageSettings settings = pyloncam->getImageSettings();
|
|
|
|
|
|
|
|
|
|
VideoSpecs specs;
|
|
|
|
|
specs.fps = framerateSpinner->value();
|
|
|
|
|
@@ -713,9 +783,9 @@ void PylonRecorder::displayBufferPreassure() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PylonRecorder::grabStillFromPylon() {
|
|
|
|
|
if (pylon->isOpen()) {
|
|
|
|
|
if (pyloncam->isOpen()) {
|
|
|
|
|
MyImage img;
|
|
|
|
|
bool valid = pylon->grabFrame(img);
|
|
|
|
|
bool valid = pyloncam->grabFrame(img);
|
|
|
|
|
if (valid) {
|
|
|
|
|
QImage qimg(static_cast<uchar *>(img.data()), img.width(), img.height(),
|
|
|
|
|
QImage::Format::Format_Grayscale8);
|
|
|
|
|
|