It can also be helpful to familiarize yourself with the NodeMapCallback example, as nodemap callbacks follow the same general procedure as events, but with a few less steps.
#include <iostream>
#include <sstream>
using namespace Spinnaker;
using namespace Spinnaker::GenApi;
using namespace Spinnaker::GenICam;
using namespace std;
{
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
Sleep(milliseconds);
#else
usleep(1000 * milliseconds);
#endif
}
{
public:
{
INodeMap& nodeMap = pCam->GetTLDeviceNodeMap();
m_deviceSerialNumber = "";
CStringPtr ptrDeviceSerialNumber = nodeMap.GetNode(
"DeviceSerialNumber");
{
m_deviceSerialNumber = ptrDeviceSerialNumber->GetValue();
}
m_imageCnt = 0;
pCam = nullptr;
}
{
}
{
if (m_imageCnt < mk_numImages)
{
cout << "Image event occurred..." << endl;
if (image->IsIncomplete())
{
cout << "Image incomplete with image status " << image->GetImageStatus() << "..." << endl << endl;
}
else
{
cout << "Grabbed image " << m_imageCnt << ", width = " << image->GetWidth()
<< ", height = " << image->GetHeight() << endl;
ostringstream filename;
filename << "ImageEvents-";
if (m_deviceSerialNumber != "")
{
filename << m_deviceSerialNumber.c_str() << "-";
}
filename << m_imageCnt << ".jpg";
convertedImage->Save(filename.str().c_str());
cout << "Image saved at " << filename.str() << endl << endl;
m_imageCnt++;
}
}
}
int getImageCount()
{
return m_imageCnt;
}
int getMaxImages()
{
return mk_numImages;
}
private:
static const unsigned int mk_numImages = 10;
unsigned int m_imageCnt;
string m_deviceSerialNumber;
};
{
int result = 0;
try
{
pCam->RegisterEventHandler(*imageEventHandler);
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
const int sleepDuration = 200;
{
cout << "\t//" << endl;
cout << "\t// Sleeping for " << sleepDuration << " ms. Grabbing images..." << endl;
cout << "\t//" << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
try
{
pCam->UnregisterEventHandler(*imageEventHandler);
delete imageEventHandler;
cout << "Image events unregistered..." << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
{
category->GetFeatures(features);
FeatureList_t::const_iterator it;
for (it = features.begin(); it != features.end(); ++it)
{
cout << pfeatureNode->GetName() << " : ";
cout << (
IsReadable(pValue) ? pValue->ToString() :
"Node not readable");
cout << endl;
}
}
else
{
cout << "Device control information not readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
cout << "Unable to get or set acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to get acquisition mode to continuous (enum entry retrieval). Aborting..." << endl << endl;
return -1;
}
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "Acquisition mode set to continuous..." << endl;
pCam->BeginAcquisition();
cout << "Acquiring images..." << endl;
pCam->EndAcquisition();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
int err = 0;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
if (err < 0)
{
return err;
}
result = result |
AcquireImages(pCam, nodeMap, nodeMapTLDevice, imageEventHandler);
pCam->DeInit();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
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");
int result = 0;
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;
unsigned int numCameras = camList.
GetSize();
cout << "Number of cameras detected: " << numCameras << endl << endl;
if (numCameras == 0)
{
system->ReleaseInstance();
cout << "Not enough cameras!" << endl;
cout << "Done! Press Enter to exit..." << endl;
getchar();
return -1;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running example for camera " << i << "..." << endl;
cout << "Camera " << i << " example complete..." << endl << endl;
}
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return result;
}