[recorder] wait for writer to finish before deleting buffer ...

more messaging, use the size-aware Image constructor
This commit is contained in:
Jan Grewe 2025-03-12 10:00:35 +01:00
parent 6ec776cd4e
commit 12c2f6292f

View File

@ -87,6 +87,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
statusHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}"); statusHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
QLabel *fileHeader = new QLabel("Output file:"); QLabel *fileHeader = new QLabel("Output file:");
fileHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}"); fileHeader->setStyleSheet("QLabel{font-size: 11pt;font-family: Arial; font-weight: Bold}");
statusBar()->addWidget(camHeader); statusBar()->addWidget(camHeader);
statusBar()->addWidget(cameraConnectedLabel); statusBar()->addWidget(cameraConnectedLabel);
statusBar()->addWidget(pressureLabel); statusBar()->addWidget(pressureLabel);
@ -98,6 +99,7 @@ PylonRecorder::PylonRecorder(QWidget *parent)
statusBar()->addWidget(writingLabel); statusBar()->addWidget(writingLabel);
statusBar()->addWidget(fileHeader); statusBar()->addWidget(fileHeader);
statusBar()->addWidget(fileLabel); statusBar()->addWidget(fileLabel);
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
detectCameras(); detectCameras();
createActions(); createActions();
@ -206,6 +208,7 @@ bool PylonRecorder::loadFile(const QString &fileName) {
void PylonRecorder::setImage(const QImage &newImage) { void PylonRecorder::setImage(const QImage &newImage) {
qDebug() << "Setting image";
//FIXME figure out how to display both images. extract to extra class... //FIXME figure out how to display both images. extract to extra class...
image = newImage; image = newImage;
// (image.colorSpace().isValid()) // (image.colorSpace().isValid())
@ -223,6 +226,7 @@ void PylonRecorder::setImage(const QImage &newImage) {
applyScaling(); applyScaling();
} }
this->update(); this->update();
qDebug() << "Setting image done";
} }
@ -608,6 +612,7 @@ void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) {
void PylonRecorder::cameraConfiguration(){ void PylonRecorder::cameraConfiguration(){
qDebug() << "Configuring camera(s)";
cameraConfigDialog = new CamConfigurator(deviceList, this); cameraConfigDialog = new CamConfigurator(deviceList, this);
connect(cameraConfigDialog, SIGNAL(accepted()), SLOT(cameraConfigurationAccepted())); connect(cameraConfigDialog, SIGNAL(accepted()), SLOT(cameraConfigurationAccepted()));
connect(cameraConfigDialog, SIGNAL(rejected()), SLOT(cameraConfigurationAborted())); connect(cameraConfigDialog, SIGNAL(rejected()), SLOT(cameraConfigurationAborted()));
@ -617,7 +622,7 @@ void PylonRecorder::cameraConfiguration(){
void PylonRecorder::cameraConfigurationAccepted() { void PylonRecorder::cameraConfigurationAccepted() {
qDebug() << "Cameras setting " << ((cameraConfigDialog->result()) ? "Accepted" : "Discarded"); qDebug() << "Camera configuration " << ((cameraConfigDialog->result()) ? "Accepted" : "Discarded");
this->layout = cameraConfigDialog->layout(); this->layout = cameraConfigDialog->layout();
camsconfigured = true; camsconfigured = true;
delete cameraConfigDialog; delete cameraConfigDialog;
@ -627,12 +632,13 @@ void PylonRecorder::cameraConfigurationAccepted() {
void PylonRecorder::cameraConfigurationAborted() { void PylonRecorder::cameraConfigurationAborted() {
qDebug() << "Camera configuration aborted!"; qDebug() << "Camera configuration aborted!";
camsconfigured = false; camsconfigured = false;
delete cameraConfigDialog;
} }
void PylonRecorder::connectCamera() { void PylonRecorder::connectCamera() {
this->layout = CameraLayout();
qDebug() << "connecting camera(s)"; qDebug() << "connecting camera(s)";
this->layout = CameraLayout();
if (deviceList.size() == 0) { if (deviceList.size() == 0) {
detectCameras(); detectCameras();
QMessageBox msgBox; QMessageBox msgBox;
@ -647,6 +653,8 @@ void PylonRecorder::connectCamera() {
qDebug() << "cameras have not been properly configured!"; qDebug() << "cameras have not been properly configured!";
return; return;
} }
//Single Camera mode
if (layout.mode == CameraMode::single && layout.devices.size() == 1) { if (layout.mode == CameraMode::single && layout.devices.size() == 1) {
qDebug() << "single camera mode"; qDebug() << "single camera mode";
std::string cname = layout.devices[0]; std::string cname = layout.devices[0];
@ -668,12 +676,15 @@ void PylonRecorder::connectCamera() {
statusBar()->showMessage(QString::fromStdString(message)); statusBar()->showMessage(QString::fromStdString(message));
updateActions(); updateActions();
} }
// Dual Camera mode
if (layout.mode == CameraMode::dual && layout.devices.size() == 2) { if (layout.mode == CameraMode::dual && layout.devices.size() == 2) {
qDebug() << "dual camera mode"; qDebug() << "dual camera mode";
std::string message; std::string message;
dualcam = new DualcamWrapper(layout); dualcam = new DualcamWrapper(layout);
bool success = dualcam->openCameras(message); bool success = dualcam->openCameras(message);
if (success) { if (success) {
qDebug()::cerr << "dual camera connected\n";
cameraConnectedLabel->setText("connected"); cameraConnectedLabel->setText("connected");
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}"); cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}");
cameraOpened = true; cameraOpened = true;
@ -843,10 +854,10 @@ void PylonRecorder::startDualcamRecording() {
connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone())); connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone()));
writer->setVideoSpecs(specs); writer->setVideoSpecs(specs);
qDebug() << "push metadata to writer"; // qDebug() << "push metadata to writer";
QSettings s; // QSettings s;
this->mdata.read(s); // this->mdata.read(s);
writer->setProjectMetadata(mdata); // writer->setProjectMetadata(mdata);
dryRun = dryRunCheckBox->isChecked(); dryRun = dryRunCheckBox->isChecked();
buffer->clear(); buffer->clear();
@ -895,9 +906,7 @@ void PylonRecorder::stopRecording() {
stopRequest = true; stopRequest = true;
grab_stop_action->setEnabled(false); grab_stop_action->setEnabled(false);
qDebug() << "StopRecording: clear buffer!"; qDebug() << "StopRecording: clear buffer!";
if(buffer != nullptr) { if (dryRun){
buffer->clear();
if (dryRun)
writerDone(); writerDone();
} }
} }
@ -919,8 +928,12 @@ void PylonRecorder::writerDone() {
} }
if (writer != nullptr) if (writer != nullptr)
writer->wait(10000); writer->wait(10000);
if(buffer != nullptr) {
buffer->clear();
}
writing = false; writing = false;
updateActions(); updateActions();
qInfo() << "writer is Done!"; qInfo() << "writer is Done!";
} }
@ -933,6 +946,7 @@ void PylonRecorder::displayActivity() {
void PylonRecorder::displaySingleFrame() { void PylonRecorder::displaySingleFrame() {
qDebug() << "display single frame";
MyImage *img; MyImage *img;
size_t fc = 0; size_t fc = 0;
img = buffer->readLast(fc); img = buffer->readLast(fc);
@ -940,7 +954,7 @@ void PylonRecorder::displaySingleFrame() {
QImage qimg(static_cast<uchar *>(img->data()), img->width(), img->height(), QImage::Format::Format_Grayscale8); QImage qimg(static_cast<uchar *>(img->data()), img->width(), img->height(), QImage::Format::Format_Grayscale8);
setImage(qimg); setImage(qimg);
}else { }else {
std::cerr << "Error reading last image" << std::endl; qDebug() << "Error reading last image";
} }
} }
@ -986,7 +1000,8 @@ void PylonRecorder::displayBufferPressure() {
void PylonRecorder::grabStillFromPylon() { void PylonRecorder::grabStillFromPylon() {
qDebug() << "Grab still image form camera!"; qDebug() << "Grab still image form camera!";
if (singlecam != nullptr && singlecam->isOpen()) { if (singlecam != nullptr && singlecam->isOpen()) {
MyImage img; ImageSettings s = singlecam->getImageSettings();
MyImage img(s.width, s.height);
bool valid = singlecam->grabFrame(img); bool valid = singlecam->grabFrame(img);
if (valid) { if (valid) {
QImage qimg(static_cast<uchar *>(img.data()), img.width(), img.height(), QImage qimg(static_cast<uchar *>(img.data()), img.width(), img.height(),
@ -996,7 +1011,7 @@ void PylonRecorder::grabStillFromPylon() {
} else { } else {
statusBar()->showMessage(tr("Camera is not open! Connect to camera first!")); statusBar()->showMessage(tr("Camera is not open! Connect to camera first!"));
} }
//FIXME does not work for single camera mode! //FIXME does not work for stereo camera mode!
qDebug() << "grabbing still image done!"; qDebug() << "grabbing still image done!";
} }