This example touches on the preparation and cleanup of a camera just before and just after the acquisition of images. Image retrieval and conversion, grabbing image data, and saving images are all covered as well.
Once comfortable with Acquisition, we suggest checking out AcquisitionMultipleCamera, NodeMapCallback, or SaveToVideo. AcquisitionMultipleCamera demonstrates simultaneously acquiring images from a number of cameras, NodeMapCallback serves as a good introduction to programming with callbacks and events, and SaveToVideo exhibits video creation.
#include <iostream>
#include <sstream>
using namespace std;
{
};
#if defined(WIN32) || defined(WIN64)
#else
#endif
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
{
return -1;
}
{
return 0;
}
if (enableHeartbeat)
{
cout << endl << "Resetting heartbeat..." << endl << endl;
}
else
{
cout << endl << "Disabling heartbeat..." << endl << endl;
}
CBooleanPtr ptrDeviceHeartbeat = nodeMap.GetNode(
"GevGVCPHeartbeatDisable");
{
cout << "Unable to configure heartbeat. Continuing with execution as this may be non-fatal..." << endl << endl;
}
else
{
ptrDeviceHeartbeat->SetValue(!enableHeartbeat);
if (!enableHeartbeat)
{
cout << "WARNING: Heartbeat has been disabled for the rest of this example run." << endl;
cout << " Heartbeat will be reset upon the completion of this run. If the " << endl;
cout << " example is aborted unexpectedly before the heartbeat is reset, the" << endl;
cout << " camera may need to be power cycled to reset the heartbeat." << endl << endl;
}
else
{
cout << "Heartbeat has been reset." << endl;
}
}
return 0;
}
{
}
{
}
{
int result = 0;
const INodeMap& sNodeMap = pCam->GetTLStreamNodeMap();
{
return 0;
}
{
streamMode = "LWF";
break;
streamMode = "Socket";
break;
default:
streamMode = "TeledyneGigeVision";
}
const CEnumEntryPtr ptrStreamModeCustom = ptrStreamMode->GetEntryByName(streamMode);
{
cout << "Stream mode " + streamMode + " not available. Aborting..." << endl;
return -1;
}
const int64_t streamModeCustom = ptrStreamModeCustom->GetValue();
ptrStreamMode->SetIntValue(streamModeCustom);
cout << endl << "Stream Mode set to " + ptrStreamMode->GetCurrentEntry()->GetSymbolic() << "..." << endl;
return 0;
}
{
int result = 0;
cout << endl << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
cout << "Unable to set acquisition mode to continuous (enum retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to get or set acquisition mode to continuous (entry retrieval). Aborting..." << endl
<< endl;
return -1;
}
const int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "Acquisition mode set to continuous..." << endl;
pCam->BeginAcquisition();
cout << "Acquiring images..." << endl;
CStringPtr ptrStringSerial = nodeMapTLDevice.GetNode(
"DeviceSerialNumber");
{
deviceSerialNumber = ptrStringSerial->GetValue();
cout << "Device serial number retrieved as " << deviceSerialNumber << "..." << endl;
}
cout << endl;
for (
unsigned int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
try
{
ImagePtr pResultImage = pCam->GetNextImage(1000);
if (pResultImage->IsIncomplete())
{
<< "..." << endl
<< endl;
}
else
{
const size_t width = pResultImage->GetWidth();
const size_t height = pResultImage->GetHeight();
cout << "Grabbed image " << imageCnt << ", width = " << width << ", height = " << height << endl;
ostringstream filename;
filename << "Acquisition-";
if (!deviceSerialNumber.empty())
{
filename << deviceSerialNumber.c_str() << "-";
}
filename << imageCnt << ".jpg";
convertedImage->Save(filename.str().c_str());
cout << "Image saved at " << filename.str() << endl;
}
pResultImage->Release();
cout << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
}
pCam->EndAcquisition();
}
{
cout <<
"Error: " << e.
what() << endl;
return -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)
{
try
{
cout << pfeatureNode->GetName() << " : ";
cout << (
IsReadable(pValue) ? pValue->ToString() :
"Node not readable");
cout << endl;
}
{
cout << "Node not readable" << endl;
}
}
}
else
{
cout << "Device control information not readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
#ifdef _DEBUG
#else
#endif
#ifdef _DEBUG
#endif
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");
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;
const 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;
}
int result = 0;
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running example for camera " << i << "..." << endl;
cout << "Camera " << i << " example complete..." << endl << endl;
}
pCam = nullptr;
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return result;
}