From 6916899620b8d4cadaf56319cceccca8eb67a949 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Wed, 12 Mar 2025 09:53:12 +0100 Subject: [PATCH] [wrapper] add sensor Size functions --- dualcamwrapper.cpp | 35 +++++++++++++++++++++++++++++------ dualcamwrapper.h | 2 ++ pylonwrapper.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- pylonwrapper.h | 3 +++ 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/dualcamwrapper.cpp b/dualcamwrapper.cpp index f7f28d9..37ff7d8 100644 --- a/dualcamwrapper.cpp +++ b/dualcamwrapper.cpp @@ -117,6 +117,29 @@ bool DualcamWrapper::exposureTime(double exposure_time, int camindex) { return false; } +uint32_t DualcamWrapper::sensorWidth(int camindex) { + qDebug() << "Reading SensorWidth from camera " << camindex; + assert(camindex >= 0 && camindex < 2); + uint32_t width = -1; + if (valid) { + GenApi::INodeMap &nodemap = getNodemap(camindex); + Pylon::CIntegerParameter pwidth( nodemap, "SensorWidth" ); + width = (uint32_t)pwidth.GetValue(); + } + return width; +} + +uint32_t DualcamWrapper::sensorHeight(int camindex) { + qDebug() << "Reading SensorHeight from camera " << camindex; + assert(camindex >= 0 && camindex < 2); + uint32_t height = -1; + if (valid) { + GenApi::INodeMap &nodemap = getNodemap(camindex); + Pylon::CIntegerParameter pheight( nodemap, "SensorHeight" ); + height = (uint32_t)pheight.GetValue(); + } + return height; +} double DualcamWrapper::gain(int camindex) { assert(camindex >= 0 && camindex < 2); @@ -207,13 +230,13 @@ void DualcamWrapper::setROI() { 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 << ")"; + GenApi::INodeMap &nodemap = getNodemap( camindex ); + uint32_t width = sensorWidth(camindex); + uint32_t height = sensorHeight(camindex); + qDebug() << "resetting camera to default ROI (" << width << ", " << height << ")"; try { - Pylon::CIntegerParameter(nodemap, "Width").SetValue(dfltWidth, false); - Pylon::CIntegerParameter(nodemap, "Height").SetValue(dfltHeight, false); + Pylon::CIntegerParameter(nodemap, "Width").SetValue(width, false); + Pylon::CIntegerParameter(nodemap, "Height").SetValue(height, false); Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(0); Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(0); } catch (const Pylon::GenericException &e) { diff --git a/dualcamwrapper.h b/dualcamwrapper.h index 284e1e8..7de977e 100644 --- a/dualcamwrapper.h +++ b/dualcamwrapper.h @@ -16,6 +16,8 @@ public: ~DualcamWrapper(); ImageSettings getImageSettings(int camindex); + uint32_t sensorWidth(int camindex); + uint32_t sensorHeight(int camindex); bool isOpen(); void terminate(); bool openCameras(std::string &message); diff --git a/pylonwrapper.cpp b/pylonwrapper.cpp index b7f92a8..bde40cd 100644 --- a/pylonwrapper.cpp +++ b/pylonwrapper.cpp @@ -157,14 +157,43 @@ bool PylonWrapper::grabFrame(MyImage &img) { camera->StartGrabbing(); camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException); camera->StopGrabbing(); + qDebug() << "grabFrame done"; } + img.setFrame(frame); return frame.IsValid(); } +uint32_t PylonWrapper::sensorWidth() { + qDebug() << "Reading SensorWidth"; + uint32_t width = -1; + if (valid) { + qDebug() << "SensorWidth available"; + GenApi::INodeMap &nodemap = camera->GetNodeMap(); + if (GenApi::IsAvailable(nodemap.GetNode("SensorWidth"))) { + Pylon::CIntegerParameter pwidth( nodemap, "SensorWidth" ); + width = (uint32_t)pwidth.GetValue(); + } + } + return width; +} + +uint32_t PylonWrapper::sensorHeight() { + qDebug() << "Reading SensorHeight"; + uint32_t height = -1; + if (valid){ + GenApi::INodeMap &nodemap = camera->GetNodeMap(); + if (GenApi::IsAvailable(nodemap.GetNode("SensorHeight"))) { + Pylon::CIntegerParameter pheight( nodemap, "SensorHeight" ); + height = (uint32_t)pheight.GetValue(); + } + } + return height; +} + void PylonWrapper::resetCamera() { - int64_t dfltWidth = 2048; - int64_t dfltHeight = 1536; + uint32_t dfltWidth = sensorWidth(); + uint32_t dfltHeight = sensorHeight(); qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")"; try { GenApi::INodeMap& nodemap = camera->GetNodeMap(); @@ -179,6 +208,7 @@ void PylonWrapper::resetCamera() { std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl; valid = false; } + qDebug() << "resetting camera to default ROI done"; } bool PylonWrapper::openCamera(std::string &message) { @@ -236,5 +266,12 @@ Pylon::CInstantCamera *PylonWrapper::getCamera() { QString PylonWrapper::userName() { GenApi::INodeMap& nodemap = camera->GetNodeMap(); QString username = Pylon::CStringParameter(nodemap, "DeviceUserID").GetValue().c_str(); + if (username.length() == 0) { + username = Pylon::CStringParameter(nodemap, "DeviceModelName").GetValue().c_str(); + } return username; +} + +QString PylonWrapper::deviceName() { + return QString::fromStdString(fullName); } \ No newline at end of file diff --git a/pylonwrapper.h b/pylonwrapper.h index f1c74fe..29698e0 100644 --- a/pylonwrapper.h +++ b/pylonwrapper.h @@ -27,9 +27,12 @@ public: bool exposureTime(double exposure_time); double gain(); bool gain(double gain_db); + uint32_t sensorHeight(); + uint32_t sensorWidth(); QString userName(); Pylon::CInstantCamera *getCamera(); void resetCamera(); + QString deviceName(); private: Pylon::CInstantCamera *camera;