From 8da179cd6fe329521bd2ec1433715840e2d4f64c Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Tue, 8 Jul 2025 15:30:16 +0200 Subject: [PATCH] support x and y offset settings --- minimal_pylon.cpp | 58 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/minimal_pylon.cpp b/minimal_pylon.cpp index 89e3561..2091a23 100644 --- a/minimal_pylon.cpp +++ b/minimal_pylon.cpp @@ -34,6 +34,18 @@ typedef high_resolution_clock Time; typedef milliseconds ms; typedef duration fsec; +uint32_t sensorHeight(CInstantCamera &camera) { + CIntegerParameter maxheight( camera.GetNodeMap(), "SensorHeight" ); + return maxheight.GetValue(); +} + +uint32_t sensorWidth(CInstantCamera &camera) { + CIntegerParameter maxwidth( camera.GetNodeMap(), "SensorWidth" ); + return maxwidth.IsValid() && maxwidth.IsReadable() ? maxwidth.GetValue() : 0; +} + +//void exposureTime(double exposure_time); + int main( int argc, char* argv[] ) { uint32_t frameCount = 100; size_t maxCameras = 1; @@ -44,6 +56,8 @@ int main( int argc, char* argv[] ) { uint32_t quality = 50; int cWidth = 2000; //2592; int cHeight = 2000; //2048; + int xOffset = 0; + int yOffset = 0; int camIndex = 0; string errorMessage = ""; String_t filename = "_TestVideo.mp4"; @@ -56,6 +70,8 @@ int main( int argc, char* argv[] ) { << "\t --help|? \t this help\n" << "\t --width|-w \t the image width in pixel, defaults to 2000\n" << "\t --height|-h \t the image height in pixel, defaults to 2000\n" + << "\t --xoffs|-x \t image x offset in pixel, defaults to 0\n" + << "\t --yoffs|-y \t image y-offset in pixel, defaults to 0\n" << "\t --cameras|-c \t the desired number of cameras to grab at the same time, defaults to 1\n" << "\t --framecount|-n \t the number of frames, defaults to 100\n" << "\t --quality|-q \t the qualtiy of the compression (0 < q <= 100), defaults to 50\n" @@ -78,6 +94,12 @@ int main( int argc, char* argv[] ) { if ((arg == "--height" || arg == "-h") && i + 1 < argc) { cHeight = std::atoi(argv[++i]); } + if ((arg == "--xoffs" || arg == "-x") && i + 1 < argc) { + xOffset = std::atoi(argv[++i]); + } + if ((arg == "--yoffs" || arg == "-y") && i + 1 < argc) { + yOffset = std::atoi(argv[++i]); + } if ((arg == "--index" || arg == "-i") && i + 1 < argc) { camIndex = std::atoi(argv[++i]); } @@ -91,18 +113,15 @@ int main( int argc, char* argv[] ) { if ((arg == "--outfile" || arg == "-o") && i + 1 < argc) { filename = Pylon::String_t(argv[++i]); } - } PylonInitialize(); - try { - // Check if CVideoWriter is supported and all DLLs are available. if (!CVideoWriter::IsSupported()) { - cout << "VideoWriter is not supported at the moment. Please install the pylon Supplementary Package for MPEG-4 which is available on the Basler website." << endl; - // Releases all pylon resources. + cout << "VideoWriter is not supported at the moment!" + << " Please install the pylon Supplementary Package" + << " for MPEG-4 which is available on the Basler website." << endl; PylonTerminate(); - // Return with error code 1. return 1; } @@ -123,16 +142,28 @@ int main( int argc, char* argv[] ) { cameras[i].Open(); cout << "Using device " << cameras[i].GetDeviceInfo().GetModelName() << endl; - CIntegerParameter width( cameras[i].GetNodeMap(), "Width" ); - CIntegerParameter height( cameras[i].GetNodeMap(), "Height" ); - CEnumParameter pixelFormat( cameras[i].GetNodeMap(), "PixelFormat" ); - CEnumParameter trigmode( cameras[i].GetNodeMap(), "TriggerMode"); + uint32_t mw = sensorWidth(cameras[i]); + uint32_t mh = sensorHeight(cameras[i]); + uint32_t maxXOffs = mw - cWidth; + uint32_t maxYOffs = mh - cHeight; + xOffset = xOffset <= maxXOffs ? xOffset : maxXOffs; + yOffset = yOffset <= maxYOffs ? yOffset : maxYOffs; + + INodeMap& nodemap = cameras[i].GetNodeMap(); + CIntegerParameter width( nodemap, "Width" ); + CIntegerParameter height( nodemap, "Height" ); + CIntegerParameter offsetX( nodemap, "OffsetX" ); + CIntegerParameter offsetY( nodemap, "OffsetY" ); + CEnumParameter pixelFormat( nodemap, "PixelFormat" ); + CEnumParameter trigmode( nodemap, "TriggerMode"); + CEnumParameter trigsource( nodemap, "TriggerSource"); + trigmode.TrySetValue( "On" ); - CEnumParameter trigsource( cameras[i].GetNodeMap(), "TriggerSource"); trigsource.TrySetValue( "Software" ); width.TrySetValue( cWidth, IntegerValueCorrection_Nearest ); height.TrySetValue( cHeight, IntegerValueCorrection_Nearest ); - + offsetX.TrySetValue( xOffset, IntegerValueCorrection_Nearest ); + offsetY.TrySetValue( yOffset, IntegerValueCorrection_Nearest ); } CIntegerParameter width( cameras[0].GetNodeMap(), "Width" ); @@ -140,7 +171,6 @@ int main( int argc, char* argv[] ) { CEnumParameter pixelFormat( cameras[0].GetNodeMap(), "PixelFormat" ); CPixelTypeMapper pixelTypeMapper( &pixelFormat ); EPixelType pixelType = pixelTypeMapper.GetPylonPixelTypeFromNodeValue( pixelFormat.GetIntValue() ); - CGrabResultPtr frames[camCount]; for (int i =0; i < camCount; i++) { CGrabResultPtr ptrGrabResult; @@ -210,7 +240,7 @@ int main( int argc, char* argv[] ) { if ( camCount > 1 ) { leftImage.AttachGrabResultBuffer( frames[0] ); rightImage.AttachGrabResultBuffer( frames[1] ); - StitchImage::StitchToRight(leftImage, rightImage, &stitchedImage, errorMessage); + StitchImage::StitchToRight( leftImage, rightImage, &stitchedImage, errorMessage ); videoWriter.Add( stitchedImage ); } else { videoWriter.Add( frames[0] );