taking still image works with specified ROI

This commit is contained in:
Jan Grewe 2024-03-06 09:18:43 +01:00
parent 6a82c8d640
commit adf48f3002
4 changed files with 66 additions and 25 deletions

View File

@ -56,6 +56,7 @@ CameraPreview::CameraPreview(QWidget *parent):cameraname(""), camera(nullptr), Q
takeStill(); takeStill();
} }
void CameraPreview::setCamera(QString &device){ void CameraPreview::setCamera(QString &device){
qDebug() << "update camera! ";// << device.toStdString(); qDebug() << "update camera! ";// << device.toStdString();
cameraname = device; cameraname = device;

View File

@ -628,13 +628,12 @@ void PylonRecorder::connectCamera() {
msgBox.exec(); msgBox.exec();
} else { } else {
cameraConfiguration(); cameraConfiguration();
if (layout.mode == CameraMode::single) { if (layout.mode == CameraMode::single && layout.devices.size() == 1) {
qDebug() << "single camera mode"; qDebug() << "single camera mode";
assert(layout.devices.size() == 1);
std::string cname = layout.devices[0]; std::string cname = layout.devices[0];
std::string message; std::string message;
qDebug() << "connecting to camera " << cname.c_str(); qDebug() << "connecting to camera " << cname.c_str();
pyloncam = new PylonWrapper(cname); pyloncam = new PylonWrapper(layout);
bool success = pyloncam->openCamera(message); bool success = pyloncam->openCamera(message);
if (success) { if (success) {
cameraConnectedLabel->setText("connected"); cameraConnectedLabel->setText("connected");

View File

@ -1,29 +1,29 @@
#include "pylonwrapper.h" #include "pylonwrapper.h"
PylonWrapper::PylonWrapper(const std::string &fullName): PylonWrapper::PylonWrapper(const std::string &fullName):
valid(false), fullName(fullName), camera(nullptr) { valid(false), fullName(fullName), camera(nullptr), withLayout(false) {
qDebug() << "Constructor with name";
Pylon::PylonInitialize();
}
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(); Pylon::PylonInitialize();
// camera = new Pylon::CInstantCamera();
// std::cerr << "Wrapper:camera is open" << camera->IsOpen() << std::endl;
// std::cerr << "Wrapper:is valid" << valid << std::endl;
} }
PylonWrapper::~PylonWrapper() { PylonWrapper::~PylonWrapper() {
std::cerr << "wrapper destructor" << std::endl; qDebug() << "wrapper destructor";
if (camera != nullptr){ if (camera != nullptr){
std::cerr << "check camera!" << std::endl;
if (camera->IsOpen()) { if (camera->IsOpen()) {
std::cerr << "close camera!" << std::endl; qDebug() << "Camera open, closing it!";
camera->Close(); camera->Close();
// std::cerr << "terminate pylon" << std::endl;
// terminate();
} }
std::cerr << "delete camera!" << std::endl;
delete camera; delete camera;
camera = nullptr; camera = nullptr;
} }
std::cerr << "wrapper: deleted camera" << std::endl; qDebug() << "Successfully deleted camera";
} }
void PylonWrapper::terminate() { void PylonWrapper::terminate() {
@ -141,6 +141,15 @@ ImageSettings PylonWrapper::getImageSettings() {
bool PylonWrapper::grabFrame(MyImage &img) { bool PylonWrapper::grabFrame(MyImage &img) {
Pylon::CGrabResultPtr frame; Pylon::CGrabResultPtr frame;
if (valid) { if (valid) {
qDebug() << "Setting width" << layout.rois[0].width;
Pylon::CIntegerParameter(camera->GetNodeMap(), "Width").SetValue(layout.rois[0].width);
qDebug() << "Setting height" << layout.rois[0].height;
Pylon::CIntegerParameter(camera->GetNodeMap(), "Height").SetValue(layout.rois[0].height);
qDebug() << "Setting xoffset" << layout.rois[0].x;
Pylon::CIntegerParameter(camera->GetNodeMap(), "OffsetX").SetValue(layout.rois[0].x);
qDebug() << "Setting yoffset" << layout.rois[0].y;
Pylon::CIntegerParameter(camera->GetNodeMap(), "OffsetY").SetValue(layout.rois[0].y);
camera->StartGrabbing(); camera->StartGrabbing();
camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException); camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
camera->StopGrabbing(); camera->StopGrabbing();
@ -149,28 +158,54 @@ bool PylonWrapper::grabFrame(MyImage &img) {
return frame.IsValid(); return frame.IsValid();
} }
void PylonWrapper::resetCamera() {
std::string n = std::string(Pylon::CStringParameter(camera->GetNodeMap(), "DeviceUserID").GetValue());
int64_t maxWidth = 2048;
int64_t maxHeight = 1536;
Pylon::CIntegerParameter(camera->GetNodeMap(), "Width").SetValue(maxWidth);
Pylon::CIntegerParameter(camera->GetNodeMap(), "Height").SetValue(maxHeight);
Pylon::CIntegerParameter(camera->GetNodeMap(), "OffsetX").SetValue(0);
Pylon::CIntegerParameter(camera->GetNodeMap(), "OffsetY").SetValue(0);
}
bool PylonWrapper::openCamera(std::string &message) { bool PylonWrapper::openCamera(std::string &message) {
qDebug() << "opening camera";
try { try {
camera = new Pylon::CInstantCamera(); camera = new Pylon::CInstantCamera();
// Pylon::CInstantCamera camera( pTl->CreateDevice( lstDevices[0] ); // Pylon::CInstantCamera camera( pTl->CreateDevice( lstDevices[0] );
// Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateFirstDevice(); // Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateFirstDevice();
Pylon::String_t fname(fullName.c_str()); Pylon::String_t fname(fullName.c_str());
Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateDevice(fname); Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateDevice(fname);
camera->Attach(pDevice); camera->Attach(pDevice);
camera->Open(); camera->Open();
resetCamera();
valid = camera->IsOpen(); valid = camera->IsOpen();
message = "Successfully opened camera!"; message = "Successfully opened camera!";
} catch (const Pylon::GenericException &e) { } catch (const Pylon::GenericException &e) {
message = e.GetDescription(); message = e.GetDescription();
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl; std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
valid = false; valid = false;
return valid;
}
if (!withLayout) {
qDebug() << "opening camera without layout, creating a new one";
ImageSettings s = getImageSettings();
layout = CameraLayout();
layout.devices.push_back(fullName);
ROI r = ROI();
r.x = 0;
r.y = 0;
r.width = s.width;
r.height = s.height;
layout.rois.push_back(r);
layout.layout = Layout::horizontal;
layout.mode = CameraMode::single;
} }
return valid; return valid;
} }
void PylonWrapper::closeCamera() { void PylonWrapper::closeCamera() {
std::cerr << "camera close !" << std::endl; qDebug() << "Close camera!";
if (camera->IsOpen()) { if (camera->IsOpen()) {
try { try {
camera->Close(); camera->Close();
@ -178,9 +213,10 @@ void PylonWrapper::closeCamera() {
delete camera; delete camera;
camera = nullptr; camera = nullptr;
} catch (const Pylon::GenericException &e) { } catch (const Pylon::GenericException &e) {
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl; qWarning() << "An exception occurred." << e.GetDescription();
} }
} }
qDebug() << "Successfully closed camera!";
} }
Pylon::CInstantCamera *PylonWrapper::getCamera() { Pylon::CInstantCamera *PylonWrapper::getCamera() {

View File

@ -3,6 +3,8 @@
#include <pylon/PylonIncludes.h> #include <pylon/PylonIncludes.h>
#include <pylon/BaslerUniversalInstantCamera.h> #include <pylon/BaslerUniversalInstantCamera.h>
#include "mylogger.h"
#include "util.h"
#include "myimage.h" #include "myimage.h"
struct ImageSettings { struct ImageSettings {
@ -15,7 +17,8 @@ struct ImageSettings {
class PylonWrapper class PylonWrapper
{ {
public: public:
PylonWrapper(const std::string &fullName); PylonWrapper(const std::string &name);
PylonWrapper(const CameraLayout &layout);
~PylonWrapper(); ~PylonWrapper();
ImageSettings getImageSettings(); ImageSettings getImageSettings();
@ -32,11 +35,13 @@ public:
double gain(); double gain();
bool gain(double gain_db); bool gain(double gain_db);
Pylon::CInstantCamera *getCamera(); Pylon::CInstantCamera *getCamera();
void resetCamera();
private: private:
Pylon::CInstantCamera *camera; Pylon::CInstantCamera *camera;
bool valid; bool valid, withLayout;
std::string fullName; std::string fullName;
CameraLayout layout;