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;
};
{
unsigned int numImagesGrabbed;
unsigned int numIncompleteImages;
unsigned int numRemovals;
std::shared_ptr<ImageEventHandlerImpl> imageEventHandler;
GrabInfo(
const string& deviceSerial) : numImagesGrabbed(0), numIncompleteImages(0), numRemovals(0)
{
imageEventHandler = make_shared<ImageEventHandlerImpl>(deviceSerial);
}
};
{
{
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->GetDeviceSerialNumber());
{
{
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->GetDeviceSerialNumber());
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 <<
"Camera configuration for device " <<
GetDeviceSerial(cam) <<
" unsuccessful, aborting..." << endl;
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;
{
try
{
}
{
cout <<
"Error starting acquisition on camera at index " << camIndex <<
": " << e.
what() << endl;
}
}
{
try
{
}
{
cout <<
"Error ending acquisition on camera at index " << camIndex <<
": " << e.
what() << endl;
}
}
system->UnregisterEventHandler(interfaceEventHandler);
{
{
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;
}