|
|
|
|
@@ -1,29 +1,29 @@
|
|
|
|
|
#include "pylonwrapper.h"
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
// camera = new Pylon::CInstantCamera();
|
|
|
|
|
// std::cerr << "Wrapper:camera is open" << camera->IsOpen() << std::endl;
|
|
|
|
|
// std::cerr << "Wrapper:is valid" << valid << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PylonWrapper::~PylonWrapper() {
|
|
|
|
|
std::cerr << "wrapper destructor" << std::endl;
|
|
|
|
|
qDebug() << "wrapper destructor";
|
|
|
|
|
if (camera != nullptr){
|
|
|
|
|
std::cerr << "check camera!" << std::endl;
|
|
|
|
|
if (camera->IsOpen()) {
|
|
|
|
|
std::cerr << "close camera!" << std::endl;
|
|
|
|
|
qDebug() << "Camera open, closing it!";
|
|
|
|
|
camera->Close();
|
|
|
|
|
// std::cerr << "terminate pylon" << std::endl;
|
|
|
|
|
// terminate();
|
|
|
|
|
}
|
|
|
|
|
std::cerr << "delete camera!" << std::endl;
|
|
|
|
|
|
|
|
|
|
delete camera;
|
|
|
|
|
camera = nullptr;
|
|
|
|
|
}
|
|
|
|
|
std::cerr << "wrapper: deleted camera" << std::endl;
|
|
|
|
|
qDebug() << "Successfully deleted camera";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PylonWrapper::terminate() {
|
|
|
|
|
@@ -141,36 +141,71 @@ ImageSettings PylonWrapper::getImageSettings() {
|
|
|
|
|
bool PylonWrapper::grabFrame(MyImage &img) {
|
|
|
|
|
Pylon::CGrabResultPtr frame;
|
|
|
|
|
if (valid) {
|
|
|
|
|
camera->StartGrabbing();
|
|
|
|
|
camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
|
|
|
|
camera->StopGrabbing();
|
|
|
|
|
}
|
|
|
|
|
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->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
|
|
|
|
camera->StopGrabbing();
|
|
|
|
|
}
|
|
|
|
|
img.setFrame(frame);
|
|
|
|
|
return frame.IsValid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PylonWrapper::openCamera(std::string &message) {
|
|
|
|
|
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) {
|
|
|
|
|
qDebug() << "opening camera";
|
|
|
|
|
try {
|
|
|
|
|
camera = new Pylon::CInstantCamera();
|
|
|
|
|
|
|
|
|
|
// Pylon::CInstantCamera camera( pTl->CreateDevice( lstDevices[0] );
|
|
|
|
|
// Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateFirstDevice();
|
|
|
|
|
Pylon::String_t fname(fullName.c_str());
|
|
|
|
|
Pylon::IPylonDevice *pDevice = Pylon::CTlFactory::GetInstance().CreateDevice(fname);
|
|
|
|
|
camera->Attach(pDevice);
|
|
|
|
|
camera->Open();
|
|
|
|
|
resetCamera();
|
|
|
|
|
valid = camera->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;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PylonWrapper::closeCamera() {
|
|
|
|
|
std::cerr << "camera close !" << std::endl;
|
|
|
|
|
qDebug() << "Close camera!";
|
|
|
|
|
if (camera->IsOpen()) {
|
|
|
|
|
try {
|
|
|
|
|
camera->Close();
|
|
|
|
|
@@ -178,9 +213,10 @@ void PylonWrapper::closeCamera() {
|
|
|
|
|
delete camera;
|
|
|
|
|
camera = nullptr;
|
|
|
|
|
} 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() {
|
|
|
|
|
|