#include "pylonrecorder.h" PylonRecorder::PylonRecorder(): valid(false) { Pylon::PylonInitialize(); camera = new Pylon::CInstantCamera(); } PylonRecorder::~PylonRecorder() { Pylon::PylonTerminate(); } void PylonRecorder::terminate() { try { //Pylon::PylonTerminate(); } catch (const Pylon::GenericException &e) { std::cerr << e.GetDescription() << std::endl; } } bool PylonRecorder::isOpen() { return valid; } ImageSettings PylonRecorder::getImageSettings() { ImageSettings settings; if (valid) { Pylon::CIntegerParameter width( camera->GetNodeMap(), "Width"); Pylon::CIntegerParameter height( camera->GetNodeMap(), "Height"); Pylon::CEnumParameter pixelFormat( camera->GetNodeMap(), "PixelFormat"); settings.width = width.GetValue(); settings.height = height.GetValue(); } return settings; } Pylon::CGrabResultPtr PylonRecorder::grabFrame() { Pylon::CPylonImage img; Pylon::CGrabResultPtr ptrGrabResult; if (valid) { camera->StartGrabbing(); camera->RetrieveResult( 5000, ptrGrabResult, Pylon::TimeoutHandling_ThrowException); camera->StopGrabbing(); } return ptrGrabResult; } bool PylonRecorder::openCamera(std::string &message) { try { camera->Attach(Pylon::CTlFactory::GetInstance().CreateFirstDevice()); camera->Open(); valid = true; 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; } void PylonRecorder::closeCamera() { if (camera->IsOpen()) { try { camera->Close(); valid = false; } catch (const Pylon::GenericException &e) { std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl; } } }