simplify setter and support setting of indicidual values

This commit is contained in:
Jan Grewe 2024-03-11 16:06:14 +01:00
parent e259d668ad
commit a013ab1153
2 changed files with 106 additions and 171 deletions

View File

@ -1,8 +1,7 @@
#include "dualcamwrapper.h" #include "dualcamwrapper.h"
DualcamWrapper::DualcamWrapper(const CameraLayout &layout): valid(false), withLayout(true), camera0(nullptr), camera1(nullptr), cameras(2, nullptr) { DualcamWrapper::DualcamWrapper(const CameraLayout &layout): valid(false), withLayout(true) {
qDebug() << "Constructor with layout"; qDebug() << "Constructor with layout";
this->fullName = layout.devices[0];
this->layout = layout; this->layout = layout;
Pylon::PylonInitialize(); Pylon::PylonInitialize();
} }
@ -10,21 +9,11 @@ DualcamWrapper::DualcamWrapper(const CameraLayout &layout): valid(false), withLa
DualcamWrapper::~DualcamWrapper() { DualcamWrapper::~DualcamWrapper() {
qDebug() << "wrapper destructor"; qDebug() << "wrapper destructor";
if (camera0 != nullptr){ for (int i =0; i < cameras.GetSize(); ++i) {
if (camera0->IsOpen()) { if (cameras[i].IsOpen()) {
qDebug() << "Camera 0 is open, closing it!"; cameras[i].Close();
camera0->Close(); qDebug() << "Camera " << i << " is open, closing it!";
} }
delete camera0;
camera0 = nullptr;
}
if (camera1 != nullptr){
if (camera1->IsOpen()) {
qDebug() << "Camera 1 is open, closing it!";
camera1->Close();
}
delete camera1;
camera1 = nullptr;
} }
terminate(); terminate();
qDebug() << "Successfully deleted cameras"; qDebug() << "Successfully deleted cameras";
@ -46,11 +35,11 @@ bool DualcamWrapper::isOpen() {
} }
double DualcamWrapper::maxFrameRate() { double DualcamWrapper::maxFrameRate(int camindex) {
assert(camindex >= 0 && camindex < 2);
double max_rate = -1; double max_rate = -1;
// FIXME max framerate of both cameras!
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); GenApi::INodeMap& nodemap = getNodemap(camindex);
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRate" ); GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRate" );
Pylon::CFloatParameter framerate( n ); Pylon::CFloatParameter framerate( n );
return framerate.GetMax(); return framerate.GetMax();
@ -59,36 +48,34 @@ double DualcamWrapper::maxFrameRate() {
} }
bool DualcamWrapper::frameRate(uint new_framerate) { bool DualcamWrapper::frameRate(uint new_framerate, int camindex) {
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); if (camindex == -1) {
frameRate(new_framerate, 0);
frameRate(new_framerate, 1);
return true;
} else if (camindex == 0 && camindex ==1) {
GenApi::INodeMap& nodemap = getNodemap(0);
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" ); GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
Pylon::CBooleanParameter enableframerate(n); Pylon::CBooleanParameter enableframerate(n);
enableframerate.SetValue(true); enableframerate.SetValue(true);
n = nodemap.GetNode( "AcquisitionFrameRate" ); n = nodemap.GetNode( "AcquisitionFrameRate" );
Pylon::CFloatParameter framerate( n ); Pylon::CFloatParameter framerate( n );
framerate.SetValue( new_framerate ); framerate.SetValue( new_framerate );
nodemap = camera1->GetNodeMap();
n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
Pylon::CBooleanParameter enableframerate1(n);
enableframerate1.SetValue(true);
n = nodemap.GetNode( "AcquisitionFrameRate" );
Pylon::CFloatParameter framerate1( n );
framerate1.SetValue( new_framerate );
return true; return true;
} else {
return false;
}
} }
return false; return false;
} }
double DualcamWrapper::frameRate() { double DualcamWrapper::frameRate(int camindex) {
assert(camindex > 0 && camindex < 2);
double rate = -1.; double rate = -1.;
//FIXME read framerate setting from both cameras
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); GenApi::INodeMap& nodemap = getNodemap(camindex);
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRate" ); GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRate" );
Pylon::CFloatParameter framerate( n ); Pylon::CFloatParameter framerate( n );
rate = framerate.GetValue(); rate = framerate.GetValue();
@ -97,11 +84,11 @@ double DualcamWrapper::frameRate() {
} }
double DualcamWrapper::exposureTime() { double DualcamWrapper::exposureTime(int camindex) {
//FIXME exposure setting from both cameras assert(camindex > 0 && camindex < 2);
double time = -1.; double time = -1.;
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); GenApi::INodeMap& nodemap = getNodemap(camindex);
GenApi::INode* n = nodemap.GetNode( "ExposureTime" ); GenApi::INode* n = nodemap.GetNode( "ExposureTime" );
Pylon::CFloatParameter exposure_time( n ); Pylon::CFloatParameter exposure_time( n );
time = exposure_time.GetValue(); time = exposure_time.GetValue();
@ -111,9 +98,12 @@ double DualcamWrapper::exposureTime() {
bool DualcamWrapper::exposureTime(double exposure_time, int camindex) { bool DualcamWrapper::exposureTime(double exposure_time, int camindex) {
// FIXME support setting exposure individually
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); if (camindex == -1) {
exposureTime(exposure_time, 0);
exposureTime(exposure_time, 1);
} else {
GenApi::INodeMap& nodemap = getNodemap(camindex);
double d = GenApi::CFloatPtr(nodemap.GetNode("ExposureTime"))->GetValue(); double d = GenApi::CFloatPtr(nodemap.GetNode("ExposureTime"))->GetValue();
GenApi::INode* n = nodemap.GetNode( "ExposureTime" ); GenApi::INode* n = nodemap.GetNode( "ExposureTime" );
try { try {
@ -123,27 +113,17 @@ bool DualcamWrapper::exposureTime(double exposure_time, int camindex) {
} }
Pylon::CFloatParameter exp_time( n ); Pylon::CFloatParameter exp_time( n );
exp_time.SetValue( exposure_time ); exp_time.SetValue( exposure_time );
nodemap = camera1->GetNodeMap();
d = GenApi::CFloatPtr(nodemap.GetNode("ExposureTime"))->GetValue();
n = nodemap.GetNode( "ExposureTime" );
try {
GenApi::CEnumerationPtr(nodemap.GetNode( "ExposureTimeMode" ))->FromString("Standard");
} catch (...) {
qWarning() << "Could not set exposure for cam1";
} }
Pylon::CFloatParameter exp_time1( n );
exp_time1.SetValue( exposure_time );
return true;
} }
return false; return false;
} }
double DualcamWrapper::gain() { double DualcamWrapper::gain(int camindex) {
assert(camindex >= 0 && camindex < 2);
double gain = -1.; double gain = -1.;
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); GenApi::INodeMap& nodemap = getNodemap(camindex);
GenApi::INode* n = nodemap.GetNode( "Gain" ); GenApi::INode* n = nodemap.GetNode( "Gain" );
Pylon::CFloatParameter detector_gain( n ); Pylon::CFloatParameter detector_gain( n );
gain = detector_gain.GetValue(); gain = detector_gain.GetValue();
@ -154,12 +134,16 @@ double DualcamWrapper::gain() {
bool DualcamWrapper::gain(double gain_db, int camindex) { bool DualcamWrapper::gain(double gain_db, int camindex) {
if (valid) { if (valid) {
GenApi::INodeMap& nodemap = camera0->GetNodeMap(); if (camindex == -1) {
GenApi::CFloatPtr(nodemap.GetNode("Gain"))->SetValue(gain_db); gain(gain_db, 0);
gain(gain_db, 1);
nodemap = camera1->GetNodeMap(); } else if (camindex >= 0 && camindex < 2) {
GenApi::INodeMap& nodemap = getNodemap(camindex);
GenApi::CFloatPtr(nodemap.GetNode("Gain"))->SetValue(gain_db); GenApi::CFloatPtr(nodemap.GetNode("Gain"))->SetValue(gain_db);
return true; return true;
} else{
return false;
}
} }
return false; return false;
} }
@ -169,12 +153,6 @@ ImageSettings DualcamWrapper::getImageSettings(int camindex) {
ImageSettings settings; ImageSettings settings;
if (valid) { if (valid) {
GenApi::INodeMap &nodemap = getNodemap(camindex); GenApi::INodeMap &nodemap = getNodemap(camindex);
// GenApi::INodeMap& nodemap;
// if (camindex == 0) {
// nodemap = camera0->GetNodeMap();
// } else {
// nodemap = camera1->GetNodeMap();
// }
Pylon::CEnumParameter pixelFormat( nodemap, "PixelFormat" ); Pylon::CEnumParameter pixelFormat( nodemap, "PixelFormat" );
Pylon::CPixelTypeMapper pixelTypeMapper( &pixelFormat ); Pylon::CPixelTypeMapper pixelTypeMapper( &pixelFormat );
Pylon::EPixelType pixelType = pixelTypeMapper.GetPylonPixelTypeFromNodeValue( pixelFormat.GetIntValue() ); Pylon::EPixelType pixelType = pixelTypeMapper.GetPylonPixelTypeFromNodeValue( pixelFormat.GetIntValue() );
@ -195,14 +173,6 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
qDebug() << "grabFrame from camera " << camindex; qDebug() << "grabFrame from camera " << camindex;
if (valid) { if (valid) {
GenApi::INodeMap &nodemap = getNodemap(camindex); GenApi::INodeMap &nodemap = getNodemap(camindex);
// GenApi::INodeMap& nodemap;
// if (camindex == 0) {
// nodemap = camera0->GetNodeMap();
// camera = camera0;
// } else {
// nodemap = camera1->GetNodeMap();
// camera = camera1;
// }
qDebug() << "Setting width" << layout.rois[0].width; qDebug() << "Setting width" << layout.rois[0].width;
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[0].width); Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[0].width);
qDebug() << "Setting height" << layout.rois[0].height; qDebug() << "Setting height" << layout.rois[0].height;
@ -223,10 +193,6 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
void DualcamWrapper::resetCamera(int camindex) { void DualcamWrapper::resetCamera(int camindex) {
GenApi::INodeMap &nodemap = getNodemap( camindex ); GenApi::INodeMap &nodemap = getNodemap( camindex );
// ->GetNodeMap();;
// if (camindex == 1){
// nodemap = camera1->GetNodeMap();
// }
int64_t dfltWidth = 2048; int64_t dfltWidth = 2048;
int64_t dfltHeight = 1536; int64_t dfltHeight = 1536;
qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")"; qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")";
@ -248,13 +214,14 @@ void DualcamWrapper::resetCamera(int camindex) {
bool DualcamWrapper::openCameras(std::string &message) { bool DualcamWrapper::openCameras(std::string &message) {
qDebug() << "opening cameras"; qDebug() << "opening cameras";
bool valid = true; bool valid = true;
Pylon::CTlFactory& tlFactory = Pylon::CTlFactory::GetInstance();
// Pylon::CInstantCameraArray cameras(2);
cameras.Initialize(2);
try { try {
camera0 = new Pylon::CInstantCamera(); cameras[0].Attach( tlFactory.CreateDevice( layout.devices[0].c_str() ) );
Pylon::String_t fname(layout.devices[0].c_str()); cameras[1].Attach( tlFactory.CreateDevice( layout.devices[1].c_str() ) );
Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateDevice(fname); valid = cameras[0].IsOpen();
camera0->Attach(pDevice); valid = valid & cameras[1].IsOpen();
camera0->Open();
valid = camera0->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();
@ -263,21 +230,6 @@ bool DualcamWrapper::openCameras(std::string &message) {
return valid; return valid;
} }
resetCamera(0); resetCamera(0);
try {
camera1 = new Pylon::CInstantCamera();
Pylon::String_t fname(layout.devices[1].c_str());
Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateDevice(fname);
camera1->Attach(pDevice);
camera1->Open();
valid = valid & camera1->IsOpen();
message = "Successfully opened camera!";
} catch (const Pylon::GenericException &e) {
message = e.GetDescription();
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
valid = false;
return valid;
}
resetCamera(1); resetCamera(1);
return valid; return valid;
@ -286,42 +238,25 @@ bool DualcamWrapper::openCameras(std::string &message) {
void DualcamWrapper::closeCameras() { void DualcamWrapper::closeCameras() {
qDebug() << "Close cameras!"; qDebug() << "Close cameras!";
if (camera0->IsOpen()) { if (cameras[0].IsOpen()) {
try { cameras[0].Close();
camera0->Close();
valid = false;
delete camera0;
camera0 = nullptr;
} catch (const Pylon::GenericException &e) {
qWarning() << "An exception occurred." << e.GetDescription();
} }
if (cameras[1].IsOpen()) {
cameras[1].Close();
} }
if (camera1->IsOpen()) {
try {
camera1->Close();
valid = false; valid = false;
delete camera1;
camera1 = nullptr;
} catch (const Pylon::GenericException &e) {
qWarning() << "An exception occurred." << e.GetDescription();
}
}
} }
Pylon::CInstantCameraArray &DualcamWrapper::getCameraArray() {
Pylon::CInstantCamera *DualcamWrapper::getCamera(int camindex) { return cameras;
if (camindex == 0) {
return camera0;
} else {
return camera1;
}
} }
// Pylon::CInstantCamera DualcamWrapper::getCamera(int camindex) {
// return this.cameras[camindex];
// }
GenApi::INodeMap& DualcamWrapper::getNodemap(int camindex){ GenApi::INodeMap& DualcamWrapper::getNodemap(int camindex){
GenApi::INodeMap &nodemap = camera0->GetNodeMap();; GenApi::INodeMap &nodemap = cameras[camindex].GetNodeMap();
if (camindex == 1){
nodemap = camera1->GetNodeMap();
}
return nodemap; return nodemap;
} }

View File

@ -15,28 +15,28 @@ public:
DualcamWrapper(const CameraLayout &layout); DualcamWrapper(const CameraLayout &layout);
~DualcamWrapper(); ~DualcamWrapper();
ImageSettings getImageSettings(int camindex); ImageSettings getImageSettings(int camindex);
bool isOpen(); bool isOpen();
void terminate(); void terminate();
bool openCameras(std::string &message); bool openCameras(std::string &message);
void closeCameras(); void closeCameras();
bool grabFrame(MyImage &img, int camindex=0); bool grabFrame(MyImage &img, int camindex=0);
bool frameRate(uint framerate); bool frameRate(uint framerate, int camindex=-1);
double frameRate(); double frameRate(int camindex);
double maxFrameRate(); double maxFrameRate(int camindex);
double exposureTime(); double exposureTime(int camindex);
bool exposureTime(double exposure_time, int camindex=-1); bool exposureTime(double exposure_time, int camindex=-1);
double gain(); double gain(int camindex);
bool gain(double gain_db, int camindex=-1); bool gain(double gain_db, int camindex=-1);
Pylon::CInstantCamera *getCamera(int camindex); Pylon::CInstantCameraArray &getCameraArray();
// Pylon::CInstantCamera getCamera(int camindex);
private: private:
void resetCamera(int camindex); void resetCamera(int camindex);
Pylon::CInstantCameraArray cameras;
GenApi::INodeMap& getNodemap(int camindex); GenApi::INodeMap& getNodemap(int camindex);
std::vector<Pylon::CInstantCamera*> cameras;
Pylon::CInstantCamera *camera0, *camera1;
bool valid, withLayout; bool valid, withLayout;
std::string fullName;
CameraLayout layout; CameraLayout layout;
}; };