The following sections list the code samples that are part of the pylon SDK.
The pylon samples can be found under <SDK ROOT>\Samples. There is a GNU make file available for each sample.
Include Files Used by Samples
The following include files are used by the samples shown below.
CameraEventPrinter.h
#ifndef INCLUDED_CAMERAEVENTPRINTER_H_4683453
#define INCLUDED_CAMERAEVENTPRINTER_H_4683453
#include <iostream>
namespace Pylon
{
class CInstantCamera;
class CCameraEventPrinter : public CCameraEventHandler
{
public:
virtual void OnCameraEvent( CInstantCamera& camera, intptr_t userProvidedId, GenApi::INode* pNode)
{
std::cout << "OnCameraEvent event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
std::cout << "User provided ID: " << userProvidedId << std::endl;
std::cout << "Event data node name: " << pNode->GetName() << std::endl;
if ( ptrValue.IsValid() )
{
std::cout << "Event node data: " << ptrValue->ToString() << std::endl;
}
std::cout << std::endl;
}
};
}
#endif
ConfigurationEventPrinter.h
#ifndef INCLUDED_CONFIGURATIONEVENTPRINTER_H_663006
#define INCLUDED_CONFIGURATIONEVENTPRINTER_H_663006
#include <iostream>
namespace Pylon
{
class CInstantCamera;
class CConfigurationEventPrinter : public CConfigurationEventHandler
{
public:
void OnAttach( CInstantCamera& )
{
std::cout << "OnAttach event" << std::endl;
}
void OnAttached( CInstantCamera& camera)
{
std::cout << "OnAttached event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnOpen( CInstantCamera& camera)
{
std::cout << "OnOpen event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnOpened( CInstantCamera& camera)
{
std::cout << "OnOpened event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnGrabStart( CInstantCamera& camera)
{
std::cout << "OnGrabStart event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnGrabStarted( CInstantCamera& camera)
{
std::cout << "OnGrabStarted event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnGrabStop( CInstantCamera& camera)
{
std::cout << "OnGrabStop event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnGrabStopped( CInstantCamera& camera)
{
std::cout << "OnGrabStopped event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnClose( CInstantCamera& camera)
{
std::cout << "OnClose event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnClosed( CInstantCamera& camera)
{
std::cout << "OnClosed event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnDestroy( CInstantCamera& camera)
{
std::cout << "OnDestroy event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnDestroyed( CInstantCamera& )
{
std::cout << "OnDestroyed event" << std::endl;
}
void OnDetach( CInstantCamera& camera)
{
std::cout << "OnDetach event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnDetached( CInstantCamera& camera)
{
std::cout << "OnDetached event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
void OnGrabError( CInstantCamera& camera,
const String_t errorMessage)
{
std::cout << "OnGrabError event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
std::cout << "Error Message: " << errorMessage << std::endl;
}
void OnCameraDeviceRemoved( CInstantCamera& camera)
{
std::cout << "OnCameraDeviceRemoved event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
}
};
}
#endif
ImageEventPrinter.h
#ifndef INCLUDED_IMAGEEVENTPRINTER_H_7884943
#define INCLUDED_IMAGEEVENTPRINTER_H_7884943
#include <iostream>
namespace Pylon
{
class CInstantCamera;
class CImageEventPrinter : public CImageEventHandler
{
public:
virtual void OnImagesSkipped( CInstantCamera& camera, size_t countOfSkippedImages)
{
std::cout << "OnImagesSkipped event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
std::cout << countOfSkippedImages << " images have been skipped." << std::endl;
std::cout << std::endl;
}
virtual void OnImageGrabbed( CInstantCamera& camera, const CGrabResultPtr& ptrGrabResult)
{
std::cout << "OnImageGrabbed event for device " << camera.GetDeviceInfo().GetModelName() << std::endl;
if (ptrGrabResult->GrabSucceeded())
{
std::cout << "SizeX: " << ptrGrabResult->GetWidth() << std::endl;
std::cout << "SizeY: " << ptrGrabResult->GetHeight() << std::endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
std::cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << std::endl;
std::cout << std::endl;
}
else
{
std::cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << std::endl;
}
}
};
}
#endif
PixelFormatAndAoiConfiguration.h
#ifndef INCLUDED_PIXELFORMATANDAOICONFIGURATION_H_00104928
#define INCLUDED_PIXELFORMATANDAOICONFIGURATION_H_00104928
namespace Pylon
{
class CInstantCamera;
}
{
public:
{
try
{
using namespace GenApi;
const CIntegerPtr offsetX = control.GetNode(
"OffsetX");
const CIntegerPtr offsetY = control.GetNode(
"OffsetY");
{
offsetX->SetValue(offsetX->GetMin());
}
{
offsetY->SetValue(offsetY->GetMin());
}
width->SetValue(width->GetMax());
height->SetValue(height->GetMax());
}
catch (const GenericException& e)
{
throw RUNTIME_EXCEPTION(
"Could not apply configuration. const GenericException caught in OnOpened method msg=%hs", e.what());
}
}
};
#endif
SampleImageCreator.h
#ifndef INCLUDED_SAMPLEIMAGECREATOR_H_2792867
#define INCLUDED_SAMPLEIMAGECREATOR_H_2792867
namespace SampleImageCreator
{
{
using namespace Pylon;
{
{0, 28, 50}, {0, 42, 75}, {0, 56, 100}, {0, 70, 125}, {0, 84, 150},
{0, 50, 0}, {0, 100, 0}, {0, 150, 0}, {0, 200, 0}, {0, 250, 0},
{50, 0, 0}, {100, 0, 0}, {150, 0, 0}, {200, 0, 0}, {250, 0, 0}
};
uint32_t numColors = sizeof( palette) / sizeof( palette[0]);
const double cX = -0.735;
const double cY = 0.11;
const double cMaxX = 1.6;
const double cMinX = -1.6;
const double cMaxY = 1;
const double cMinY = -1;
const uint32_t cMaxIterations = 50;
for ( uint32_t pixelY = 0; pixelY < height; ++pixelY )
{
for ( uint32_t pixelX = 0; pixelX < width; ++pixelX, ++pCurrentPixel )
{
long double x = ((cMaxX-cMinX) / width) * pixelX + cMinX;
long double y = cMaxY - pixelY * ((cMaxY-cMinY) / height);
long double xd = 0;
long double yd = 0;
int i = 0;
for(; i < cMaxIterations; ++i)
{
xd = x * x - y * y + cX;
yd = 2 *x * y + cY;
x = xd;
y = yd;
if ( (x * x + y * y) > 4 )
{
break;
}
}
if ( i >= cMaxIterations)
{
pCurrentPixel = palette[0];
}
else
{
pCurrentPixel = palette[ i % numColors ];
}
}
}
if ( juliaFractal.GetPixelType() != pixelType)
{
}
return juliaFractal;
}
{
using namespace Pylon;
{
{0, 28, 50}, {0, 42, 75}, {0, 56, 100}, {0, 70, 125}, {0, 84, 150},
{0, 50, 0}, {0, 100, 0}, {0, 150, 0}, {0, 200, 0}, {0, 250, 0},
{50, 0, 0}, {100, 0, 0}, {150, 0, 0}, {200, 0, 0}, {250, 0, 0}
};
uint32_t numColors = sizeof( palette) / sizeof( palette[0]);
const double cMaxX = 1.0;
const double cMinX = -2.0;
const double cMaxY = 1.2;
const double cMinY = -1.2;
const uint32_t cMaxIterations = 50;
for ( uint32_t pixelY = 0; pixelY < height; ++pixelY )
{
for ( uint32_t pixelX = 0; pixelX < width; ++pixelX, ++pCurrentPixel )
{
long double xStart = ((cMaxX-cMinX) / width) * pixelX + cMinX;
long double yStart = cMaxY - pixelY * ((cMaxY-cMinY) / height);
long double x = xStart;
long double y = yStart;
long double xd =0;
long double yd =0;
int i = 0;
for(; i < cMaxIterations; ++i)
{
xd = x * x - y * y + xStart;
yd = 2 *x * y + yStart;
x = xd;
y = yd;
if ( (x * x + y * y) > 4 )
{
break;
}
}
if ( i >= cMaxIterations)
{
pCurrentPixel = palette[0];
}
else
{
pCurrentPixel = palette[ i % numColors ];
}
}
}
if ( mandelbrotFractal.GetPixelType() != pixelType)
{
}
return mandelbrotFractal;
}
}
#endif
DeviceRemovalHandling
#include "../include/ConfigurationEventPrinter.h"
using namespace Pylon;
using namespace std;
class CHeartbeatHelper
{
public:
: m_pHeartbeatTimeout(NULL)
{
m_pHeartbeatTimeout = camera.
GetTLNodeMap().GetNode(
"HeartbeatTimeout");
}
bool SetValue(int64_t NewValue)
{
if (!m_pHeartbeatTimeout.IsValid())
return false;
int64_t correctedValue = NewValue - (NewValue % m_pHeartbeatTimeout->GetInc());
m_pHeartbeatTimeout->SetValue(correctedValue);
return true;
}
bool SetMax()
{
if (!m_pHeartbeatTimeout.IsValid())
return false;
int64_t maxVal = m_pHeartbeatTimeout->GetMax();
return SetValue(maxVal);
}
protected:
};
{
public:
{
cout << endl << endl;
cout << "CSampleConfigurationEventHandler::OnCameraDeviceRemoved called." << std::endl;
}
};
static const uint32_t c_loopCounterInitialValue = 20 * 4;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
int loopCount = 0;
cout << endl;
loopCount = c_loopCounterInitialValue;
cout << endl << "Please disconnect the device (timeout " << loopCount / 4 << "s) " << endl;
CHeartbeatHelper heartbeatHelper(camera);
heartbeatHelper.SetValue(1000);
try
{
while ( loopCount > 0)
{
if (--loopCount % 4 == 0)
{
cout << ".";
cout.flush();
}
width->SetValue( width->GetMax() - (width->GetInc() * (loopCount % 2)));
}
}
catch (const GenericException &e)
{
{
cout << endl;
cout << "The camera has been removed from the PC." << endl;
cout << "The camera device removal triggered an exception:" << endl
<< e.GetDescription() << endl;
}
else
{
throw;
}
}
cout << endl << "Timeout expired" << endl;
loopCount = c_loopCounterInitialValue;
cout << endl << "Please connect the same device to the PC again (timeout " << loopCount / 4 << "s) " << endl;
filter.push_back( info);
for ( ; loopCount > 0; --loopCount)
{
if ( loopCount % 4 == 0)
{
cout << ".";
cout.flush();
}
{
cout << endl << endl;
break;
}
}
{
cout << endl;
cout << endl;
}
else
{
cout << endl << "Timeout expired." << endl;
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 100;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
{
{
cout <<
"SizeX: " << ptrGrabResult->
GetWidth() << endl;
cout <<
"SizeY: " << ptrGrabResult->
GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->
GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
else
{
}
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_CameraEvents
#include "../include/ConfigurationEventPrinter.h"
#include "../include/CameraEventPrinter.h"
using namespace Pylon;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
typedef CBasler1394CameraEventHandler CameraEventHandler_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#else
#error camera type is not specified. For example, define USE_GIGE for using GigE cameras
#endif
using namespace std;
enum MyEvents
{
eMyExposureEndEvent = 100,
eMyEventOverrunEvent = 200
};
static const uint32_t c_countOfImagesToGrab = 5;
class CSampleCameraEventHandler : public CameraEventHandler_t
{
public:
virtual void OnCameraEvent( Camera_t& camera, intptr_t userProvidedId, GenApi::INode* )
{
std::cout << std::endl;
switch ( userProvidedId )
{
case eMyExposureEndEvent:
cout << "Exposure End event. FrameID: " << camera.ExposureEndEventFrameID.GetValue() << " Timestamp: " << camera.ExposureEndEventTimestamp.GetValue() << std::endl << std::endl;
break;
case eMyEventOverrunEvent:
cout << "Event Overrun event. FrameID: " << camera.EventOverrunEventFrameID.GetValue() << " Timestamp: " << camera.EventOverrunEventTimestamp.GetValue() << std::endl << std::endl;
break;
}
}
};
{
public:
{
cout << "CSampleImageEventHandler::OnImageGrabbed called." << std::endl;
cout << std::endl;
cout << std::endl;
}
};
int main(int argc, char* argv[])
{
int exitCode = 0;
CSampleCameraEventHandler* pHandler1 = new CSampleCameraEventHandler;
CCameraEventPrinter* pHandler2 = new CCameraEventPrinter;
try
{
camera.GrabCameraEvents = true;
camera.Open();
{
}
camera.StartGrabbing( c_countOfImagesToGrab);
while ( camera.IsGrabbing())
{
{
camera.ExecuteSoftwareTrigger();
}
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
delete pHandler1;
delete pHandler2;
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_CameraEvents_Usb
#include "../include/ConfigurationEventPrinter.h"
#include "../include/CameraEventPrinter.h"
using namespace Pylon;
#if defined( USE_USB )
using namespace Basler_UsbCameraParams;
#else
#error Camera type is not specified. For example, define USE_USB for using USB cameras.
#endif
using namespace std;
enum MyEvents
{
eMyExposureEndEvent = 100
};
static const uint32_t c_countOfImagesToGrab = 5;
class CSampleCameraEventHandler : public CameraEventHandler_t
{
public:
virtual void OnCameraEvent( Camera_t& camera, intptr_t userProvidedId, GenApi::INode* )
{
std::cout << std::endl;
switch ( userProvidedId )
{
case eMyExposureEndEvent:
cout << "Exposure End event. FrameID: " << camera.EventExposureEndFrameID.GetValue() << " Timestamp: " << camera.EventExposureEndTimestamp.GetValue() << std::endl << std::endl;
break;
}
}
};
{
public:
{
cout << "CSampleImageEventHandler::OnImageGrabbed called." << std::endl;
cout << std::endl;
cout << std::endl;
}
};
int main(int argc, char* argv[])
{
int exitCode = 0;
CSampleCameraEventHandler* pHandler1 = new CSampleCameraEventHandler;
CCameraEventPrinter* pHandler2 = new CCameraEventPrinter;
try
{
camera.GrabCameraEvents = true;
camera.Open();
{
}
camera.StartGrabbing( c_countOfImagesToGrab);
while ( camera.IsGrabbing())
{
{
camera.ExecuteSoftwareTrigger();
}
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
delete pHandler1;
delete pHandler2;
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_ChunkImage
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
typedef Pylon::CBasler1394ImageEventHandler ImageEventHandler_t;
typedef Pylon::CBasler1394GrabResultPtr GrabResultPtr_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#elif defined( USE_USB )
using namespace Basler_UsbCameraParams;
#else
#error Camera type is not specified. For example, define USE_GIGE for using GigE cameras.
#endif
using namespace std;
class CSampleImageEventHandler : public ImageEventHandler_t
{
public:
virtual void OnImageGrabbed( Camera_t& camera, const GrabResultPtr_t& ptrGrabResult)
{
GenApi::CIntegerPtr chunkTimestamp( ptrGrabResult->GetChunkDataNodeMap().GetNode(
"ChunkTimestamp"));
cout << "OnImageGrabbed: TimeStamp (Result) accessed via node map: " << chunkTimestamp->GetValue() << endl;
cout << "OnImageGrabbed: TimeStamp (Result) accessed via result member: " << ptrGrabResult->ChunkTimestamp.GetValue() << endl;
}
};
static const uint32_t c_countOfImagesToGrab = 5;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
{
camera.ChunkModeActive.SetValue(true);
}
else
{
}
camera.ChunkEnable.SetValue(true);
#ifndef USE_USB // USB camera devices provide generic counters. An explicit FrameCounter value is not provided by USB camera devices.
camera.ChunkEnable.SetValue(true);
#endif
camera.ChunkEnable.SetValue(true);
camera.StartGrabbing( c_countOfImagesToGrab);
GrabResultPtr_t ptrGrabResult;
while( camera.IsGrabbing())
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
cout << "GrabSucceeded: " << ptrGrabResult->GrabSucceeded() << endl;
cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl;
{
}
if (ptrGrabResult->HasCRC() && ptrGrabResult->CheckCRC() == false)
{
}
cout << "TimeStamp (Result): " << ptrGrabResult->ChunkTimestamp.GetValue() << endl;
#ifndef USE_USB // USB camera devices provide generic counters. An explicit FrameCounter value is not provided by USB camera devices.
cout << "FrameCounter (Result): " << ptrGrabResult->ChunkFramecounter.GetValue() << endl;
#endif
cout << endl;
}
camera.ChunkModeActive.SetValue(false);
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_MultiCast
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
#include "../include/ConfigurationEventPrinter.h"
#include "../include/ImageEventPrinter.h"
#if defined(PYLON_WIN_BUILD)
# include <conio.h>
#elif defined(PYLON_UNIX_BUILD)
# include <stdio.h>
# include <termios.h>
# include <unistd.h>
# include <fcntl.h>
#endif
using namespace Basler_GigECameraParams;
using namespace Basler_GigEStreamParams;
using namespace Pylon;
#ifndef USE_GIGE
#error This example is usable for GigE cameras only.
#endif
using namespace std;
static const uint32_t c_countOfImagesToGrab = 100;
bool KeyPressed(void)
{
#if defined(PYLON_WIN_BUILD)
return _kbhit() != 0;
#elif defined(PYLON_UNIX_BUILD)
struct termios savedTermios;
int savedFL;
struct termios termios;
int ch;
tcgetattr(STDIN_FILENO, &savedTermios);
savedFL = fcntl(STDIN_FILENO, F_GETFL, 0);
termios = savedTermios;
termios.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &termios);
fcntl(STDIN_FILENO, F_SETFL, savedFL | O_NONBLOCK);
ch = getchar();
fcntl(STDIN_FILENO, F_SETFL, savedFL);
tcsetattr(STDIN_FILENO, TCSANOW, &savedTermios);
if (ch != EOF)
{
ungetc(ch, stdin);
}
return ch != EOF;
#endif
}
int main(int argc, char* argv[])
{
int exitCode = 0;
bool monitorMode = false;
{
char key;
cout << "Start multicast sample in (c)ontrol or in (m)onitor mode? (c/m) ";
do
cin.get(key);
while ( (key != 'c') && (key != 'm') && (key != 'C') && (key != 'M'));
monitorMode = (key == 'm') || (key == 'M');
}
while(KeyPressed())
{ getchar(); }
try
{
if ( monitorMode)
{
}
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
if ( monitorMode)
{
camera.MonitorModeActive = true;
camera.Open();
if (camera.GetStreamGrabberParams().DestinationAddr.GetValue() != "0.0.0.0" &&
camera.GetStreamGrabberParams().DestinationPort.GetValue() != 0)
{
camera.StartGrabbing( c_countOfImagesToGrab);
} else
{
cerr << endl << "Failed to open stream grabber (monitor mode): The acquisition is not yet started by the controlling application." << endl;
cerr << endl << "Start the controlling application before starting the monitor application" << endl;
}
}
else
{
camera.Open();
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.StartGrabbing();
}
while( !KeyPressed() && camera.IsGrabbing())
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cin.ignore(cin.rdbuf()->in_avail());
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_MultipleCameras
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 10;
static const size_t c_maxCamerasToUse = 2;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
{
}
for ( size_t i = 0; i < cameras.GetSize(); ++i)
{
cameras[ i ].Attach( tlFactory.
CreateDevice( devices[ i ]));
cout << "Using device " << cameras[ i ].GetDeviceInfo().GetModelName() << endl;
}
cameras.StartGrabbing();
for( int i = 0; i < c_countOfImagesToGrab && cameras.IsGrabbing(); ++i)
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(cameraContextValue, ptrGrabResult);
#endif
cout << "Camera " << cameraContextValue << ": " << cameras[ cameraContextValue ].GetDeviceInfo().GetModelName() << endl;
cout <<
"GrabSucceeded: " << ptrGrabResult->
GrabSucceeded() << endl;
cout <<
"SizeX: " << ptrGrabResult->
GetWidth() << endl;
cout <<
"SizeY: " << ptrGrabResult->
GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->
GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_Strategies
#include "../include/ConfigurationEventPrinter.h"
#include "../include/ImageEventPrinter.h"
using namespace Pylon;
using namespace std;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.MaxNumBuffer = 15;
camera.Open();
if (camera.CanWaitForFrameTriggerReady())
{
cout << "Grab using the GrabStrategy_OneByOne default strategy:" << endl << endl;
for ( int i = 0; i < 3; ++i)
{
{
camera.ExecuteSoftwareTrigger();
}
}
if ( camera.GetGrabResultWaitObject().Wait( 0))
{
cout << endl << "Grab results wait in the output queue." << endl << endl;
}
int nBuffersInQueue = 0;
{
nBuffersInQueue++;
}
cout << "Retrieved " << nBuffersInQueue << " grab results from output queue." << endl << endl;
camera.StopGrabbing();
cout << endl << "Grab using strategy GrabStrategy_LatestImageOnly:" << endl << endl;
for ( int i = 0; i < 3; ++i)
{
{
camera.ExecuteSoftwareTrigger();
}
}
if ( camera.GetGrabResultWaitObject().Wait( 0))
{
cout << endl << "A grab result waits in the output queue." << endl << endl;
}
nBuffersInQueue = 0;
{
nBuffersInQueue++;
}
cout << "Retrieved " << nBuffersInQueue << " grab result from output queue." << endl << endl;
camera.StopGrabbing();
cout << endl << "Grab using strategy GrabStrategy_LatestImages:" << endl << endl;
camera.OutputQueueSize = 2;
for ( int i = 0; i < 3; ++i)
{
{
camera.ExecuteSoftwareTrigger();
}
}
if ( camera.GetGrabResultWaitObject().Wait( 0))
{
cout << endl << "Grab results wait in the output queue." << endl << endl;
}
nBuffersInQueue = 0;
{
{
}
nBuffersInQueue++;
}
cout << "Retrieved " << nBuffersInQueue << " grab results from output queue." << endl << endl;
camera.OutputQueueSize = 1;
camera.OutputQueueSize = camera.MaxNumBuffer;
camera.StopGrabbing();
if ( !camera.IsUsb())
{
cout << endl << "Grab using the GrabStrategy_UpcomingImage strategy:" << endl << endl;
if ( !camera.GetGrabResultWaitObject().Wait( 0))
{
cout << "No grab result waits in the output queue." << endl << endl;
}
camera.StopGrabbing();
}
}
else
{
cout << endl;
cout << "This sample can only be used with cameras that can be queried whether they are ready to accept the next frame trigger.";
cout << endl;
cout << endl;
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_UsingActionCommand
#include <time.h>
#include <stdlib.h>
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Basler_GigECameraParams;
using namespace Pylon;
using namespace std;
#ifndef USE_GIGE
#error This example is usable for GigE cameras only.
#endif
static const uint32_t c_maxCamerasToUse = 2;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
CTlFactory& tlFactory = CTlFactory::GetInstance();
if (pTL == NULL)
{
}
{
}
usableDeviceInfos.push_back(allDeviceInfos[0]);
const String_t subnet(static_cast<const CBaslerGigEDeviceInfo&>(allDeviceInfos[0]).GetSubnetAddress());
for (size_t i = 1; i < allDeviceInfos.size() && usableDeviceInfos.size() < c_maxCamerasToUse; ++i)
{
{
usableDeviceInfos.push_back(gigeinfo);
}
else
{
cerr << "Camera will not be used because it is in a different subnet "
<< subnet << "!" << endl;
}
}
srand((unsigned)time(NULL));
const uint32_t DeviceKey = rand();
const uint32_t GroupKey = 0x112233;
for (size_t i = 0; i < cameras.GetSize(); ++i)
{
cameras[i].Attach(tlFactory.
CreateDevice(usableDeviceInfos[i]));
cameras[i].SetCameraContext(i);
}
cameras.Open();
cout << endl << "Issuing an action command." << endl;
cameras.StartGrabbing();
const int DefaultTimeout_ms = 5000;
for (size_t i = 0; i < usableDeviceInfos.size() && cameras.IsGrabbing(); ++i)
{
intptr_t cameraIndex = ptrGrabResult->GetCameraContext();
if (ptrGrabResult->GrabSucceeded())
{
#ifdef PYLON_WIN_BUILD
if (cameraIndex <= 31)
Pylon::DisplayImage(cameraIndex, ptrGrabResult);
#endif
cout << "Camera " << cameraIndex << ": " << cameras[cameraIndex].GetDeviceInfo().GetModelName() <<
" (" << cameras[cameraIndex].GetDeviceInfo().GetIpAddress() << ")" << endl;
cout << "GrabSucceeded: " << ptrGrabResult->GrabSucceeded() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
}
else
{
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}
cameras.StopGrabbing();
cameras.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while (cin.get() != '\n');
return exitCode;
}
Grab_UsingBufferFactory
#ifdef PYLON_WIN_BUILD
#include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 5;
{
public:
MyBufferFactory()
: m_lastBufferContext(1000)
{
}
virtual ~MyBufferFactory()
{
}
virtual void AllocateBuffer( size_t bufferSize, void** pCreatedBuffer, intptr_t& bufferContext)
{
try
{
pCreatedBuffer = new uint8_t[bufferSize];
bufferContext = ++m_lastBufferContext;
cout << "Created buffer " << bufferContext << ", " << *pCreatedBuffer << endl;
}
catch (const std::exception&)
{
if (*pCreatedBuffer != NULL)
{
uint8_t* p = reinterpret_cast<uint8_t*>(pCreatedBuffer);
delete[] p;
pCreatedBuffer = NULL;
}
throw;
}
}
virtual void FreeBuffer( void* pCreatedBuffer, intptr_t bufferContext)
{
uint8_t* p = reinterpret_cast<uint8_t*>(pCreatedBuffer);
delete [] p;
cout << "Freed buffer " << bufferContext << ", " << pCreatedBuffer << endl;
}
virtual void DestroyBufferFactory()
{
delete this;
}
protected:
unsigned long m_lastBufferContext;
};
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
MyBufferFactory myFactory;
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.MaxNumBuffer = 5;
camera.StartGrabbing( c_countOfImagesToGrab);
while ( camera.IsGrabbing())
{
{
cout <<
"SizeX: " << ptrGrabResult->
GetWidth() << endl;
cout <<
"SizeY: " << ptrGrabResult->
GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->
GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
else
{
}
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_UsingExposureEndEvent
#include "../include/ConfigurationEventPrinter.h"
#include <iomanip>
#ifdef PYLON_UNIX_BUILD
# include <sys/time.h>
#endif
using namespace Pylon;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
typedef CBasler1394CameraEventHandler CameraEventHandler_t;
typedef CBasler1394ImageEventHandler ImageEventHandler_t;
typedef Pylon::CBasler1394GrabResultPtr GrabResultPtr_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#else
#error camera type is not specified. For example, define USE_GIGE for using GigE cameras
#endif
using namespace std;
enum MyEvents
{
eMyExposureEndEvent,
eMyFrameStartOvertrigger,
eMyEventOverrunEvent,
eMyImageReceivedEvent,
eMyMoveEvent,
eMyNoEvent
};
const char* MyEventNames[] =
{
"ExposureEndEvent ",
"FrameStartOvertrigger",
"EventOverrunEvent ",
"ImageReceived ",
"Move ",
"NoEvent "
};
struct LogItem
{
LogItem()
: eventType( eMyNoEvent)
, frameNumber(0)
{
}
LogItem( MyEvents event, uint32_t frameNr)
: eventType(event)
, frameNumber(frameNr)
{
#if defined(PYLON_WIN_BUILD)
QueryPerformanceCounter(&time);
#elif defined(PYLON_UNIX_BUILD)
struct timeval tv;
gettimeofday(&tv, NULL);
time = static_cast<unsigned long long>(tv.tv_sec) * 1000L + static_cast<unsigned long long>(tv.tv_usec) / 1000LL;
#endif
}
#if defined(PYLON_WIN_BUILD)
LARGE_INTEGER time;
#elif defined(PYLON_UNIX_BUILD)
unsigned long long time;
#endif
MyEvents eventType;
uint16_t frameNumber;
};
void PrintLog( const std::vector<LogItem>& aLog)
{
#if defined(PYLON_WIN_BUILD)
LARGE_INTEGER timerFrequency;
QueryPerformanceFrequency(&timerFrequency);
#endif
cout << std::endl << "Warning, the printed time values can be wrong on older PC hardware." << std::endl << std::endl;
cout << "Time [ms] " << "Event " << "FrameNumber" << std::endl;
cout << "------------ " << "--------------------- " << "-----------" << std::endl;
size_t logSize = aLog.size();
for ( size_t i = 0; i < logSize; ++i)
{
double time_ms = 0;
if ( i)
{
#if defined(PYLON_WIN_BUILD)
__int64 oldTicks = ((__int64)aLog[i-1].time.HighPart << 32) + (__int64)aLog[i-1].time.LowPart;
__int64 newTicks = ((__int64)aLog[i].time.HighPart << 32) + (__int64)aLog[i].time.LowPart;
long double timeDifference = (long double) (newTicks - oldTicks);
long double ticksPerSecond = (long double) (((__int64)timerFrequency.HighPart << 32) + (__int64)timerFrequency.LowPart);
time_ms = (timeDifference / ticksPerSecond) * 1000;
#elif defined(PYLON_UNIX_BUILD)
time_ms = aLog[i].time - aLog[i-1].time;
#endif
}
cout << setw(12) << fixed << setprecision(4) << time_ms <<" "<< MyEventNames[ aLog[i].eventType ] <<" "<< aLog[i].frameNumber << std::endl;
}
}
static const uint32_t c_countOfImagesToGrab = 50;
#if defined ( USE_GIGE )
{
public:
CEventHandler()
: m_nextExpectedFrameNumberImage(1)
, m_nextExpectedFrameNumberExposureEnd(1)
, m_nextFrameNumberForMove(1)
{
m_log.reserve( c_countOfImagesToGrab * 2);
}
{
if ( userProvidedId == eMyExposureEndEvent)
{
uint16_t frameNumber = (uint16_t)camera.ExposureEndEventFrameID.GetValue();
m_log.push_back( LogItem( eMyExposureEndEvent, frameNumber));
if ( GetIncrementedFrameNumber( frameNumber) != m_nextExpectedFrameNumberExposureEnd)
{
if ( frameNumber == m_nextFrameNumberForMove)
{
MoveImagedItemOrSensorHead();
}
if ( frameNumber != m_nextExpectedFrameNumberExposureEnd)
{
throw RUNTIME_EXCEPTION(
"An Exposure End event has been lost. Expected frame number is %d but got frame number %d.", m_nextExpectedFrameNumberExposureEnd, frameNumber);
}
IncrementFrameNumber( m_nextExpectedFrameNumberExposureEnd);
}
}
else if ( userProvidedId == eMyFrameStartOvertrigger)
{
m_log.push_back( LogItem( eMyFrameStartOvertrigger, 0));
}
else if ( userProvidedId == eMyEventOverrunEvent)
{
m_log.push_back( LogItem( eMyEventOverrunEvent, 0));
}
else
{
PYLON_ASSERT2(false, "The sample has been modified and a new event has been registered. Add handler code above.");
}
}
{
uint16_t frameNumber = (uint16_t)ptrGrabResult->GetBlockID();
m_log.push_back( LogItem( eMyImageReceivedEvent, frameNumber));
if ( frameNumber == m_nextFrameNumberForMove)
{
MoveImagedItemOrSensorHead();
}
if ( frameNumber != m_nextExpectedFrameNumberImage)
{
throw RUNTIME_EXCEPTION(
"An image has been lost. Expected frame number is %d but got frame number %d.", m_nextExpectedFrameNumberExposureEnd, frameNumber);
}
IncrementFrameNumber( m_nextExpectedFrameNumberImage);
}
void MoveImagedItemOrSensorHead()
{
m_log.push_back( LogItem( eMyMoveEvent, m_nextFrameNumberForMove));
IncrementFrameNumber( m_nextFrameNumberForMove);
}
void PrintLog()
{
::PrintLog( m_log);
}
private:
void IncrementFrameNumber( uint16_t& frameNumber)
{
frameNumber = GetIncrementedFrameNumber( frameNumber);
}
uint16_t GetIncrementedFrameNumber( uint16_t frameNumber)
{
++frameNumber;
if ( frameNumber == 0)
{
++frameNumber;
}
return frameNumber;
}
uint16_t m_nextExpectedFrameNumberImage;
uint16_t m_nextExpectedFrameNumberExposureEnd;
uint16_t m_nextFrameNumberForMove;
std::vector<LogItem> m_log;
};
#else //No GigE camera
class CEventHandler : public CameraEventHandler_t , public ImageEventHandler_t
{
public:
CEventHandler()
{
m_log.reserve( c_countOfImagesToGrab * 2);
}
virtual void OnCameraEvent( Camera_t& camera, intptr_t userProvidedId, GenApi::INode* )
{
if ( userProvidedId == eMyExposureEndEvent)
{
m_log.push_back( LogItem( eMyExposureEndEvent, (uint16_t)camera.ExposureEndEventFrameID.GetValue()));
MoveImagedItemOrSensorHead();
}
else if ( userProvidedId == eMyFrameStartOvertrigger)
{
m_log.push_back( LogItem( eMyFrameStartOvertrigger, 0));
}
else if ( userProvidedId == eMyEventOverrunEvent)
{
m_log.push_back( LogItem( eMyEventOverrunEvent, 0));
}
else
{
PYLON_ASSERT2(false, "The sample has been modified and a new event has been registered. Add handler code above.");
}
}
virtual void OnImageGrabbed( Camera_t& camera, const GrabResultPtr_t& ptrGrabResult)
{
m_log.push_back( LogItem( eMyImageReceivedEvent, (uint16_t)ptrGrabResult->GetBlockID()));
}
void MoveImagedItemOrSensorHead()
{
m_log.push_back( LogItem( eMyMoveEvent, 0));
}
void PrintLog()
{
::PrintLog( m_log);
}
private:
std::vector<LogItem> m_log;
};
#endif
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
CEventHandler eventHandler;
camera.GrabCameraEvents = true;
camera.Open();
{
}
{
}
camera.StartGrabbing( c_countOfImagesToGrab);
while ( camera.IsGrabbing())
{
}
{
}
eventHandler.PrintLog();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_UsingExposureEndEvent_Usb
#include "../include/ConfigurationEventPrinter.h"
#include <iomanip>
#ifdef PYLON_UNIX_BUILD
# include <sys/time.h>
#endif
using namespace Pylon;
using namespace Basler_UsbCameraParams;
using namespace std;
enum MyEvents
{
eMyExposureEndEvent,
eMyFrameStartOvertrigger,
eMyImageReceivedEvent,
eMyMoveEvent,
eMyNoEvent
};
const char* MyEventNames[] =
{
"ExposureEndEvent ",
"FrameStartOvertrigger",
"ImageReceived ",
"Move ",
"NoEvent "
};
struct LogItem
{
LogItem()
: eventType( eMyNoEvent)
, frameNumber(0)
{
}
LogItem( MyEvents event, uint16_t frameNr)
: eventType(event)
, frameNumber(frameNr)
{
#if defined(PYLON_WIN_BUILD)
QueryPerformanceCounter(&time);
#elif defined(PYLON_UNIX_BUILD)
struct timeval tv;
gettimeofday(&tv, NULL);
time = static_cast<unsigned long long>(tv.tv_sec) * 1000L + static_cast<unsigned long long>(tv.tv_usec) / 1000LL;
#endif
}
#if defined(PYLON_WIN_BUILD)
LARGE_INTEGER time;
#elif defined(PYLON_UNIX_BUILD)
unsigned long long time;
#endif
MyEvents eventType;
uint16_t frameNumber;
};
void PrintLog( const std::vector<LogItem>& aLog)
{
#if defined(PYLON_WIN_BUILD)
LARGE_INTEGER timerFrequency;
QueryPerformanceFrequency(&timerFrequency);
#endif
cout << std::endl << "Warning, the printed time values can be wrong on older PC hardware." << std::endl << std::endl;
cout << "Time [ms] " << "Event " << "FrameNumber" << std::endl;
cout << "------------ " << "--------------------- " << "-----------" << std::endl;
size_t logSize = aLog.size();
for ( size_t i = 0; i < logSize; ++i)
{
double time_ms = 0;
if ( i)
{
#if defined(PYLON_WIN_BUILD)
__int64 oldTicks = ((__int64)aLog[i-1].time.HighPart << 32) + (__int64)aLog[i-1].time.LowPart;
__int64 newTicks = ((__int64)aLog[i].time.HighPart << 32) + (__int64)aLog[i].time.LowPart;
long double timeDifference = (long double) (newTicks - oldTicks);
long double ticksPerSecond = (long double) (((__int64)timerFrequency.HighPart << 32) + (__int64)timerFrequency.LowPart);
time_ms = (timeDifference / ticksPerSecond) * 1000;
#elif defined(PYLON_UNIX_BUILD)
time_ms = aLog[i].time - aLog[i-1].time;
#endif
}
cout << setw(12) << fixed << setprecision(4) << time_ms <<" "<< MyEventNames[ aLog[i].eventType ] <<" "<< aLog[i].frameNumber << std::endl;
}
}
static const uint32_t c_countOfImagesToGrab = 50;
class CEventHandler : public CameraEventHandler_t, public ImageEventHandler_t
{
public:
CEventHandler()
: m_nextExpectedFrameNumberImage(0)
, m_nextExpectedFrameNumberExposureEnd(0)
, m_nextFrameNumberForMove(0)
, m_frameIDsInitialized(false)
{
m_log.reserve( c_countOfImagesToGrab * 3);
}
virtual void OnCameraEvent( Camera_t& camera, intptr_t userProvidedId, GenApi::INode* )
{
if ( userProvidedId == eMyExposureEndEvent)
{
uint16_t frameNumber = (uint16_t)camera.EventExposureEndFrameID.GetValue();
m_log.push_back( LogItem( eMyExposureEndEvent, frameNumber));
if ( GetIncrementedFrameNumber( frameNumber) != m_nextExpectedFrameNumberExposureEnd)
{
if ( frameNumber == m_nextFrameNumberForMove)
{
MoveImagedItemOrSensorHead();
}
if ( frameNumber != m_nextExpectedFrameNumberExposureEnd)
{
throw RUNTIME_EXCEPTION(
"An Exposure End event has been lost. Expected frame number is %d but got frame number %d.", m_nextExpectedFrameNumberExposureEnd, frameNumber);
}
IncrementFrameNumber( m_nextExpectedFrameNumberExposureEnd);
}
}
else if ( userProvidedId == eMyFrameStartOvertrigger)
{
m_log.push_back( LogItem( eMyFrameStartOvertrigger, 0));
}
else
{
PYLON_ASSERT2(false, "The sample has been modified and a new event has been registered. Add handler code above.");
}
}
virtual void OnImageGrabbed( Camera_t& camera, const GrabResultPtr_t& ptrGrabResult)
{
uint16_t frameNumber = (uint16_t)ptrGrabResult->GetBlockID();
m_log.push_back( LogItem( eMyImageReceivedEvent, frameNumber));
if ( frameNumber == m_nextFrameNumberForMove)
{
MoveImagedItemOrSensorHead();
}
if ( frameNumber != m_nextExpectedFrameNumberImage)
{
throw RUNTIME_EXCEPTION(
"An image has been lost. Expected frame number is %d but got frame number %d.", m_nextExpectedFrameNumberImage, frameNumber);
}
IncrementFrameNumber( m_nextExpectedFrameNumberImage);
}
void MoveImagedItemOrSensorHead()
{
m_log.push_back( LogItem( eMyMoveEvent, m_nextFrameNumberForMove));
IncrementFrameNumber( m_nextFrameNumberForMove);
}
void PrintLog()
{
::PrintLog( m_log);
}
private:
void IncrementFrameNumber( uint16_t& frameNumber)
{
frameNumber = GetIncrementedFrameNumber( frameNumber);
}
uint16_t GetIncrementedFrameNumber( uint16_t frameNumber)
{
++frameNumber;
return frameNumber;
}
uint16_t m_nextExpectedFrameNumberImage;
uint16_t m_nextExpectedFrameNumberExposureEnd;
uint16_t m_nextFrameNumberForMove;
bool m_frameIDsInitialized;
std::vector<LogItem> m_log;
};
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
CEventHandler eventHandler;
camera.GrabCameraEvents = true;
camera.Open();
{
}
{
}
camera.StartGrabbing( c_countOfImagesToGrab);
while ( camera.IsGrabbing())
{
}
{
}
eventHandler.PrintLog();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_UsingGrabLoopThread
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
#include "../include/ConfigurationEventPrinter.h"
#include "../include/ImageEventPrinter.h"
using namespace Pylon;
using namespace std;
{
public:
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
cout << "CSampleImageEventHandler::OnImageGrabbed called." << std::endl;
cout << std::endl;
cout << std::endl;
}
};
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
camera.Open();
if (camera.CanWaitForFrameTriggerReady())
{
cerr << endl << "Enter \"t\" to trigger the camera or \"e\" to exit and press enter? (t/e)" << endl << endl;
char key;
do
{
cin.get(key);
if ( (key == 't' || key == 'T'))
{
{
camera.ExecuteSoftwareTrigger();
}
}
}
while ( (key != 'e') && (key != 'E'));
}
else
{
cout << endl;
cout << "This sample can only be used with cameras that can be queried whether they are ready to accept the next frame trigger.";
cout << endl;
cout << endl;
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
cin.ignore(cin.rdbuf()->in_avail());
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_UsingSequencer
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
#if defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
using namespace Basler_GigEStreamParams;
#else
#error Camera type is not specified. For example, define USE_GIGE for using GigE cameras.
#endif
using namespace std;
static const uint32_t c_countOfImagesToGrab = 10;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
{
camera.SequenceEnable.SetValue(false);
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.SequenceSetTotalNumber = 3;
int64_t increments = (camera.Height.GetMax() - camera.Height.GetMin()) / camera.Height.GetInc();
camera.SequenceSetIndex = 0;
camera.Height.SetValue( camera.Height.GetInc() * (increments / 4));
camera.SequenceSetStore.Execute();
camera.SequenceSetIndex = 1;
camera.Height.SetValue( camera.Height.GetInc() * (increments / 2));
camera.SequenceSetStore.Execute();
camera.SequenceSetIndex = 2;
camera.Height.SetValue( camera.Height.GetInc() * increments);
camera.SequenceSetStore.Execute();
camera.SequenceEnable.SetValue(true);
camera.StartGrabbing( c_countOfImagesToGrab);
while ( camera.IsGrabbing())
{
{
camera.ExecuteSoftwareTrigger();
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, grabResult);
#endif
cout <<
"SizeX: " << grabResult->
GetWidth() << endl;
cout <<
"SizeY: " << grabResult->
GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) grabResult->
GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
}
else
{
}
}
cerr << endl << "Press enter to continue." << endl << endl;
while( camera.IsGrabbing() && cin.get() != '\n');
}
camera.SequenceEnable.SetValue(false);
}
else
{
cout << "The sequencer feature is not available for this camera."<< endl;
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Grab_UsingSequencer_Usb
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
#if defined ( USE_USB )
using namespace Basler_UsbCameraParams;
#else
#error Camera type is not specified. Define USE_USB for using Usb cameras.
#endif
using namespace std;
static const uint32_t c_countOfImagesToGrab = 10;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
{
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
int64_t increments = (camera.Height.GetMax() - camera.Height.GetMin()) / camera.Height.GetInc();
int64_t initialSet = camera.SequencerSetSelector.GetMin();
int64_t incSet = camera.SequencerSetSelector.GetInc();
int64_t curSet = initialSet;
camera.SequencerSetSelector.SetValue(initialSet);
{
camera.SequencerPathSelector.SetValue(0);
camera.SequencerSetNext.SetValue(initialSet);
camera.SequencerPathSelector.SetValue(1);
}
camera.SequencerSetNext.SetValue(curSet + incSet);
camera.Height.SetValue(camera.Height.GetInc() * (increments / 4));
camera.SequencerSetSave.Execute();
curSet += incSet;
camera.SequencerSetSelector.SetValue(curSet);
camera.SequencerSetNext.SetValue(curSet + incSet);
camera.Height.SetValue(camera.Height.GetInc() * (increments / 2));
camera.SequencerSetSave.Execute();
curSet += incSet;
camera.SequencerSetSelector.SetValue(curSet);
camera.SequencerSetNext.SetValue(initialSet);
camera.Height.SetValue(camera.Height.GetInc() * increments);
camera.SequencerSetSave.Execute();
camera.StartGrabbing(c_countOfImagesToGrab);
while (camera.IsGrabbing())
{
{
camera.ExecuteSoftwareTrigger();
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, grabResult);
#endif
cout <<
"SizeX: " << grabResult->
GetWidth() << endl;
cout <<
"SizeY: " << grabResult->
GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *)grabResult->
GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t)pImageBuffer[0] << endl << endl;
}
else
{
}
}
cerr << endl << "Press enter to continue." << endl << endl;
while (camera.IsGrabbing() && cin.get() != '\n');
}
}
else
{
cout << "The sequencer feature is not available for this camera." << endl;
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while (cin.get() != '\n');
return exitCode;
}
ParametrizeCamera_AutoFunctions
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
using namespace std;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#else
#error camera type is not specified. For example, define USE_GIGE for using GigE cameras
#endif
typedef Camera_t::GrabResultPtr_t GrabResultPtr_t;
bool IsColorCamera(Camera_t& camera);
void AutoGainOnce(Camera_t& camera);
void AutoGainContinuous(Camera_t& camera);
void AutoExposureOnce(Camera_t& camera);
void AutoExposureContinuous(Camera_t& camera);
void AutoWhiteBalance(Camera_t& camera);
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
{
camera.GainRaw.SetValue( camera.GainRaw.GetMax());
AutoGainOnce(camera);
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.GainRaw.SetValue( camera.GainRaw.GetMax());
AutoGainContinuous(camera);
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.ExposureTimeRaw.SetValue( camera.ExposureTimeRaw.GetMin());
AutoExposureOnce(camera);
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.ExposureTimeRaw.SetValue( camera.ExposureTimeRaw.GetMin());
AutoExposureContinuous(camera);
if (IsColorCamera(camera))
{
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.BalanceRatioAbs.SetValue(3.14);
camera.BalanceRatioAbs.SetValue(0.5);
camera.BalanceRatioAbs.SetValue(0.125);
AutoWhiteBalance(camera);
}
}
else
{
cerr << "Only area scan cameras support auto functions." << endl;
}
camera.Close();
}
{
cerr << "A timeout has occurred." << endl
cerr << "Please make sure you remove the cap from the camera lens before running this sample." << endl;
exitCode = 0;
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
void AutoGainOnce(Camera_t& camera)
{
{
cout << "The camera does not support Gain Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.AutoFunctionAOIOffsetX.SetValue(0);
camera.AutoFunctionAOIOffsetY.SetValue(0);
camera.AutoFunctionAOIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionAOIHeight.SetValue(camera.Height.GetMax());
camera.AutoTargetValue.SetValue(80);
cout << "Trying 'GainAuto = Once'." << endl;
cout << "Initial Gain = " << camera.GainRaw.GetValue() << endl;
camera.AutoGainRawLowerLimit.SetValue(camera.GainRaw.GetMin());
camera.AutoGainRawUpperLimit.SetValue(camera.GainRaw.GetMax());
int n = 0;
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
++n;
if (n > 100)
{
}
}
cout << "GainAuto went back to 'Off' after " << n << " frames." << endl;
cout << "Final Gain = " << camera.GainRaw.GetValue() << endl << endl;
}
void AutoGainContinuous(Camera_t& camera)
{
{
cout << "The camera does not support Gain Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.AutoFunctionAOIOffsetX.SetValue(0);
camera.AutoFunctionAOIOffsetY.SetValue(0);
camera.AutoFunctionAOIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionAOIHeight.SetValue(camera.Height.GetMax());
camera.AutoTargetValue.SetValue(80);
cout << "Trying 'GainAuto = Continuous'." << endl;
cout << "Initial Gain = " << camera.GainRaw.GetValue() << endl;
for (int n = 0; n < 20; n++)
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
cout << "Final Gain = " << camera.GainRaw.GetValue() << endl << endl;
}
void AutoExposureOnce(Camera_t& camera)
{
{
cout << "The camera does not support Exposure Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.AutoFunctionAOIOffsetX.SetValue(0);
camera.AutoFunctionAOIOffsetY.SetValue(0);
camera.AutoFunctionAOIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionAOIHeight.SetValue(camera.Height.GetMax());
camera.AutoTargetValue.SetValue(80);
cout << "Trying 'ExposureAuto = Once'." << endl;
cout << "Initial exposure time = ";
cout << camera.ExposureTimeAbs.GetValue() << " us" << endl;
camera.AutoExposureTimeAbsLowerLimit.SetValue(camera.AutoExposureTimeAbsLowerLimit.GetMin());
camera.AutoExposureTimeAbsUpperLimit.SetValue(camera.AutoExposureTimeAbsLowerLimit.GetMax());
int n = 0;
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
++n;
if (n > 100)
{
}
}
cout << "ExposureAuto went back to 'Off' after " << n << " frames." << endl;
cout << "Final exposure time = ";
cout << camera.ExposureTimeAbs.GetValue() << " us" << endl << endl;
}
void AutoExposureContinuous(Camera_t& camera)
{
{
cout << "The camera does not support Exposure Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.AutoFunctionAOIOffsetX.SetValue(0);
camera.AutoFunctionAOIOffsetY.SetValue(0);
camera.AutoFunctionAOIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionAOIHeight.SetValue(camera.Height.GetMax());
camera.AutoTargetValue.SetValue(80);
cout << "ExposureAuto 'GainAuto = Continuous'." << endl;
cout << "Initial exposure time = ";
cout << camera.ExposureTimeAbs.GetValue() << " us" << endl;
for (int n = 0; n < 20; n++)
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
cout << "Final exposure time = ";
cout << camera.ExposureTimeAbs.GetValue() << " us" << endl << endl;
}
void AutoWhiteBalance(Camera_t& camera)
{
{
cout << "The camera does not support Balance White Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
camera.AutoFunctionAOIOffsetX.SetValue(0);
camera.AutoFunctionAOIOffsetY.SetValue(0);
camera.AutoFunctionAOIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionAOIHeight.SetValue(camera.Height.GetMax());
cout << "Trying 'BalanceWhiteAuto = Once'." << endl;
cout << "Initial balance ratio: ";
cout << "R = " << camera.BalanceRatioAbs.GetValue() << " ";
cout << "G = " << camera.BalanceRatioAbs.GetValue() << " ";
cout << "B = " << camera.BalanceRatioAbs.GetValue() << endl;
int n = 0;
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
++n;
if (n > 100)
{
}
}
cout << "BalanceWhiteAuto went back to 'Off' after ";
cout << n << " frames." << endl;
cout << "Final balance ratio: ";
cout << "R = " << camera.BalanceRatioAbs.GetValue() << " ";
cout << "G = " << camera.BalanceRatioAbs.GetValue() << " ";
cout << "B = " << camera.BalanceRatioAbs.GetValue() << endl;
}
bool IsColorCamera(Camera_t& camera)
{
camera.PixelFormat.GetEntries(Entries);
bool Result = false;
for (size_t i = 0; i < Entries.size(); i++)
{
GenApi::INode *pNode = Entries[i];
{
GenApi::IEnumEntry *pEnum = dynamic_cast<GenApi::IEnumEntry *>(pNode);
{
Result = true;
break;
}
}
}
return Result;
}
ParametrizeCamera_AutoFunctions_Usb
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
using namespace std;
using namespace Basler_UsbCameraParams;
typedef Camera_t::GrabResultPtr_t GrabResultPtr_t;
bool IsColorCamera(Camera_t& camera);
void AutoGainOnce(Camera_t& camera);
void AutoGainContinuous(Camera_t& camera);
void AutoExposureOnce(Camera_t& camera);
void AutoExposureContinuous(Camera_t& camera);
void AutoWhiteBalance(Camera_t& camera);
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
if (!
IsAvailable(camera.AutoFunctionROISelector) &&
IsAvailable(camera.GetNodeMap().GetNode(
"AutoFunctionAOISelector")))
{
cout << "This camera only supports the deprecated AutoFunctionAOIxxxx camera parameters." << endl;
cout << "If you want to configure the regions used by the auto functions on this camera, use" << endl;
cout << "the AutoFunctionAOIxxxx parameters instead of the AutoFunctionROIxxxx parameters." << endl << endl;
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return 0;
}
camera.Open();
{
camera.Gain.SetValue( camera.Gain.GetMax());
AutoGainOnce(camera);
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.Gain.SetValue( camera.Gain.GetMax());
AutoGainContinuous(camera);
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.ExposureTime.SetValue( camera.ExposureTime.GetMin());
AutoExposureOnce(camera);
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.ExposureTime.SetValue( camera.ExposureTime.GetMin());
AutoExposureContinuous(camera);
if (IsColorCamera(camera))
{
cerr << endl << "Press Enter to continue." << endl;
while( cin.get() != '\n');
camera.BalanceRatio.SetValue(3.14);
camera.BalanceRatio.SetValue(0.5);
camera.BalanceRatio.SetValue(0.125);
AutoWhiteBalance(camera);
}
}
else
{
cerr << "Only area scan cameras support auto functions." << endl;
}
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
void AutoGainOnce(Camera_t& camera)
{
{
cout << "The camera does not support Gain Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
{
camera.AutoFunctionROIUseBrightness.SetValue(true);
camera.AutoFunctionROIUseBrightness.SetValue(false);
camera.AutoFunctionROIOffsetX.SetValue(0);
camera.AutoFunctionROIOffsetY.SetValue(0);
camera.AutoFunctionROIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionROIHeight.SetValue(camera.Height.GetMax());
}
camera.AutoTargetBrightness.SetValue(0.3);
cout << "Trying 'GainAuto = Once'." << endl;
cout << "Initial Gain = " << camera.Gain.GetValue() << endl;
camera.AutoGainLowerLimit.SetValue(camera.Gain.GetMin());
camera.AutoGainUpperLimit.SetValue(camera.Gain.GetMax());
int n = 0;
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
++n;
if (n > 100)
{
}
}
cout << "GainAuto went back to 'Off' after " << n << " frames." << endl;
cout << "Final Gain = " << camera.Gain.GetValue() << endl << endl;
}
void AutoGainContinuous(Camera_t& camera)
{
{
cout << "The camera does not support Gain Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
{
camera.AutoFunctionROIUseBrightness.SetValue(true);
camera.AutoFunctionROIUseBrightness.SetValue(false);
camera.AutoFunctionROIOffsetX.SetValue(0);
camera.AutoFunctionROIOffsetY.SetValue(0);
camera.AutoFunctionROIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionROIHeight.SetValue(camera.Height.GetMax());
}
camera.AutoTargetBrightness.SetValue(0.3);
cout << "Trying 'GainAuto = Continuous'." << endl;
cout << "Initial Gain = " << camera.Gain.GetValue() << endl;
for (int n = 0; n < 20; n++)
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
cout << "Final Gain = " << camera.Gain.GetValue() << endl << endl;
}
void AutoExposureOnce(Camera_t& camera)
{
{
cout << "The camera does not support Exposure Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
{
camera.AutoFunctionROIUseBrightness.SetValue(true);
camera.AutoFunctionROIUseBrightness.SetValue(false);
camera.AutoFunctionROIOffsetX.SetValue(0);
camera.AutoFunctionROIOffsetY.SetValue(0);
camera.AutoFunctionROIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionROIHeight.SetValue(camera.Height.GetMax());
}
camera.AutoTargetBrightness.SetValue(0.3);
cout << "Trying 'ExposureAuto = Once'." << endl;
cout << "Initial exposure time = ";
cout << camera.ExposureTime.GetValue() << " us" << endl;
camera.AutoExposureTimeLowerLimit.SetValue(camera.AutoExposureTimeLowerLimit.GetMin());
camera.AutoExposureTimeUpperLimit.SetValue(camera.AutoExposureTimeLowerLimit.GetMax());
int n = 0;
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
++n;
if (n > 100)
{
}
}
cout << "ExposureAuto went back to 'Off' after " << n << " frames." << endl;
cout << "Final exposure time = ";
cout << camera.ExposureTime.GetValue() << " us" << endl << endl;
}
void AutoExposureContinuous(Camera_t& camera)
{
{
cout << "The camera does not support Exposure Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
{
camera.AutoFunctionROIUseBrightness.SetValue(true);
camera.AutoFunctionROIUseBrightness.SetValue(false);
camera.AutoFunctionROIOffsetX.SetValue(0);
camera.AutoFunctionROIOffsetY.SetValue(0);
camera.AutoFunctionROIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionROIHeight.SetValue(camera.Height.GetMax());
}
camera.AutoTargetBrightness.SetValue(0.3);
cout << "ExposureAuto 'GainAuto = Continuous'." << endl;
cout << "Initial exposure time = ";
cout << camera.ExposureTime.GetValue() << " us" << endl;
for (int n = 0; n < 20; n++)
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
cout << "Final exposure time = ";
cout << camera.ExposureTime.GetValue() << " us" << endl << endl;
}
void AutoWhiteBalance(Camera_t& camera)
{
{
cout << "The camera does not support Balance White Auto." << endl << endl;
return;
}
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
camera.Width.SetValue(camera.Width.GetMax());
camera.Height.SetValue(camera.Height.GetMax());
{
camera.AutoFunctionROIUseWhiteBalance.SetValue(false);
camera.AutoFunctionROIUseWhiteBalance.SetValue(true);
camera.AutoFunctionROIOffsetX.SetValue(0);
camera.AutoFunctionROIOffsetY.SetValue(0);
camera.AutoFunctionROIWidth.SetValue(camera.Width.GetMax());
camera.AutoFunctionROIHeight.SetValue(camera.Height.GetMax());
}
cout << "Trying 'BalanceWhiteAuto = Once'." << endl;
cout << "Initial balance ratio: ";
cout << "R = " << camera.BalanceRatio.GetValue() << " ";
cout << "G = " << camera.BalanceRatio.GetValue() << " ";
cout << "B = " << camera.BalanceRatio.GetValue() << endl;
int n = 0;
{
GrabResultPtr_t ptrGrabResult;
camera.GrabOne( 5000, ptrGrabResult);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
++n;
if (n > 100)
{
}
}
cout << "BalanceWhiteAuto went back to 'Off' after ";
cout << n << " frames." << endl;
cout << "Final balance ratio: ";
cout << "R = " << camera.BalanceRatio.GetValue() << " ";
cout << "G = " << camera.BalanceRatio.GetValue() << " ";
cout << "B = " << camera.BalanceRatio.GetValue() << endl;
}
bool IsColorCamera(Camera_t& camera)
{
camera.PixelFormat.GetEntries(Entries);
bool Result = false;
for (size_t i = 0; i < Entries.size(); i++)
{
GenApi::INode *pNode = Entries[i];
{
GenApi::IEnumEntry *pEnum = dynamic_cast<GenApi::IEnumEntry *>(pNode);
{
Result = true;
break;
}
}
}
return Result;
}
ParametrizeCamera_Configurations
#include "../include/ImageEventPrinter.h"
#include "../include/ConfigurationEventPrinter.h"
#include "../include/PixelFormatAndAoiConfiguration.h"
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 3;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
cout << "Grab using continuous acquisition:" << endl << endl;
camera.Open();
camera.StartGrabbing( c_countOfImagesToGrab);
while( camera.IsGrabbing())
{
}
camera.Close();
cout << "Grab using software trigger mode:" << endl << endl;
camera.StartGrabbing( c_countOfImagesToGrab);
while( camera.IsGrabbing())
{
camera.ExecuteSoftwareTrigger();
}
cout << "Grab using single frame acquisition:" << endl << endl;
camera.GrabOne( 5000, ptrGrabResult);
camera.Open();
camera.GrabOne( 5000, ptrGrabResult);
camera.GrabOne( 5000, ptrGrabResult);
camera.GrabOne( 5000, ptrGrabResult);
camera.Close();
cout << "Grab using multiple configuration objects:" << endl << endl;
CConfigurationEventPrinter* pEventPrinterObject = new CConfigurationEventPrinter;
cout << endl << "Grab, configuration events are printed:" << endl << endl;
camera.GrabOne( 5000, ptrGrabResult);
camera.DeregisterConfiguration( pEventPrinterObject);
delete pEventPrinterObject;
pEventPrinterObject = NULL;
cout << endl << "Grab, configuration events are not printed:" << endl << endl;
camera.GrabOne( 5000, ptrGrabResult);
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
ParametrizeCamera_GenericParameterAccess
using namespace Pylon;
using namespace GenApi;
using namespace std;
int64_t Adjust(int64_t val, int64_t minimum, int64_t maximum, int64_t inc)
{
if (inc <= 0)
{
}
if (minimum > maximum)
{
}
if (val < minimum)
{
return minimum;
}
if (val > maximum)
{
return maximum;
}
if (inc == 1)
{
return val;
}
else
{
return minimum + ( ((val - minimum) / inc) * inc );
}
}
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
INodeMap& nodemap = camera.GetNodeMap();
camera.Open();
cout << "Camera Device Information" << endl
<< "=========================" << endl;
cout << "Vendor : "
cout << "Model : "
cout << "Firmware version : "
cout << "Camera Device Settings" << endl
<< "======================" << endl;
{
offsetX->SetValue( offsetX->GetMin());
}
{
offsetY->SetValue( offsetY->GetMin());
}
int64_t newWidth = 202;
newWidth = Adjust(newWidth, width->GetMin(), width->GetMax(), width->GetInc());
int64_t newHeight = 101;
newHeight = Adjust(newHeight, height->GetMin(), height->GetMax(), height->GetInc());
width->SetValue(newWidth);
height->SetValue(newHeight);
cout << "OffsetX : " << offsetX->GetValue() << endl;
cout << "OffsetY : " << offsetY->GetValue() << endl;
cout << "Width : " << width->GetValue() << endl;
cout << "Height : " << height->GetValue() << endl;
String_t oldPixelFormat = pixelFormat->ToString();
cout << "Old PixelFormat : " << oldPixelFormat << endl;
if (
IsAvailable( pixelFormat->GetEntryByName(
"Mono8")))
{
pixelFormat->FromString( "Mono8");
cout << "New PixelFormat : " << pixelFormat->ToString() << endl;
}
{
gainAuto->FromString("Off");
}
if ( camera.GetSfncVersion() >= Sfnc_2_0_0)
{
double newGain = gain->GetMin() + ((gain->GetMax() - gain->GetMin()) / 2);
gain->SetValue(newGain);
cout << "Gain (50%) : " << gain->GetValue() << " (Min: " << gain->GetMin() << "; Max: " << gain->GetMax() << ")" << endl;
}
else
{
int64_t newGainRaw = gainRaw->GetMin() + ((gainRaw->GetMax() - gainRaw->GetMin()) / 2);
newGainRaw = Adjust(newGainRaw, gainRaw->GetMin(), gainRaw->GetMax(), gainRaw->GetInc());
gainRaw->SetValue(newGainRaw);
cout << "Gain (50%) : " << gainRaw->GetValue() << " (Min: " << gainRaw->GetMin() << "; Max: " << gainRaw->GetMax() << "; Inc: " << gainRaw->GetInc() << ")" << endl;
}
pixelFormat->FromString(oldPixelFormat);
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
ParametrizeCamera_LoadAndSave
using namespace Pylon;
using namespace std;
const char Filename[] = "NodeMap.pfs";
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
cout << "Saving camera's node map to file..."<< endl;
cout << "Reading file back to camera's node map..."<< endl;
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
ParametrizeCamera_LookupTable
using namespace Pylon;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#elif defined ( USE_USB )
using namespace Basler_UsbCameraParams;
#else
#error camera type is not specified. For example, define USE_GIGE for using GigE cameras
#endif
using namespace std;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
cout << "Opening camera...";
camera.Open();
cout << "done" << endl;
cout << "Writing LUT....";
const int nValues = (int) camera.LUTIndex.GetMax() + 1;
int inc;
if ( nValues == 4096 )
inc = 8;
else if ( nValues == 1024 )
inc = 2;
else
{
}
for ( int i = 0; i < nValues; i += inc )
{
camera.LUTIndex.SetValue( i );
camera.LUTValue.SetValue( nValues - 1 - i );
}
cout << "done" << endl;
camera.LUTEnable.SetValue( true );
camera.LUTEnable.SetValue( false );
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
ParametrizeCamera_NativeParameterAccess
using namespace Pylon;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#elif defined ( USE_CAMERALINK )
#include <pylon/cameralink/BaslerCameraLinkInstantCamera.h>
typedef Pylon::CBaslerCameraLinkInstantCamera Camera_t;
using namespace Basler_CLCameraParams;
#elif defined ( USE_USB )
using namespace Basler_UsbCameraParams;
#else
#error Camera type is not specified. For example, define USE_GIGE for using GigE cameras.
#endif
using namespace std;
int64_t Adjust(int64_t val, int64_t minimum, int64_t maximum, int64_t inc)
{
if (inc <= 0)
{
}
if (minimum > maximum)
{
}
if (val < minimum)
{
return minimum;
}
if (val > maximum)
{
return maximum;
}
if (inc == 1)
{
return val;
}
else
{
return minimum + ( ((val - minimum) / inc) * inc );
}
}
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
camera.Open();
cout << "Camera Device Information" << endl
<< "=========================" << endl;
cout << "Vendor : "
<< camera.DeviceVendorName.GetValue() << endl;
cout << "Model : "
<< camera.DeviceModelName.GetValue() << endl;
cout << "Firmware version : "
<< camera.DeviceFirmwareVersion.GetValue() << endl << endl;
cout << "Camera Device Settings" << endl
<< "======================" << endl;
{
camera.OffsetX.SetValue(camera.OffsetX.GetMin());
}
{
camera.OffsetY.SetValue(camera.OffsetY.GetMin());
}
int64_t newWidth = 202;
newWidth = Adjust(newWidth, camera.Width.GetMin(), camera.Width.GetMax(), camera.Width.GetInc());
int64_t newHeight = 101;
newHeight = Adjust(newHeight, camera.Height.GetMin(), camera.Height.GetMax(), camera.Height.GetInc());
camera.Width.SetValue(newWidth);
camera.Height.SetValue(newHeight);
cout << "OffsetX : " << camera.OffsetX.GetValue() << endl;
cout << "OffsetY : " << camera.OffsetY.GetValue() << endl;
cout << "Width : " << camera.Width.GetValue() << endl;
cout << "Height : " << camera.Height.GetValue() << endl;
cout << "Old PixelFormat : " << camera.PixelFormat.ToString() << " (" << oldPixelFormat << ")" << endl;
{
cout << "New PixelFormat : " << camera.PixelFormat.ToString() << " (" << camera.PixelFormat.GetValue() << ")" << endl;
}
{
camera.GainAuto.FromString("Off");
}
#ifdef USE_USB
double newGain = camera.Gain.GetMin() + ((camera.Gain.GetMax() - camera.Gain.GetMin()) / 2);
camera.Gain.SetValue(newGain);
cout << "Gain (50%) : " << camera.Gain.GetValue() << " (Min: " << camera.Gain.GetMin() << "; Max: " << camera.Gain.GetMax() << ")" << endl;
#else
int64_t newGainRaw = camera.GainRaw.GetMin() + ((camera.GainRaw.GetMax() - camera.GainRaw.GetMin()) / 2);
newGainRaw = Adjust(newGainRaw, camera.GainRaw.GetMin(), camera.GainRaw.GetMax(), camera.GainRaw.GetInc());
camera.GainRaw.SetValue(newGainRaw);
cout << "Gain (50%) : " << camera.GainRaw.GetValue() << " (Min: " << camera.GainRaw.GetMin() << "; Max: " << camera.GainRaw.GetMax() << "; Inc: " << camera.GainRaw.GetInc() << ")" << endl;
#endif
camera.PixelFormat.SetValue(oldPixelFormat);
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
ParametrizeCamera_Shading
#define _CRT_SECURE_NO_WARNINGS
using namespace Pylon;
#include <float.h>
#include <errno.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4244)
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#if defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
using namespace Basler_GigEStreamParams;
#elif defined( USE_1394 )
#error Currently no Basler 1394 camera supports shading
#else
#error Camera type is not specified. For example, define USE_GIGE for using GigE cameras
#endif
using namespace std;
void CreateShadingData(Camera_t& camera,
const char *pLocalFilename);
void UploadFile(Camera_t& camera,
const char *pCameraFilename,
const char *pLocalFilename);
void CheckShadingData(Camera_t& camera);
static const char LocalFilename[] = "ShadingData.bin";
#define USE_SHADING_SET_1 // Define which shading set we are going to use.
#if defined (USE_SHADING_SET_1)
static const char CameraFilename[] = "UserGainShading1";
#elif defined (USE_SHADING_SET_2)
static const char CameraFilename[] = "UserGainShading2";
#else
#error No shading set defined!
#endif
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
{
CreateShadingData( camera, LocalFilename);
UploadFile( camera, CameraFilename, LocalFilename);
CheckShadingData( camera);
}
else
{
cerr << "Only line scan cameras support gain shading." << endl;
}
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
void AverageLines(Camera_t& camera,
uint32_t Width,
uint32_t Height,
uint32_t NumCoeffs,
double *Intensities)
{
for (uint32_t x = 0; x < NumCoeffs; x++)
{
Intensities[x] = 0.0;
}
cout << "Grab frame for averaging." << endl;
camera.GrabOne( 5000, ptrGrabResult);
uint8_t *Buffer =
static_cast<uint8_t*
>( ptrGrabResult->
GetBuffer());
if (NumCoeffs == 3 * Width)
{
for (uint32_t x = 0; x < Width; x++)
{
for (uint32_t y = 0; y < Height; y++)
{
uint32_t idx = 3 * (y * Width + x);
Intensities[x] += Buffer[idx];
Intensities[x + Width] += Buffer[idx + 1];
Intensities[x + 2 * Width] += Buffer[idx + 2];
}
}
}
else
{
for (uint32_t x = 0; x < Width; x++)
{
for (uint32_t y = 0; y < Height; y++)
{
Intensities[x] += Buffer[y * Width + x];
}
}
}
double scale = 1.0 / double(Height);
for (uint32_t x = 0; x < NumCoeffs; x++)
{
Intensities[x] *= scale;
}
}
void CalculateCoeffs( uint32_t Width,
uint32_t Height,
uint32_t NumCoeffs,
double * pDblCoeff )
{
if (NumCoeffs == 3 * Width)
{
double MinR = DBL_MAX;
double MinG = DBL_MAX;
double MinB = DBL_MAX;
double MaxR = -DBL_MAX;
double MaxG = -DBL_MAX;
double MaxB = -DBL_MAX;
for (uint32_t x = 0; x < Width; x++)
{
if (pDblCoeff[x] < MinR)
{
MinR = pDblCoeff[x];
}
if (pDblCoeff[x] > MaxR)
{
MaxR = pDblCoeff[x];
}
if (pDblCoeff[x + Width] < MinG)
{
MinG = pDblCoeff[x + Width];
}
if (pDblCoeff[x + Width] > MaxG)
{
MaxG = pDblCoeff[x + Width];
}
if (pDblCoeff[x + 2 * Width] < MinB)
{
MinB = pDblCoeff[x + 2 * Width];
}
if (pDblCoeff[x + 2 * Width] > MaxB)
{
MaxB = pDblCoeff[x + 2 * Width];
}
}
cout << "MaxR = " << (MaxR / MinR) << " * MinR" << endl;
cout << "MaxG = " << (MaxG / MinG) << " * MinG" << endl;
cout << "MaxB = " << (MaxB / MinB) << " * MinB" << endl;
for (uint32_t x = 0; x < Width; x++)
{
pDblCoeff[x] = MaxR / pDblCoeff[x];
pDblCoeff[x + Width] = MaxG / pDblCoeff[x + Width];
pDblCoeff[x + 2 * Width] = MaxB / pDblCoeff[x + 2 * Width];
}
}
else
{
double Min = DBL_MAX;
double Max = -DBL_MAX;
for (uint32_t x = 0; x < Width; x++)
{
if (pDblCoeff[x] < Min)
{
Min = pDblCoeff[x];
}
if (pDblCoeff[x] > Max)
{
Max = pDblCoeff[x];
}
}
cout << "Max = " << (Max / Min) << " * Min" << endl;
for (uint32_t x = 0; x < Width; x++)
{
pDblCoeff[x] = Max / pDblCoeff[x];
}
}
}
bool SupportsRGB(Camera_t& camera);
void CreateShadingData(Camera_t& camera, const char *pLocalFilename)
{
uint32_t Width = (uint32_t)camera.Width.GetValue();
uint32_t Height = (uint32_t)camera.Height.GetValue();
int32_t BytesPerPixel = 1;
if (SupportsRGB(camera))
{
BytesPerPixel = 3;
}
else
{
}
camera.ShadingEnable.SetValue(false);
uint32_t NumCoeffs = BytesPerPixel * Width;
double *pDblCoeff = new double[NumCoeffs];
AverageLines(camera, Width, Height, NumCoeffs, pDblCoeff);
CalculateCoeffs(Width, Height, NumCoeffs, pDblCoeff);
uint32_t *pCoeffs = new uint32_t[NumCoeffs];
for (uint32_t x = 0; x < NumCoeffs; x++)
{
uint32_t coeff = uint32_t(pDblCoeff[x] * (1 << 16));
if (coeff > 0x0003FFFF)
{
static bool PrintMessage = true;
if (PrintMessage)
{
PrintMessage = false;
cout << "Gain shading had to be clipped." << endl;
}
coeff = 0x0003FFFF;
}
pCoeffs[x] = coeff;
}
delete[] pDblCoeff;
FILE *fp = fopen(pLocalFilename, "wb");
if (fp == NULL )
{
}
struct ShadingHeader_t
{
unsigned char version;
unsigned char type;
unsigned char sensorType;
unsigned char lineType;
unsigned short width;
unsigned short reserved;
};
static const unsigned char ShadingVersion_1 = 0x5a;
static const unsigned char ShadingType_Gain = 0xc3;
static const unsigned char ShadingSensorType_Line = 0x02;
static const unsigned char ShadingLineType_Single = 0x01;
static const unsigned char ShadingLineType_Tri = 0x03;
ShadingHeader_t h;
h.version = ShadingVersion_1;
h.type = ShadingType_Gain;
h.sensorType = ShadingSensorType_Line;
h.lineType = BytesPerPixel == 3 ? ShadingLineType_Tri : ShadingLineType_Single;
h.width = uint16_t(Width);
h.reserved = 0;
fwrite(&h, sizeof(h), 1, fp);
fwrite(pCoeffs, sizeof(uint32_t), NumCoeffs, fp);
fclose(fp);
delete[] pCoeffs;
}
void UploadFile(Camera_t& camera,
const char *pCameraFilename,
const char *pLocalFilename)
{
FILE *fp = fopen(pLocalFilename, "rb");
if ( fp == NULL )
{
}
fseek(fp, 0, SEEK_END);
size_t Size = ftell(fp);
rewind(fp);
if (Size == 0)
{
fclose(fp);
return;
}
char *pBuf = new char[Size];
size_t read = fread(pBuf, 1, Size, fp);
fclose(fp);
if (read != Size)
{
}
GenApi::ODevFileStream stream( &camera.GetNodeMap(), pCameraFilename);
stream.write(pBuf, streamsize(Size));
stream.close();
delete[] pBuf;
}
void CheckShadingData(Camera_t& camera)
{
uint32_t Width = (uint32_t)camera.Width.GetValue();
uint32_t Height = (uint32_t)camera.Height.GetValue();
int32_t BytesPerPixel = 1;
if (SupportsRGB(camera))
{
BytesPerPixel = 3;
}
camera.ShadingSetSelector.SetValue(ShadingSet);
camera.ShadingSetActivate.Execute();
camera.ShadingEnable.SetValue(true);
uint32_t NumCoeffs = BytesPerPixel * Width;
double *pDblCoeff = new double[NumCoeffs];
AverageLines( camera,
Width,
Height,
NumCoeffs,
pDblCoeff);
cout << endl << "After applying shading correction:" << endl;
CalculateCoeffs(Width, Height, NumCoeffs, pDblCoeff);
delete[] pDblCoeff;
}
bool SupportsRGB(Camera_t& camera)
{
camera.PixelFormat.GetEntries(Entries);
bool Result = false;
for (size_t i = 0; i < Entries.size(); i++)
{
GenApi::INode *pNode = Entries[i];
{
GenApi::IEnumEntry *pEnum = dynamic_cast<GenApi::IEnumEntry *>(pNode);
{
Result = true;
break;
}
}
}
return Result;
}
ParametrizeCamera_UserSets
using namespace Pylon;
#if defined( USE_1394 )
#include <pylon/1394/Basler1394InstantCamera.h>
typedef Pylon::CBasler1394InstantCamera Camera_t;
using namespace Basler_IIDC1394CameraParams;
#elif defined ( USE_GIGE )
using namespace Basler_GigECameraParams;
#elif defined ( USE_CAMERALINK )
#include <pylon/cameralink/BaslerCameraLinkInstantCamera.h>
typedef Pylon::CBaslerCameraLinkInstantCamera Camera_t;
using namespace Basler_CLCameraParams;
#elif defined ( USE_USB )
using namespace Basler_UsbCameraParams;
#else
#error Camera type is not specified. For example, define USE_GIGE for using GigE cameras.
#endif
using namespace std;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
#ifdef USE_USB
#else
#endif
cout << "Loading default settings" << endl;
camera.UserSetLoad.Execute();
cout << "Turning off Gain Auto and Exposure Auto." << endl;
#ifdef USE_USB
camera.Gain.SetValue(camera.Gain.GetMin());
camera.ExposureTime.SetValue(camera.ExposureTime.GetMin());
#else
camera.GainRaw.SetValue(camera.GainRaw.GetMin());
camera.ExposureTimeRaw.SetValue(camera.ExposureTimeRaw.GetMin());
#endif
cout << "Saving currently active settings to user set 1." << endl;
camera.UserSetSave.Execute();
cout << endl << "Loading default settings." << endl;
camera.UserSetLoad.Execute();
cout << "Default settings" << endl;
cout << "================" << endl;
#ifdef USE_USB
cout << "Gain : " << camera.Gain.GetValue() << endl;
cout << "Exposure time : " << camera.ExposureTime.GetValue() << endl;
#else
cout << "Gain : " << camera.GainRaw.GetValue() << endl;
cout << "Exposure time : " << camera.ExposureTimeRaw.GetValue() << endl;
#endif
cout << endl << "Loading user set 1 settings." << endl;
camera.UserSetLoad.Execute();
cout << "User set 1 settings" << endl;
cout << "===================" << endl;
#ifdef USE_USB
cout << "Gain : " << camera.Gain.GetValue() << endl;
cout << "Exposure time : " << camera.ExposureTime.GetValue() << endl;
#else
cout << "Gain : " << camera.GainRaw.GetValue() << endl;
cout << "Exposure time : " << camera.ExposureTimeRaw.GetValue() << endl;
#endif
#ifdef USE_USB
camera.UserSetDefault.SetValue(oldDefaultUserSet);
#else
camera.UserSetDefaultSelector.SetValue(oldDefaultUserSet);
#endif
camera.Close();
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Utility_Image
#include <iomanip>
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
#include "../include/SampleImageCreator.h"
using namespace Pylon;
using namespace GenApi;
using namespace std;
void PrintImageProperties(
IImage& image)
{
cout
<< endl;
}
void ShowImage(
IImage& image,
const char* message = NULL)
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, image);
#endif
if ( message)
{
cout << endl << message << " ";
}
std::ios state(NULL);
state.copyfmt(cout);
const uint8_t* pBytes =
reinterpret_cast<const uint8_t*
>(image.
GetBuffer());
cout << endl << "First six bytes of the image: " << endl;
for (unsigned int i = 0; i < 6; ++i)
{
cout << "0x" << hex << setfill('0') << setw(2) << unsigned(pBytes[i]) << " ";
}
cout << endl;
cout.copyfmt(state);
cerr << "Press Enter to continue." << endl;
while( cin.get() != '\n');
}
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
const uint32_t cWidth = 640;
const uint32_t cHeight = 480;
const uint32_t cPadding = 10;
const uint8_t cSampleGrayValue = 160;
{
cout << "The properties of the newly created image." << endl;
PrintImageProperties( imageMono8);
uint32_t width = imageMono8.GetWidth();
uint32_t height = imageMono8.GetHeight();
uint8_t* buffer = static_cast<uint8_t*>( imageMono8.GetBuffer());
uint8_t* p = buffer;
for (uint32_t y = 0; y < height; ++y)
{
for (uint32_t x = 0; x < width; ++x, ++p)
{
p = (uint8_t)((x + y) % 256);
}
}
ShowImage( imageMono8, "Created image.");
cout << endl << "After assignment multiple images reference the same data." << endl;
PrintImageProperties( imageMono8);
PrintImageProperties( sameImageMono8A);
PrintImageProperties( sameImageMono8B);
cout << endl << "The properties of a full copy of the test image." << endl;
PrintImageProperties( copiedImage);
cout << endl << "Assigned to image object after releasing the image data." << endl;
PrintImageProperties( sameImageMono8B);
cout << endl << "A newly created image object." << endl;
PrintImageProperties( reusedImage);
cout << "After resetting the image properties. A new Buffer is allocated." << endl;
PrintImageProperties( reusedImage);
cout << "After resetting the image properties to a smaller image. The buffer is reused." << endl;
PrintImageProperties( reusedImage);
cout << "After resetting the image properties to a larger image." << endl << "A new Buffer is allocated." << endl;
PrintImageProperties( reusedImage);
cout << endl << "After resetting the image properties while the image data is referenced by another image. A new Buffer is allocated." << endl;
PrintImageProperties( sameImageMono8A);
cout << endl << "After resetting the image properties with additional padding." << endl;
PrintImageProperties( sameImageMono8A);
}
{
vector<uint8_t> buffer( (cWidth + cPadding) * cHeight, cSampleGrayValue);
size_t bufferSize = buffer.size() * sizeof( buffer[ 0 ]);
cout << endl << "The properties of an image with an attached user buffer." << endl;
PrintImageProperties( imageA);
cout << "After resetting the image properties to a smaller image. The buffer is reused." << endl;
PrintImageProperties( imageA);
try
{
cout << "Try calling the Reset method when the user buffer is too small for the new image." << endl;
}
catch (const GenericException &e)
{
cerr << "Expected exception: " << e.GetDescription() << endl;
}
cout << endl << "The properties of an image after a full copy of a user buffer." << endl;
PrintImageProperties( imageB);
}
{
cout << endl << "Waiting for an image to be grabbed." << endl;
try
{
Camera.GrabOne( 1000, ptrGrabResult);
}
catch (const GenericException &e)
{
cerr << "Could not grab an image: " << endl
<< e.GetDescription() << endl;
}
{
cout << endl << "The properties of the grabbed image." << endl;
PrintImageProperties( ptrGrabResult);
ShowImage( ptrGrabResult, "Grabbed image.");
cout << endl << "The properties of an image with an attached grab result." << endl;
PrintImageProperties( image);
uint32_t width = ptrGrabResult->
GetWidth();
uint32_t height = ptrGrabResult->
GetHeight();
cout << "After the grab result has been released." << endl;
PrintImageProperties( image);
image.
Reset( pixelType, width / 2, height);
cout << endl << "After resetting the image properties while a grab result is referenced. A new Buffer is allocated." << endl;
PrintImageProperties( image);
}
}
{
#ifdef PYLON_WIN_BUILD
imageSaved.
Save( ImageFileFormat_Bmp,
"JuliaFractal.bmp");
#endif
#ifdef PYLON_WIN_BUILD
imageLoaded.
Load(
"JuliaFractal.bmp");
cout << endl << "The properties of the loaded sample image." << endl;
PrintImageProperties( imageLoaded);
ShowImage( imageLoaded, "The loaded sample image is shown.");
#endif
}
{
cout << endl << "The properties of the sample image." << endl;
PrintImageProperties( sampleImage);
uint32_t topLeftX = cWidth / 4;
uint32_t topLeftY = cHeight /2;
uint32_t width = cWidth / 4;
uint32_t height = cHeight / 4;
aoi = sampleImage.
GetAoi( topLeftX, topLeftY, width, height);
cout << "After creating an AOI." << endl;
PrintImageProperties( aoi);
ShowImage( aoi, "AOI of the sample image.");
cout << "The properties of a full copy of the AOI image." << endl;
PrintImageProperties( copiedAoi);
topLeftX = width / 4;
topLeftY = height / 4;
width = width / 2;
height = height / 2;
aoiFromAoi = aoi.
GetAoi( topLeftX, topLeftY, width, height);
cout << "After creating an AOI of an AOI." << endl;
PrintImageProperties( aoiFromAoi);
ShowImage( aoiFromAoi, "AOI of the AOI of the sample image.");
cout << "After reusing the buffer of the sample image." << endl;
PrintImageProperties( aoiFromAoi);
}
{
imageRGB8planar = SampleImageCreator::CreateMandelbrotFractal(
PixelType_RGB8planar, cWidth, cHeight);
ShowImage( imageRGB8planar, "Sample image.");
ShowImage( redPlane, "Red plane of the sample image.");
ShowImage( greenPlane, "Green plane of the sample image.");
ShowImage( bluePlane, "Blue plane of the sample image.");
ShowImage( imageRGB8planar, "Sample image with red set to zero.");
}
{
#ifdef PYLON_WIN_BUILD
CPylonBitmapImage bitmapImage;
bitmapImage.CopyImage( sampleImage);
cout << endl << "The properties of the bitmap image." << endl;
PrintImageProperties( bitmapImage);
ShowImage( bitmapImage, "The sample image is shown.");
CPylonBitmapImage sameBitmapImageA( bitmapImage);
CPylonBitmapImage sameBitmapImageB = bitmapImage;
cout << endl << "After assignment multiple images reference the same data." << endl;
PrintImageProperties( bitmapImage);
PrintImageProperties( sameBitmapImageA);
PrintImageProperties( sameBitmapImageB);
sameBitmapImageB.Release();
cout << endl << "Assigned to image object after releasing the image data." << endl;
PrintImageProperties( sameBitmapImageB);
converter.
Convert( bitmapImage, sampleImage);
cout << endl << "The properties of the converted bitmap image." << endl;
PrintImageProperties( bitmapImage);
ShowImage( bitmapImage, "The to monochrome converted sample image is shown.");
cout << endl << "The properties of the reused bitmap image with equal properties." << endl;
PrintImageProperties( bitmapImage);
cout << endl << "The properties of the newly allocated bitmap image with different properties." << endl;
PrintImageProperties( bitmapImage);
HBITMAP bitmap = bitmapImage;
bitmap = bitmapImage.Detach();
cout << endl << "The image object after detaching the image data." << endl;
PrintImageProperties( bitmapImage);
::DeleteObject( bitmap);
#endif
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Utility_ImageFormatConverter
#include <iomanip>
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
#include "../include/SampleImageCreator.h"
using namespace Pylon;
using namespace GenApi;
using namespace std;
void ShowImage(
IImage& image,
const char* message = NULL)
{
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, image);
#endif
if ( message)
{
cout << endl << message << " ";
}
std::ios state(NULL);
state.copyfmt(cout);
const uint8_t* pBytes =
reinterpret_cast<const uint8_t*
>(image.
GetBuffer());
cout << endl << "First six bytes of the image: " << endl;
for (unsigned int i = 0; i < 6; ++i)
{
cout << "0x" << hex << setfill('0') << setw(2) << unsigned(pBytes[i]) << " ";
}
cout << endl;
cout.copyfmt(state);
cerr << "Press Enter to continue." << endl;
while( cin.get() != '\n');
}
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
const uint32_t cWidth = 640;
const uint32_t cHeight = 480;
{
ShowImage( imageRGB8packed, "Source image.");
converter.
Convert( targetImage, imageRGB8packed);
ShowImage( targetImage, "Converted image.");
}
{
cout << endl << "Waiting for an image to be grabbed." << endl;
try
{
if ( Camera.GrabOne( 1000, ptrGrabResult))
{
{
ShowImage( ptrGrabResult, "Grabbed image.");
}
else
{
ShowImage( ptrGrabResult, "Grabbed image.");
converter.
Convert( targetImage, ptrGrabResult);
ShowImage( targetImage, "Converted image.");
}
}
}
catch (const GenericException &e)
{
cerr << "Could not grab an image: " << endl
<< e.GetDescription() << endl;
}
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}
Utility_ImageLoadAndSave
#include "../include/SampleImageCreator.h"
using namespace Pylon;
using namespace GenApi;
using namespace std;
int main(int argc, char* argv[])
{
int exitCode = 0;
try
{
const uint32_t cWidth = 640;
const uint32_t cHeight = 480;
{
<< " be saved without conversion as tiff." << endl;
#ifdef PYLON_WIN_BUILD
imageRGB16packed.
Save( ImageFileFormat_Bmp,
"MandelbrotFractal.bmp");
<< " be saved without conversion as bmp." << endl;
#endif
uint32_t width = imageRGB16packed.
GetWidth();
uint32_t height = imageRGB16packed.
GetHeight();
"MandelbrotFractal.png",
buffer,
bufferSize,
pixelType,
width,
height,
paddingX,
orientation);
}
{
<< "RGB16packed." << endl;
#ifdef PYLON_WIN_BUILD
imageBGR8packedFromBmp.
Load(
"MandelbrotFractal.bmp");
<< "BGR8packed." << endl;
#endif
}
#ifdef PYLON_WIN_BUILD
{
}
#endif
{
cout << endl << "Waiting for an image to be grabbed." << endl;
try
{
if ( Camera.GrabOne( 1000, ptrGrabResult))
{
}
}
catch (const GenericException &e)
{
cerr << "Could not grab an image: " << endl
<< e.GetDescription() << endl;
}
}
}
catch (const GenericException &e)
{
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
return exitCode;
}