Compare commits

..

1 Commits

Author SHA1 Message Date
767f8b7e42 roi dimensions must be multiples of four 2024-03-18 11:46:57 +01:00
10 changed files with 82 additions and 64 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);
@@ -65,7 +69,7 @@ void CameraPreview::setCamera(QString &device){
delete camera;
camera = nullptr;
}
camera = new SingleCamWrapper(cameraname.toStdString());
camera = new PylonWrapper(cameraname.toStdString());
std::string message;
bool success = camera->openCamera(message);
if (!success) {
@@ -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

@@ -12,7 +12,7 @@
#include <QPainter>
#include <pylon/PylonIncludes.h>
#include "singlecamwrapper.h"
#include "pylonwrapper.h"
#include "util.h"
namespace Ui {
class CameraPreview;
@@ -52,8 +52,8 @@ private:
void takeStill();
void setImage(const QPixmap &img);
void validate(QSpinBox *origin, QSpinBox *dest, int limit);
SingleCamWrapper *camera;
int ensureDivbyfour(int value);
PylonWrapper *camera;
};

View File

@@ -194,11 +194,15 @@ 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;
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;
}
}

View File

@@ -1,8 +1,8 @@
#include "singlecamgrabber.h"
#include "grabber.h"
#include <iostream>
#include <pylon/PylonIncludes.h>
void SinglecamGrabber::run() {
void Grabber::run() {
stop_request = false;
int count = 0;
if (camera->isOpen()) {

View File

@@ -1,16 +1,16 @@
#ifndef SINGLECAMGRABBER_H
#define SINGLECAMGRABBER_H
#ifndef GRABBER_H
#define GRABBER_H
#include <QObject>
#include <QThread>
#include "singlecamwrapper.h"
#include "pylonwrapper.h"
#include "imagebuffer.h"
class SinglecamGrabber : public QThread
class Grabber : public QThread
{
Q_OBJECT
public:
SinglecamGrabber(SingleCamWrapper *camera, ImageBuffer*buffer, int framerate, QObject *parent = nullptr) :
Grabber(PylonWrapper *camera, ImageBuffer*buffer, int framerate, QObject *parent = nullptr) :
QThread(parent), camera(camera), buffer(buffer), framerate(framerate) {}
void run() override;
@@ -29,7 +29,7 @@ public:
private:
bool stop_request = false;
SingleCamWrapper *camera;
PylonWrapper *camera;
ImageBuffer *buffer;
int framerate;
double exposure, gain;
@@ -51,4 +51,4 @@ signals:
void terminated();
};
#endif // SINGLECAMGRABBER_H
#endif // GRABBER_H

View File

@@ -652,7 +652,7 @@ void PylonRecorder::connectCamera() {
std::string cname = layout.devices[0];
std::string message;
qDebug() << "connecting to camera " << cname.c_str();
singlecam = new SingleCamWrapper(layout);
singlecam = new PylonWrapper(layout);
bool success = singlecam->openCamera(message);
if (success) {
cameraConnectedLabel->setText("connected");
@@ -762,7 +762,7 @@ void PylonRecorder::startSinglecamRecording() {
delete singlecamgrabber;
singlecamgrabber = nullptr;
}
singlecamgrabber = new SinglecamGrabber(singlecam, buffer, defaultFrameRate);
singlecamgrabber = new Grabber(singlecam, buffer, defaultFrameRate);
if (framerateSpinner->value() != singlecamgrabber->currentFramerate())
singlecamgrabber->setFrameRate(framerateSpinner->value());

View File

@@ -7,10 +7,10 @@
#include <QCheckBox>
#include <QSettings>
#include <pylon/PylonIncludes.h>
#include "singlecamwrapper.h"
#include "pylonwrapper.h"
#include "dualcamwrapper.h"
#include "imagebuffer.h"
#include "singlecamgrabber.h"
#include "grabber.h"
#include "dualcamgrabber.h"
#include "writer.h"
#include "projectsettings.h"
@@ -105,10 +105,10 @@ private:
QProgressBar *loadBar;
QScrollArea *scrollArea;
double scaleFactor = 1;
SingleCamWrapper *singlecam;
PylonWrapper *singlecam;
DualcamWrapper *dualcam;
ImageBuffer *buffer;
SinglecamGrabber *singlecamgrabber;
Grabber *singlecamgrabber;
DualcamGrabber *dualcamgrabber;
Writer *writer;
CameraLayout layout;

View File

@@ -1,19 +1,19 @@
#include "singlecamwrapper.h"
#include "pylonwrapper.h"
SingleCamWrapper::SingleCamWrapper(const std::string &fullName):
PylonWrapper::PylonWrapper(const std::string &fullName):
valid(false), fullName(fullName), camera(nullptr), withLayout(false) {
qDebug() << "Constructor with name";
Pylon::PylonInitialize();
}
SingleCamWrapper::SingleCamWrapper(const CameraLayout &layout): valid(false), withLayout(true), camera(nullptr) {
PylonWrapper::PylonWrapper(const CameraLayout &layout): valid(false), withLayout(true), camera(nullptr) {
qDebug() << "Constructor with layout";
this->fullName = layout.devices[0];
this->layout = layout;
Pylon::PylonInitialize();
}
SingleCamWrapper::~SingleCamWrapper() {
PylonWrapper::~PylonWrapper() {
qDebug() << "wrapper destructor";
if (camera != nullptr){
if (camera->IsOpen()) {
@@ -27,7 +27,7 @@ SingleCamWrapper::~SingleCamWrapper() {
qDebug() << "Successfully deleted camera";
}
void SingleCamWrapper::terminate() {
void PylonWrapper::terminate() {
qDebug() << "Terminate";
try {
Pylon::PylonTerminate();
@@ -36,11 +36,11 @@ void SingleCamWrapper::terminate() {
}
}
bool SingleCamWrapper::isOpen() {
bool PylonWrapper::isOpen() {
return valid;
}
double SingleCamWrapper::maxFrameRate() {
double PylonWrapper::maxFrameRate() {
double max_rate = -1;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -51,7 +51,7 @@ double SingleCamWrapper::maxFrameRate() {
return max_rate;
}
bool SingleCamWrapper::frameRate(uint new_framerate) {
bool PylonWrapper::frameRate(uint new_framerate) {
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
@@ -66,7 +66,7 @@ bool SingleCamWrapper::frameRate(uint new_framerate) {
return false;
}
double SingleCamWrapper::frameRate() {
double PylonWrapper::frameRate() {
double rate = -1.;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -77,7 +77,7 @@ double SingleCamWrapper::frameRate() {
return rate;
}
double SingleCamWrapper::exposureTime() {
double PylonWrapper::exposureTime() {
double time = -1.;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -88,7 +88,7 @@ double SingleCamWrapper::exposureTime() {
return time;
}
bool SingleCamWrapper::exposureTime(double exposure_time) {
bool PylonWrapper::exposureTime(double exposure_time) {
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
double d = GenApi::CFloatPtr(nodemap.GetNode("ExposureTime"))->GetValue();
@@ -105,7 +105,7 @@ bool SingleCamWrapper::exposureTime(double exposure_time) {
return false;
}
double SingleCamWrapper::gain() {
double PylonWrapper::gain() {
double gain = -1.;
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
@@ -116,7 +116,7 @@ double SingleCamWrapper::gain() {
return gain;
}
bool SingleCamWrapper::gain(double gain_db) {
bool PylonWrapper::gain(double gain_db) {
if (valid) {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
GenApi::CFloatPtr(nodemap.GetNode("Gain"))->SetValue(gain_db);
@@ -125,7 +125,7 @@ bool SingleCamWrapper::gain(double gain_db) {
return false;
}
ImageSettings SingleCamWrapper::getImageSettings() {
ImageSettings PylonWrapper::getImageSettings() {
ImageSettings settings;
if (valid) {
Pylon::CEnumParameter pixelFormat( camera->GetNodeMap(), "PixelFormat" );
@@ -141,7 +141,7 @@ ImageSettings SingleCamWrapper::getImageSettings() {
return settings;
}
bool SingleCamWrapper::grabFrame(MyImage &img) {
bool PylonWrapper::grabFrame(MyImage &img) {
Pylon::CGrabResultPtr frame;
qDebug() << "grabFrame";
if (valid) {
@@ -162,7 +162,7 @@ bool SingleCamWrapper::grabFrame(MyImage &img) {
return frame.IsValid();
}
void SingleCamWrapper::resetCamera() {
void PylonWrapper::resetCamera() {
int64_t dfltWidth = 2048;
int64_t dfltHeight = 1536;
qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")";
@@ -181,7 +181,7 @@ void SingleCamWrapper::resetCamera() {
}
}
bool SingleCamWrapper::openCamera(std::string &message) {
bool PylonWrapper::openCamera(std::string &message) {
qDebug() << "opening camera";
try {
camera = new Pylon::CInstantCamera();
@@ -215,7 +215,7 @@ bool SingleCamWrapper::openCamera(std::string &message) {
return valid;
}
void SingleCamWrapper::closeCamera() {
void PylonWrapper::closeCamera() {
qDebug() << "Close camera!";
if (camera->IsOpen()) {
try {
@@ -229,11 +229,11 @@ void SingleCamWrapper::closeCamera() {
}
}
Pylon::CInstantCamera *SingleCamWrapper::getCamera() {
Pylon::CInstantCamera *PylonWrapper::getCamera() {
return camera;
}
QString SingleCamWrapper::userName() {
QString PylonWrapper::userName() {
GenApi::INodeMap& nodemap = camera->GetNodeMap();
QString username = Pylon::CStringParameter(nodemap, "DeviceUserID").GetValue().c_str();
return username;

View File

@@ -1,5 +1,5 @@
#ifndef SINGLECAMWRAPPER_H
#define SINGLECAMWRAPPER_H
#ifndef PYLONWRAPPER_H
#define PYLONWRAPPER_H
#include <pylon/PylonIncludes.h>
#include <pylon/BaslerUniversalInstantCamera.h>
@@ -7,12 +7,12 @@
#include "util.h"
#include "myimage.h"
class SingleCamWrapper
class PylonWrapper
{
public:
SingleCamWrapper(const std::string &name);
SingleCamWrapper(const CameraLayout &layout);
~SingleCamWrapper();
PylonWrapper(const std::string &name);
PylonWrapper(const CameraLayout &layout);
~PylonWrapper();
ImageSettings getImageSettings();
bool isOpen();
@@ -41,4 +41,4 @@ private:
};
#endif // SINGLECAMWRAPPER_H
#endif // PYLONWRAPPER_H

View File

@@ -6,7 +6,7 @@
#include <pylon/PylonIncludes.h>
#include <nix.hpp>
#include "singlecamwrapper.h"
#include "pylonwrapper.h"
#include "imagebuffer.h"
#include "projectsettings.h"
#include "util.h"