From 767f8b7e42f5ebba76f81c5009da496877abbdc9 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Mon, 18 Mar 2024 11:46:57 +0100 Subject: [PATCH] roi dimensions must be multiples of four --- camerapreview.cpp | 26 ++++++++++++++++++++------ camerapreview.h | 2 +- dualcamwrapper.cpp | 28 ++++++++++++++++------------ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/camerapreview.cpp b/camerapreview.cpp index d52acb2..6c714f3 100644 --- a/camerapreview.cpp +++ b/camerapreview.cpp @@ -9,29 +9,33 @@ CameraPreview::CameraPreview(QWidget *parent):cameraname(""), camera(nullptr), Q this->setLayout(new QVBoxLayout(this)); this->layout()->addWidget(label); imgLabel = new QLabel(this); - imgLabel->setMinimumSize(QSize(1024, 768)); + imgLabel->setMinimumSize(QSize(800, 600)); this->layout()->addWidget(imgLabel); QWidget *controls = new QWidget(this); width = new QSpinBox(controls); - width->setMinimum(1); + width->setSingleStep(4); + width->setMinimum(4); width->setMaximum(2048); width->setValue(width->maximum()); connect(width, SIGNAL(textChanged(QString)), SLOT(updateWidth(QString))); height = new QSpinBox(controls); - height->setMinimum(1); + height->setSingleStep(4); + height->setMinimum(4); height->setMaximum(1536); height->setValue(height->maximum()); connect(height, SIGNAL(textChanged(QString)), SLOT(updateHeight(QString))); xoffs = new QSpinBox(controls); + xoffs->setSingleStep(4); xoffs->setMinimum(0); xoffs->setMaximum(2047); xoffs->setValue(0); connect(xoffs, SIGNAL(textChanged(QString)), SLOT(updateXoffs(QString))); yoffs = new QSpinBox(controls); + yoffs->setSingleStep(4); yoffs->setMinimum(0); yoffs->setMaximum(1535); yoffs->setValue(0); @@ -95,7 +99,7 @@ void CameraPreview::takeStill() { QImage::Format::Format_Grayscale8); QPixmap mpm = QPixmap::fromImage(img); this->pm = mpm; - mpm = mpm.scaledToWidth(1024); + mpm = mpm.scaledToWidth(800); setImage(mpm); updateROI(); } else { @@ -140,15 +144,25 @@ void CameraPreview::updateYoffs(QString s) { } void CameraPreview::validate(QSpinBox *origin, QSpinBox *dest, int limit){ + int val = ensureDivbyfour(origin->value()); + origin->setValue(val); if (origin->value() + dest->value() > limit) { dest->setValue(limit - origin->value()); } } +int CameraPreview::ensureDivbyfour(int val) { + if (val % 4 != 0) { + int divisor = floor(val / 4); + val = divisor * 4; + } + return val; +} + void CameraPreview::updateROI(bool emitSignal) { QImage img = pm.toImage(); - double scaling = 1024.0 / img.width(); - img = img.scaledToWidth(1024); + double scaling = 800.0 / img.width(); + img = img.scaledToWidth(800); QPainter qPainter(&img); qPainter.setBrush(Qt::NoBrush); qPainter.setPen(Qt::red); diff --git a/camerapreview.h b/camerapreview.h index dcc540a..09ce0b8 100644 --- a/camerapreview.h +++ b/camerapreview.h @@ -52,7 +52,7 @@ private: void takeStill(); void setImage(const QPixmap &img); void validate(QSpinBox *origin, QSpinBox *dest, int limit); - + int ensureDivbyfour(int value); PylonWrapper *camera; }; diff --git a/dualcamwrapper.cpp b/dualcamwrapper.cpp index d897eff..5b450a1 100644 --- a/dualcamwrapper.cpp +++ b/dualcamwrapper.cpp @@ -193,12 +193,16 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) { void DualcamWrapper::setROI() { for (int camindex = 0; camindex < 2; camindex++){ - qDebug() << "Setting ROI: w" << layout.rois[camindex].width << " h: "<< layout.rois[camindex].height << " x " << layout.rois[camindex].x << " y " << layout.rois[camindex].y << std::endl; + qDebug() << "Setting ROI: w" << layout.rois[camindex].width << " h: "<< layout.rois[camindex].height << " x " << layout.rois[camindex].x << " y " << layout.rois[camindex].y; + try { GenApi::INodeMap &nodemap = getNodemap(camindex); Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width); Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height); Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x); Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y); + } catch (const Pylon::GenericException &e) { + std::cerr << e.GetDescription() << std::endl; + } } } @@ -207,17 +211,17 @@ void DualcamWrapper::resetCamera(int camindex) { GenApi::INodeMap &nodemap = getNodemap( camindex ); int64_t dfltWidth = 2048; int64_t dfltHeight = 1536; - qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")"; - try { - Pylon::CIntegerParameter(nodemap, "Width").SetValue(dfltWidth, false); - Pylon::CIntegerParameter(nodemap, "Height").SetValue(dfltHeight, false); - Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(0); - Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(0); - } catch (const Pylon::GenericException &e) { - std::string message = e.GetDescription(); - std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl; - valid = false; - } + qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")"; + try { + Pylon::CIntegerParameter(nodemap, "Width").SetValue(dfltWidth, false); + Pylon::CIntegerParameter(nodemap, "Height").SetValue(dfltHeight, false); + Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(0); + Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(0); + } catch (const Pylon::GenericException &e) { + std::string message = e.GetDescription(); + std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl; + valid = false; + } }