roi dimensions must be multiples of four

This commit is contained in:
Jan Grewe 2024-03-18 11:46:57 +01:00
parent 2bed70b971
commit 767f8b7e42
3 changed files with 37 additions and 19 deletions

View File

@ -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);

View File

@ -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;
};

View File

@ -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;
}
}