roi dimensions must be multiples of four
This commit is contained in:
parent
2bed70b971
commit
767f8b7e42
@ -9,29 +9,33 @@ CameraPreview::CameraPreview(QWidget *parent):cameraname(""), camera(nullptr), Q
|
|||||||
this->setLayout(new QVBoxLayout(this));
|
this->setLayout(new QVBoxLayout(this));
|
||||||
this->layout()->addWidget(label);
|
this->layout()->addWidget(label);
|
||||||
imgLabel = new QLabel(this);
|
imgLabel = new QLabel(this);
|
||||||
imgLabel->setMinimumSize(QSize(1024, 768));
|
imgLabel->setMinimumSize(QSize(800, 600));
|
||||||
this->layout()->addWidget(imgLabel);
|
this->layout()->addWidget(imgLabel);
|
||||||
QWidget *controls = new QWidget(this);
|
QWidget *controls = new QWidget(this);
|
||||||
|
|
||||||
width = new QSpinBox(controls);
|
width = new QSpinBox(controls);
|
||||||
width->setMinimum(1);
|
width->setSingleStep(4);
|
||||||
|
width->setMinimum(4);
|
||||||
width->setMaximum(2048);
|
width->setMaximum(2048);
|
||||||
width->setValue(width->maximum());
|
width->setValue(width->maximum());
|
||||||
connect(width, SIGNAL(textChanged(QString)), SLOT(updateWidth(QString)));
|
connect(width, SIGNAL(textChanged(QString)), SLOT(updateWidth(QString)));
|
||||||
|
|
||||||
height = new QSpinBox(controls);
|
height = new QSpinBox(controls);
|
||||||
height->setMinimum(1);
|
height->setSingleStep(4);
|
||||||
|
height->setMinimum(4);
|
||||||
height->setMaximum(1536);
|
height->setMaximum(1536);
|
||||||
height->setValue(height->maximum());
|
height->setValue(height->maximum());
|
||||||
connect(height, SIGNAL(textChanged(QString)), SLOT(updateHeight(QString)));
|
connect(height, SIGNAL(textChanged(QString)), SLOT(updateHeight(QString)));
|
||||||
|
|
||||||
xoffs = new QSpinBox(controls);
|
xoffs = new QSpinBox(controls);
|
||||||
|
xoffs->setSingleStep(4);
|
||||||
xoffs->setMinimum(0);
|
xoffs->setMinimum(0);
|
||||||
xoffs->setMaximum(2047);
|
xoffs->setMaximum(2047);
|
||||||
xoffs->setValue(0);
|
xoffs->setValue(0);
|
||||||
connect(xoffs, SIGNAL(textChanged(QString)), SLOT(updateXoffs(QString)));
|
connect(xoffs, SIGNAL(textChanged(QString)), SLOT(updateXoffs(QString)));
|
||||||
|
|
||||||
yoffs = new QSpinBox(controls);
|
yoffs = new QSpinBox(controls);
|
||||||
|
yoffs->setSingleStep(4);
|
||||||
yoffs->setMinimum(0);
|
yoffs->setMinimum(0);
|
||||||
yoffs->setMaximum(1535);
|
yoffs->setMaximum(1535);
|
||||||
yoffs->setValue(0);
|
yoffs->setValue(0);
|
||||||
@ -95,7 +99,7 @@ void CameraPreview::takeStill() {
|
|||||||
QImage::Format::Format_Grayscale8);
|
QImage::Format::Format_Grayscale8);
|
||||||
QPixmap mpm = QPixmap::fromImage(img);
|
QPixmap mpm = QPixmap::fromImage(img);
|
||||||
this->pm = mpm;
|
this->pm = mpm;
|
||||||
mpm = mpm.scaledToWidth(1024);
|
mpm = mpm.scaledToWidth(800);
|
||||||
setImage(mpm);
|
setImage(mpm);
|
||||||
updateROI();
|
updateROI();
|
||||||
} else {
|
} else {
|
||||||
@ -140,15 +144,25 @@ void CameraPreview::updateYoffs(QString s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CameraPreview::validate(QSpinBox *origin, QSpinBox *dest, int limit){
|
void CameraPreview::validate(QSpinBox *origin, QSpinBox *dest, int limit){
|
||||||
|
int val = ensureDivbyfour(origin->value());
|
||||||
|
origin->setValue(val);
|
||||||
if (origin->value() + dest->value() > limit) {
|
if (origin->value() + dest->value() > limit) {
|
||||||
dest->setValue(limit - origin->value());
|
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) {
|
void CameraPreview::updateROI(bool emitSignal) {
|
||||||
QImage img = pm.toImage();
|
QImage img = pm.toImage();
|
||||||
double scaling = 1024.0 / img.width();
|
double scaling = 800.0 / img.width();
|
||||||
img = img.scaledToWidth(1024);
|
img = img.scaledToWidth(800);
|
||||||
QPainter qPainter(&img);
|
QPainter qPainter(&img);
|
||||||
qPainter.setBrush(Qt::NoBrush);
|
qPainter.setBrush(Qt::NoBrush);
|
||||||
qPainter.setPen(Qt::red);
|
qPainter.setPen(Qt::red);
|
||||||
|
@ -52,7 +52,7 @@ private:
|
|||||||
void takeStill();
|
void takeStill();
|
||||||
void setImage(const QPixmap &img);
|
void setImage(const QPixmap &img);
|
||||||
void validate(QSpinBox *origin, QSpinBox *dest, int limit);
|
void validate(QSpinBox *origin, QSpinBox *dest, int limit);
|
||||||
|
int ensureDivbyfour(int value);
|
||||||
PylonWrapper *camera;
|
PylonWrapper *camera;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -193,12 +193,16 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
|
|||||||
|
|
||||||
void DualcamWrapper::setROI() {
|
void DualcamWrapper::setROI() {
|
||||||
for (int camindex = 0; camindex < 2; camindex++){
|
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);
|
GenApi::INodeMap &nodemap = getNodemap(camindex);
|
||||||
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width);
|
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width);
|
||||||
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height);
|
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height);
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x);
|
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x);
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y);
|
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y);
|
||||||
|
} catch (const Pylon::GenericException &e) {
|
||||||
|
std::cerr << e.GetDescription() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user