This example uses a global map to retain image information, including the number of images grabbed, the number of incomplete images and the number of removals for each camera over the duration of the example. Cameras may be added or removed after the example has started.
The example assumes each camera has a unique serial number and is capable of configuring User Set 1. Note that if a camera was configured and is disconnected before the example ends, it will not be reconfigured to use the default User Set.
#include <iostream>
#include <iomanip>
#include <map>
using namespace std;
{
public:
{
m_deviceSerialNumber = deviceSerial;
}
{
}
private:
string m_deviceSerialNumber;
};
{
{
}
};
{
{
cout << "Error OnImageEvent: camera " << m_deviceSerialNumber << " not found in grab info map" << endl;
return;
}
if (image->IsIncomplete())
{
cameraGrabInfo->second.numIncompleteImages++;
}
else
{
unsigned int& numImagesGrabbed = cameraGrabInfo->second.numImagesGrabbed;
numImagesGrabbed++;
if (numImagesGrabbed % 10 == 0)
{
cout << numImagesGrabbed << " Images grabbed for " << m_deviceSerialNumber << endl;
}
}
}
{
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
Sleep(milliseconds);
#else
usleep(1000 * milliseconds);
#endif
}
{
try
{
}
{
cout <<
"Error refreshing camera list: " << e.
what() << endl;
}
}
{
public:
{
const std::string serialNum = std::string(pCamera->TLDevice.DeviceSerialNumber.ToString());
{
{
try
{
cam->BeginAcquisition();
}
{
cout <<
"Error beginning acquisition: " << e.
what() << endl;
}
}
else
{
cout << "Error OnDeviceArrival: configuration for device " << serialNum << " failed.";
}
}
}
{
const string deviceSerial = std::string(pCamera->TLDevice.DeviceSerialNumber.ToString());
cout << endl << deviceSerial << " Device Removal Detected" << endl << endl;
{
cameraGrabInfo->second.numRemovals++;
}
else
{
cout << "Error OnDeviceRemoval: camera " << deviceSerial << " not found in grab info map" << endl;
}
}
private:
};
{
bool result = true;
try
{
{
cout << "Unable to set User Set Selector to User Set 1 (node retrieval). Aborting..." << endl << endl;
return false;
}
CEnumEntryPtr ptrUserSet1 = ptrUserSetSelector->GetEntryByName(
"UserSet1");
{
cout << "Unable to get User Set Selector to User Set 1 (enum entry retrieval). Aborting..." << endl << endl;
return false;
}
const int64_t userSet1 = ptrUserSet1->GetValue();
ptrUserSetSelector->SetIntValue(userSet1);
{
cout << "Unable to set User Set Default to User Set 1 (node retrieval). Aborting..." << endl << endl;
return false;
}
ptrUserSetDefault->SetIntValue(userSet1);
{
cout << "Unable to get acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return false;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to set acquisition mode to continuous (enum entry retrieval). Aborting..." << endl << endl;
return false;
}
const int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
{
cout << "Unable to set acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return false;
}
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
CCommandPtr ptrUserSetSave = nodeMap.GetNode(
"UserSetSave");
{
cout << "Unable to save Settings to User Set 1. Aborting..." << endl << endl;
return false;
}
ptrUserSetSave->Execute();
}
{
cout <<
"Error configuring user set 1: " << e.
what() << endl;
result = false;
}
return result;
}
{
try
{
{
cout << "Unable to set User Set Selector to Default (node retrieval). Aborting..." << endl << endl;
return;
}
CEnumEntryPtr ptrUserSetDefaultEntry = ptrUserSetSelector->GetEntryByName(
"Default");
{
cout << "Unable to get User Set Selector to Default (enum entry retrieval). Aborting..." << endl << endl;
return;
}
const int64_t userSetDefault = ptrUserSetDefaultEntry->GetValue();
ptrUserSetSelector->SetIntValue(userSetDefault);
{
cout << "Unable to set User Set Default to User Set 1 (node retrieval). Aborting..." << endl << endl;
return;
}
ptrUserSetDefault->SetIntValue(userSetDefault);
CCommandPtr ptrUserSetLoad = nodeMap.GetNode(
"UserSetLoad");
{
cout << "Unable to load Settings from User Set Default. Aborting..." << endl << endl;
return;
}
ptrUserSetLoad->Execute();
}
{
cout <<
"Error resetting camera to use default user set: " << e.
what() << endl;
}
}
{
INodeMap& nodeMap = pCam->GetTLDeviceNodeMap();
CStringPtr ptrDeviceSerialNumber = nodeMap.GetNode(
"DeviceSerialNumber");
{
return string(ptrDeviceSerialNumber->GetValue());
}
return "";
}
{
bool result = true;
try
{
pCam->Init();
cout << endl
<< endl
<< "*** " << (cameraFound ? "RESUMING" : "STARTING") << " RECOVERY EXAMPLE FOR " << deviceSerialNumber
<< " ***" << endl
<< endl;
if (!cameraFound)
{
cout << "Configuring device " << deviceSerialNumber << endl;
{
return false;
}
pCam->RegisterEventHandler(*(
cameraGrabInfoMap.find(deviceSerialNumber)->second.imageEventHandler));
}
}
{
cout <<
"Error Running single camera: " << e.
what() << endl;
result = false;
}
return result;
}
{
cout << endl << "Printing Final Statistics " << endl << endl;
const unsigned int printWidth = 20;
cout << setw(printWidth) << left << "Serial Number:" << setw(printWidth) << left
<< "Images Grabbed:" << setw(printWidth) << left << "Incomplete Images:" << setw(printWidth) << left
<< "Camera Removals:" << endl;
{
cout << setw(printWidth) << left << camInfo->first << setw(printWidth) << left
<< camInfo->second.numImagesGrabbed << setw(printWidth) << left << camInfo->second.numIncompleteImages
<< setw(printWidth) << left << camInfo->second.numRemovals << endl;
}
}
{
FILE* tempFile = fopen("test.txt", "w+");
if (tempFile == nullptr)
{
cout << "Failed to create file in current folder. Please check permissions." << endl;
cout << "Press Enter to exit..." << endl;
getchar();
return -1;
}
fclose(tempFile);
remove("test.txt");
cout << "Application build date: " << __DATE__ << " " << __TIME__ << endl << endl;
const LibraryVersion spinnakerLibraryVersion = system->GetLibraryVersion();
cout <<
"Spinnaker library version: " << spinnakerLibraryVersion.
major <<
"." << spinnakerLibraryVersion.
minor
<<
"." << spinnakerLibraryVersion.
type <<
"." << spinnakerLibraryVersion.
build << endl
<< endl
<< endl;
cout <<
"Number of cameras detected: " <<
globalCamList.GetSize() << endl;
for (
unsigned int camIndex = 0; camIndex <
globalCamList.GetSize(); camIndex++)
{
{
cout <<
"Camera configuration for device " <<
GetDeviceSerial(cam) <<
" unsuccessful, aborting...";
return -1;
}
}
system->RegisterEventHandler(interfaceEventHandler);
cout << endl
<< "Cameras may be unplugged/plugged in after the example has started." << endl
<< "After the example begins, please press Enter to end the example..." << endl;
cout << endl << "Press Enter to begin..." << endl << endl;
string temp;
for (
unsigned int camIndex = 0; camIndex <
globalCamList.GetSize(); camIndex++)
{
try
{
}
{
cout <<
"Error starting acquisition on camera at index " << camIndex <<
": " << e.
what() << endl;
}
}
for (
unsigned int camIndex = 0; camIndex <
globalCamList.GetSize(); camIndex++)
{
try
{
}
{
cout <<
"Error ending acquisition on camera at index " << camIndex <<
": " << e.
what() << endl;
}
}
system->UnregisterEventHandler(interfaceEventHandler);
for (
unsigned int camIndex = 0; camIndex <
globalCamList.GetSize(); ++camIndex)
{
{
cout <<
"Resetting configuration for device " <<
GetDeviceSerial(cam) << endl;
cam->DeInit();
}
}
cout << endl;
cout << endl;
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
return 0;
}
int main(int, char **)
Definition Acquisition.cpp:527
std::map< std::string, GrabInfo > cameraGrabInfoMap
Definition AcquisitionMultipleCameraRecovery.cpp:99
void PrintExampleStatistics()
Definition AcquisitionMultipleCameraRecovery.cpp:462
CameraList globalCamList
Definition AcquisitionMultipleCameraRecovery.cpp:139
bool ConfigureCamera(CameraPtr pCam)
Definition AcquisitionMultipleCameraRecovery.cpp:405
bool ConfigureUserSet1(CameraPtr pCam)
Definition AcquisitionMultipleCameraRecovery.cpp:245
void RefreshCameraList(SystemPtr system)
Definition AcquisitionMultipleCameraRecovery.cpp:155
void ResetCameraUserSetToDefault(CameraPtr pCam)
Definition AcquisitionMultipleCameraRecovery.cpp:337
void SleepyWrapper(int milliseconds)
Definition AcquisitionMultipleCameraRecovery.cpp:144
string GetDeviceSerial(CameraPtr pCam)
Definition AcquisitionMultipleCameraRecovery.cpp:392
Definition AcquisitionMultipleCameraRecovery.cpp:57
void OnImageEvent(ImagePtr image)
Image event callback.
Definition AcquisitionMultipleCameraRecovery.cpp:109
~ImageEventHandlerImpl()
Definition AcquisitionMultipleCameraRecovery.cpp:66
Definition AcquisitionMultipleCameraRecovery.cpp:175
void OnDeviceRemoval(CameraPtr pCamera)
Callback to the device removal event.
Definition AcquisitionMultipleCameraRecovery.cpp:214
void OnDeviceArrival(CameraPtr pCamera)
Device arrival event callback.
Definition AcquisitionMultipleCameraRecovery.cpp:183
~InterfaceEventHandlerImpl()
Definition AcquisitionMultipleCameraRecovery.cpp:179
virtual bool IsValid() const
True if the pointer is valid.
Used to hold a list of camera objects.
Definition CameraList.h:42
A reference tracked pointer to a camera object.
Definition CameraPtr.h:44
The Exception object represents an error that is returned from the library.
Definition Exception.h:51
virtual const char * what() const
virtual override for what().
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:75
bool IsValid() const
true if the pointer is valid
Definition Pointer.h:172
A handler for capturing image arrival events.
Definition ImageEventHandler.h:42
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A handler to device arrival and removal events on all interfaces.
Definition InterfaceEventHandler.h:40
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition INode.h:277
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition INode.h:253
interface SPINNAKER_API_ABSTRACT INodeMap
Interface to access the node map.
Definition INodeMap.h:54
Definition Autovector.h:36
std::istream & getline(std::istream &is, Spinnaker::GenICam::gcstring &str)
STL getline.
Definition GCString.h:189
Definition AcquisitionMultipleCameraRecovery.cpp:86
unsigned int numImagesGrabbed
Definition AcquisitionMultipleCameraRecovery.cpp:87
std::shared_ptr< ImageEventHandlerImpl > imageEventHandler
Definition AcquisitionMultipleCameraRecovery.cpp:90
unsigned int numRemovals
Definition AcquisitionMultipleCameraRecovery.cpp:89
unsigned int numIncompleteImages
Definition AcquisitionMultipleCameraRecovery.cpp:88
Provides easier access to the current version of Spinnaker.
Definition SpinnakerDefs.h:658
unsigned int minor
Minor version of the library.
Definition SpinnakerDefs.h:663
unsigned int major
Major version of the library.
Definition SpinnakerDefs.h:660
unsigned int type
Version type of the library.
Definition SpinnakerDefs.h:666
unsigned int build
Build number of the library.
Definition SpinnakerDefs.h:669