Spinnaker SDK C++
4.1.0.338
 
 

 
Loading...
Searching...
No Matches
GigEVisionPerformance.cpp

GigEVisionPerformance.cpp measures GigE Vision performance.

GigEVisionPerformance.cpp measures GigE Vision performance. It is built on top of Acquisition example.

This example measures CPU related performance statistics and print them out at the end.

//=============================================================================
// Copyright (c) 2024 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR).
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================
#include "Spinnaker.h"
#include <iostream>
#include <sstream>
#include <sys/types.h>
#include "CpuUtil.h"
using namespace std;
using namespace Spinnaker;
using namespace Spinnaker::GenApi;
using namespace Spinnaker::GenICam;
// Following parameters can be configured through command-line arguments.
// Use "-?" argument to see detailed usage information.
int TestDuration = 0; // seconds
char* PixelFormatToSet = nullptr;
int PacketSizeToSet = 9000;
bool IsRelease = false; // whether to call release() on the image Pointer or let it be done implicitly by the grab loop
bool UseDuration = false;
bool UseMaxFramerate = false;
float UserSetFramerate = 0.0;
int NumImagesToGrab = 100;
// Supported command-line arguments
const char* argNumImages = "-numimages";
const char* argDuration = "-duration";
const char* argRelease = "-callrelease";
const char* argBayerRG = "-bayerrg";
const char* argPacketSize = "-packetsize";
const char* argPacketDelay = "-packetdelay";
const char* argMaxFrames = "-maxfps";
const char* argUserSetFrames = "-fps";
const char* argPrintUsage = "-?";
void PrintUsage()
{
cout << argPrintUsage << " <Displays this usage information>" << endl;
cout << argNumImages << " <Optional. Sets number of images to stream>" << endl;
cout << argDuration << " <Optional. Sets time in seconds to stream>" << endl;
cout << argRelease << " <Optional. Calls Release() explicitly on grabbed image pointer if set>" << endl;
cout << argBayerRG
<< " <Optional. Sets Pixel Format to BayerRG 8 or BayerRG16 for color cameras, using 8 or 16 as "
"argument>"
<< endl;
cout << argPacketSize << " <Optional. Sets desired Packet Size>" << endl;
cout << argPacketDelay << " <Optional. Sets desired Packet Delay>" << endl;
cout << argMaxFrames << " <Optional. Sets AcquisitionFramerate to max>" << endl;
cout << argUserSetFrames << " <Optional. Sets desired AcquisitionFramerate>" << endl;
cout << endl;
}
bool ParseArguments(int argc, char* argv[])
{
cout << endl << "*** PARSING ARGUMENTS ***" << endl << endl;
cout << "Use '-?' to see list of supported arguments." << endl << endl;
if (argc == 1)
{
// Grabbing 100 images using maximum framerate by default.
cout << "Grabbing 100 images using maximum framerate..." << endl << endl;
// Continue with default parameters
return true;
}
for (int argument = 1; argument < argc; ++argument)
{
if (strncmp(argv[argument], argPrintUsage, strlen(argPrintUsage)) == 0)
{
// Print usage information
return false;
}
if (strncmp(argv[argument], argDuration, strlen(argDuration)) == 0)
{
if (argument + 1 <= argc)
{
UseDuration = true;
TestDuration = atoi(argv[argument + 1]);
argument++;
}
}
if (strncmp(argv[argument], argNumImages, strlen(argNumImages)) == 0)
{
if (argument + 1 <= argc)
{
UseDuration = false;
NumImagesToGrab = atoi(argv[argument + 1]);
argument++;
}
}
if (strncmp(argv[argument], argPacketSize, strlen(argPacketSize)) == 0)
{
if (argument + 1 <= argc)
{
PacketSizeToSet = atoi(argv[argument + 1]);
argument++;
}
}
if (strncmp(argv[argument], argPacketDelay, strlen(argPacketDelay)) == 0)
{
if (argument + 1 <= argc)
{
PacketDelayToSet = atoi(argv[argument + 1]);
argument++;
}
}
if (strncmp(argv[argument], argUserSetFrames, strlen(argUserSetFrames)) == 0)
{
if (argument + 1 <= argc)
{
UserSetFramerate = stof(argv[argument + 1]);
argument++;
}
}
if (strncmp(argv[argument], argBayerRG, strlen(argBayerRG)) == 0)
{
if (argument + 1 <= argc)
{
int bayerRG_bits = atoi(argv[argument + 1]);
switch (bayerRG_bits)
{
case 8:
PixelFormatToSet = "BayerRG8";
break;
case 16:
PixelFormatToSet = "BayerRG16";
break;
default:
cout << "User did not specify BayerRG 8 or BayerRG 16" << endl << endl;
}
cout << "Using Pixel Format: " << PixelFormatToSet << endl << endl;
argument++;
}
}
if (strncmp(argv[argument], argRelease, strlen(argRelease)) == 0)
{
IsRelease = true;
}
if (strncmp(argv[argument], argMaxFrames, strlen(argMaxFrames)) == 0)
{
}
}
return true;
}
void getCameraCategory(INodeMap& nodeMap, string categoryString)
{
try
{
stringstream cameraFeaturesFromCategoryStream;
cout << endl << "*** Get Camera Config.. " << categoryString << endl;
FeatureList_t features;
CCategoryPtr category = nodeMap.GetNode(categoryString.c_str());
category->GetFeatures(features);
FeatureList_t::const_iterator it;
for (it = features.begin(); it != features.end(); ++it)
{
CNodePtr pfeatureNode = *it;
CValuePtr pValue = (CValuePtr)pfeatureNode;
if (IsReadable(pValue))
{
gcstring featureName = pfeatureNode->GetName();
gcstring sensorString = pValue->ToString();
cameraFeaturesFromCategoryStream << pfeatureNode->GetName() << " : ";
cameraFeaturesFromCategoryStream << sensorString;
cameraFeaturesFromCategoryStream << endl;
}
}
std::string stringToReturn = cameraFeaturesFromCategoryStream.str();
cout << stringToReturn << endl;
}
{
cout << "Exception in getCameraCategory():" << e.what() << endl;
}
}
{
try
{
cout << endl << endl << "*** DATASTREAM STATS ***" << endl << endl;
stringstream outSS;
// Get model name
const TransportLayerStream& camStreamInfo = pCamera->TLStream;
if (IsReadable(camStreamInfo.StreamID))
{
outSS << "Stream ID: " << camStreamInfo.StreamID.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamType))
{
outSS << "Stream Type: " << camStreamInfo.StreamType.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamMode))
{
outSS << "Stream Mode: " << camStreamInfo.StreamMode.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamBufferCountResult))
{
outSS << "Stream Buffer Count: " << camStreamInfo.StreamBufferCountResult.ToString() << endl;
}
{
outSS << "Stream Buffer Handling Mode: " << camStreamInfo.StreamBufferHandlingMode.ToString() << endl;
}
{
outSS << "Stream Announced Buffer Minimum: " << camStreamInfo.StreamAnnounceBufferMinimum.ToString()
<< endl;
}
{
outSS << "Stream Announced Buffer Count: " << camStreamInfo.StreamAnnouncedBufferCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamStartedFrameCount))
{
outSS << "Stream Started Frame Count: " << camStreamInfo.StreamStartedFrameCount.ToString() << endl;
}
{
outSS << "Stream Delivered Frame Count: " << camStreamInfo.StreamDeliveredFrameCount.ToString() << endl;
}
{
outSS << "Stream Incomplete Frame Count: " << camStreamInfo.StreamIncompleteFrameCount.ToString() << endl;
}
{
outSS << "Stream Received Frame Count: " << camStreamInfo.StreamReceivedFrameCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamLostFrameCount))
{
outSS << "Stream Lost Frame Count: " << camStreamInfo.StreamLostFrameCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamDroppedFrameCount))
{
outSS << "Stream Dropped Frame Count: " << camStreamInfo.StreamDroppedFrameCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamInputBufferCount))
{
outSS << "Stream Input Buffer Count: " << camStreamInfo.StreamInputBufferCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamOutputBufferCount))
{
outSS << "Stream Output Buffer Count: " << camStreamInfo.StreamOutputBufferCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamChunkCountMaximum))
{
outSS << "Stream Chunk Maximum: " << camStreamInfo.StreamChunkCountMaximum.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamCRCCheckEnable))
{
outSS << "Stream CRC Check Enable: " << camStreamInfo.StreamCRCCheckEnable.ToString() << endl;
}
{
outSS << "Stream Received Packet Count: " << camStreamInfo.StreamReceivedPacketCount.ToString() << endl;
}
if (IsReadable(camStreamInfo.StreamMissedPacketCount))
{
outSS << "Stream Incomplete Packet Count: " << camStreamInfo.StreamMissedPacketCount.ToString() << endl;
}
{
outSS << "Stream Packet Resend Enable: " << camStreamInfo.StreamPacketResendEnable.ToString() << endl;
}
{
outSS << "Stream Packet Resend Timeout: " << camStreamInfo.StreamPacketResendTimeout.ToString() << endl;
}
{
outSS << "Stream Packet Resend Max Requests: " << camStreamInfo.StreamPacketResendMaxRequests.ToString()
<< endl;
}
{
outSS << "Stream Packet Resend Request Count: " << camStreamInfo.StreamPacketResendRequestCount.ToString()
<< endl;
}
{
outSS << "Stream Packet Resend Request Success Count: "
<< camStreamInfo.StreamPacketResendRequestTimeoutCount.ToString() << endl;
}
{
outSS << "Stream Packet Resend Requested Packet Count: "
<< camStreamInfo.StreamPacketResendRequestedPacketCount.ToString() << endl;
}
{
outSS << "Stream Packet Resend Received Packet Count: "
<< camStreamInfo.StreamPacketResendReceivedPacketCount.ToString() << endl;
}
{
outSS << "Stream Packets Duplicated Count: " << camStreamInfo.StreamPacketsDuplicatedCount.ToString()
<< endl;
}
{
outSS << "Stream Packets Timeout Count: " << camStreamInfo.StreamPacketsTimeoutCount.ToString() << endl;
}
{
outSS << "Stream Packets Not Yet Available Count: "
<< camStreamInfo.StreamPacketsNotYetAvailableCount.ToString() << endl;
}
{
outSS << "Stream Packets Temporarily Unavailable Count: "
<< camStreamInfo.StreamPacketsTemporarilyUnavailableCount.ToString() << endl;
}
{
outSS << "Stream Packets Per Frame Count: " << camStreamInfo.StreamPacketsPerFrameCount.ToString() << endl;
}
{
outSS << "Stream Packets Unavailable Count: " << camStreamInfo.StreamPacketsUnavailableCount.ToString()
<< endl;
}
cout << outSS.str() << endl;
}
{
cout << "Problem reading device info : " << e.GetError() << " - " << e.GetErrorMessage() << endl;
}
}
// This function acquires and saves x images from a device.
int AcquireImages(CameraPtr pCam, INodeMap& nodeMap, INodeMap& nodeMapGenTL, int numImagesToAcquire, int iteration)
{
int result = 0;
cout << endl << endl << "*** ACQUIRING " << numImagesToAcquire << " IMAGES ***" << endl << endl;
try
{
// Retrieve enumeration node from nodemap
CEnumerationPtr ptrAcquisitionMode = nodeMap.GetNode("AcquisitionMode");
if (!IsReadable(ptrAcquisitionMode) || !IsWritable(ptrAcquisitionMode))
{
cout << "Unable to set acquisition mode to continuous (enum retrieval). Aborting..." << endl << endl;
return -1;
}
// Retrieve entry node from enumeration node
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName("Continuous");
if (!IsReadable(ptrAcquisitionModeContinuous))
{
cout << "Unable to set acquisition mode to continuous (entry retrieval). Aborting..." << endl << endl;
return -1;
}
// Retrieve integer value from entry node
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
// Set integer value from entry node as new value of enumeration node
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "Acquisition mode set to Continuous..." << endl;
// Begin acquiring images
pCam->BeginAcquisition();
cout << "Acquiring images..." << endl;
const unsigned int k_numImages = numImagesToAcquire;
ImagePtr pResultImage;
// Start Capturing CPU Stats
for (unsigned int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
{
try
{
pResultImage = pCam->GetNextImage(1000);
if (IsRelease)
{
pResultImage->Release();
}
}
{
cout << "Error: " << e.what() << endl;
result = -1;
}
}
// Stop Capturing CPU Stats
// Fetch CPU Stats
// End Acquisition
pCam->EndAcquisition();
cout << "Finished acquiring images..." << endl;
}
{
cout << "Error: " << e.what() << endl;
result = -1;
}
return result;
}
// This function prints the device information of the camera from the transport
// layer; please see NodeMapInfo example for more in-depth comments on printing
// device information from the nodemap.
int PrintDeviceInfo(INodeMap& nodeMap)
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
CCategoryPtr category = nodeMap.GetNode("DeviceInformation");
if (IsReadable(category))
{
category->GetFeatures(features);
FeatureList_t::const_iterator it;
for (it = features.begin(); it != features.end(); ++it)
{
CNodePtr pfeatureNode = *it;
cout << pfeatureNode->GetName() << " : ";
CValuePtr pValue = (CValuePtr)pfeatureNode;
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;
}
{
cout << endl << "*** CPU USAGE STATS ***" << endl << endl;
stringstream outSS;
outSS << "Kernel Time: " << cpuUsageInfo.kernelSystemTime.wHour << "H"
<< ":" << cpuUsageInfo.kernelSystemTime.wMinute << "M"
<< ":" << cpuUsageInfo.kernelSystemTime.wSecond << "S"
<< ":" << cpuUsageInfo.kernelSystemTime.wMilliseconds << "ms"
<< "\n";
outSS << "User Time: " << cpuUsageInfo.userSystemTime.wHour << "H"
<< ":" << cpuUsageInfo.userSystemTime.wMinute << "M"
<< ":" << cpuUsageInfo.userSystemTime.wSecond << "S"
<< ":" << cpuUsageInfo.userSystemTime.wMilliseconds << "ms"
<< "\n";
outSS << "Kernel Time: "
<< ((cpuUsageInfo.kernelSystemTime.wHour * 60 * 60 * 1000) +
(cpuUsageInfo.kernelSystemTime.wMinute * 60 * 1000) + (cpuUsageInfo.kernelSystemTime.wSecond * 1000) +
(cpuUsageInfo.kernelSystemTime.wMilliseconds))
<< "ms"
<< "\n";
outSS << "User Time: "
<< ((cpuUsageInfo.userSystemTime.wHour * 60 * 60 * 1000) + (cpuUsageInfo.userSystemTime.wMinute * 60 * 1000) +
(cpuUsageInfo.userSystemTime.wSecond * 1000) + (cpuUsageInfo.userSystemTime.wMilliseconds))
<< "ms"
<< "\n";
outSS << "CPU Usage: " << cpuUsageInfo.cpuPercentage << "%\n";
outSS << "Total Time: " << cpuUsageInfo.elapsedTime << " seconds"
<< "\n";
cout << outSS.str() << endl;
}
{
INodeMap& nodeMap = pCam->GetNodeMap();
INodeMap& nodeMapDevice = pCam->GetTLDeviceNodeMap();
INodeMap& nodeMapStream = pCam->GetTLStreamNodeMap();
PrintDeviceInfo(nodeMap);
PrintDeviceInfo(nodeMapDevice);
PrintDeviceInfo(nodeMapStream);
}
{
INodeMap& NodeMap = pCam->GetNodeMap();
// Turning AcquisitionFrameRateEnable on
CBooleanPtr ptrFrameRateEnable = NodeMap.GetNode("AcquisitionFrameRateEnable");
if (ptrFrameRateEnable == nullptr)
{
// AcquisitionFrameRateEnabled is used for Gen2 devices
ptrFrameRateEnable = NodeMap.GetNode("AcquisitionFrameRateEnabled");
}
if (IsWritable(ptrFrameRateEnable))
{
ptrFrameRateEnable->SetValue(true);
cout << "AcquisitionFrameRateEnable set to True" << endl;
}
// Turning AcquisitionFrameRateAuto off
CEnumerationPtr ptrFrameRateAuto = NodeMap.GetNode("AcquisitionFrameRateAuto");
if (!IsReadable(ptrFrameRateAuto) || !IsWritable(ptrFrameRateAuto))
{
cout << "Unable to get or set AcquisitionFrameRateAuto..." << endl << endl;
return false;
}
CEnumEntryPtr ptrFrameRateAutoModeOff = ptrFrameRateAuto->GetEntryByName("Off");
if (!IsReadable(ptrFrameRateAutoModeOff))
{
cout << "Unable to get AcquisitionFrameRateAuto to OFF. Aborting..." << endl << endl;
return false;
}
// Retrieve integer value from entry node
const int64_t valueFrameRateAutoOff = ptrFrameRateAutoModeOff->GetValue();
// Set integer value from entry node as new value of enumeration node
ptrFrameRateAuto->SetIntValue(valueFrameRateAutoOff);
cout << "AcquisitionFrameRateAuto set to OFF" << endl;
return true;
}
{
//-IsMaxFrameRate
{
try
{
cout << "Setting maximum framerate" << endl;
INodeMap& nodeMap = pCam->GetNodeMap();
// Set AcquisitionFrameRate to maximum
CFloatPtr AcquisitionFrameRateNode = nodeMap.GetNode("AcquisitionFrameRate");
if (!IsReadable(AcquisitionFrameRateNode) || !IsWritable(AcquisitionFrameRateNode))
{
cout << "Unable to get or set AcquisitionFrameRate to Max. Aborting..." << endl << endl;
return false;
}
AcquisitionFrameRateNode->SetValue(AcquisitionFrameRateNode->GetMax());
}
{
cout << "Exception setting FrameRate to maximum: " << e.what() << endl;
}
return true;
}
// User set framerate
else if (UserSetFramerate > 0)
{
try
{
cout << "Setting framerate to: " << UserSetFramerate << endl << endl;
INodeMap& nodeMap = pCam->GetNodeMap();
// Set AcquisitionFrameRate to user defined value
CFloatPtr AcquisitionFrameRateNode = nodeMap.GetNode("AcquisitionFrameRate");
if (!IsWritable(AcquisitionFrameRateNode))
{
cout << "Unable to set AcquisitionFrameRate to " << UserSetFramerate << ". Aborting..." << endl << endl;
return false;
}
AcquisitionFrameRateNode->SetValue(UserSetFramerate);
}
{
cout << "Exception setting framerate: " << e.what() << endl;
}
return true;
}
return false;
}
// This function acts as the body of the example; please see NodeMapInfo example
// for more in-depth comments on setting up cameras.
{
int result = 0;
try
{
// Retrieve GenTL nodemap and print device information
INodeMap& nodeMapGenTL = pCam->GetTLDeviceNodeMap();
result = PrintDeviceInfo(nodeMapGenTL);
cout << endl << endl << "*** INITIALIZING DEVICE ***" << endl << endl;
// Initialize camera
pCam->Init();
// Retrieve GenICam nodemap
INodeMap& nodeMap = pCam->GetNodeMap();
// set the packet size
try
{
cout << "Setting the Packet Size to: " << PacketSizeToSet << endl << endl;
CIntegerPtr PacketSizeNode = nodeMap.GetNode("GevSCPSPacketSize");
if (!IsWritable(PacketSizeNode))
{
cout << "Unable to set Packet Size to: " << PacketSizeToSet << ". Aborting..." << endl << endl;
}
PacketSizeNode->SetValue(PacketSizeToSet);
cout << "Setting the Packet Delay to: " << PacketDelayToSet << endl << endl;
CIntegerPtr PacketDelayNode = nodeMap.GetNode("GevSCPD");
if (!IsWritable(PacketDelayNode))
{
cout << "Unable to set Packet Delay to: " << PacketDelayToSet << ". Aborting..." << endl << endl;
}
PacketDelayNode->SetValue(PacketDelayToSet);
}
{
cout << "Exception setting packet size to " << PacketSizeToSet << ". Exception: " << e.what() << endl;
}
// Set pixel format
try
{
{
cout << "Setting Pixel Format to: " << PixelFormatToSet << endl << endl;
CEnumerationPtr PixalFormatNode = nodeMap.GetNode("PixelFormat");
if (!IsReadable(PixalFormatNode))
{
cout << "Unable to read PixalFormat. Aborting..." << endl << endl;
return false;
}
CEnumEntryPtr PixelFormat_entry = PixalFormatNode->GetEntryByName(PixelFormatToSet);
if (!IsWritable(PixalFormatNode))
{
cout << "Unable to set PixalFormat to: " << PixelFormatToSet << ". Aborting..." << endl << endl;
return false;
}
PixalFormatNode->SetIntValue(PixelFormat_entry->GetValue());
}
}
{
cout << "Exception setting Pixel Format to " << PixelFormatToSet << e.what() << endl;
}
// Setting exposure time
try
{
try
{
cout << endl << "Turning off ExposureAuto..." << endl;
CEnumerationPtr ExposureModeNode = nodeMap.GetNode("ExposureAuto");
if (!IsWritable(ExposureModeNode))
{
cout << "Unable to turn off ExposureAuto. Aborting..." << endl << endl;
return false;
}
ExposureModeNode->SetIntValue(0);
}
catch (Exception e)
{
cout << "Exception setting ExposureAuto to Off. Exception: " << e.what() << endl;
}
cout << endl << "Setting minimum Exposure Time" << endl;
CFloatPtr ExposureTimeNode = nodeMap.GetNode("ExposureTime");
if (!IsReadable(ExposureTimeNode) || !IsWritable(ExposureTimeNode))
{
cout << "Unable to get or set ExposureTime to minimum. Aborting..." << endl << endl;
return false;
}
ExposureTimeNode->SetValue(ExposureTimeNode->GetMin() + 10);
}
{
cout << "Exception setting minimum exposure time. Exception: " << e.what() << endl;
}
// Set FrameRate
SetFrameRate(pCam);
{
cout << "Streaming for duration of: " << TestDuration << " seconds" << endl;
// Get FrameRate
INodeMap& nodeMap = pCam->GetNodeMap();
CFloatPtr AcquisitionFrameRateNode = nodeMap.GetNode("AcquisitionFrameRate");
if (!IsReadable(AcquisitionFrameRateNode))
{
cout << "Unable to read AcquisitionFrameRate. Aborting..." << endl << endl;
return false;
}
double FrameRate = AcquisitionFrameRateNode->GetValue();
NumImagesToGrab = static_cast<int>(FrameRate * TestDuration);
}
// Acquire images
cout << "This iteration will stream: " << NumImagesToGrab << " images" << endl;
result = result | AcquireImages(pCam, nodeMap, nodeMapGenTL, NumImagesToGrab, 0);
// Print Data Stream Nodemap Information
// Print CPU Usage Stats
// Deinitialize camera
pCam->DeInit();
}
{
cout << "Error: " << e.what() << endl;
result = -1;
}
return result;
}
// Example entry point; please see Enumeration example for more in-depth
// comments on preparing and cleaning up the system.
int main(int argc, char* argv[])
{
// Print application build information
cout << "Application build date: " << __DATE__ << " " << __TIME__ << endl << endl;
// Parse arguments
if (!ParseArguments(argc, argv))
{
return -1;
}
int result = 0;
// Retrieve singleton reference to system object
SystemPtr system = System::GetInstance();
// Print out current library version
const LibraryVersion spinnakerLibraryVersion = system->GetLibraryVersion();
cout << "Spinnaker library version: " << spinnakerLibraryVersion.major << "." << spinnakerLibraryVersion.minor
<< "." << spinnakerLibraryVersion.type << "." << spinnakerLibraryVersion.build << endl
<< endl;
// Retrieve list of cameras from the system
CameraList camList = system->GetCameras();
unsigned int numCameras = camList.GetSize();
cout << "Number of cameras detected: " << numCameras << endl << endl;
// Finish if there are no cameras
if (numCameras == 0)
{
// Clear camera list before releasing system
camList.Clear();
// Release system
system->ReleaseInstance();
cout << "No cameras detected." << endl;
cout << "Done!" << endl;
// getchar();
return -1;
}
//
// Create shared pointer to camera
//
// *** NOTES ***
// The CameraPtr object is a shared pointer, and will generally clean itself
// up upon exiting its scope. However, if a shared pointer is created in the
// same scope that a system object is explicitly released (i.e. this scope),
// the reference to the shared point must be broken manually.
//
// *** LATER ***
// Shared pointers can be terminated manually by assigning them to nullptr.
// This keeps releasing the system from throwing an exception.
//
CameraPtr pCam = nullptr;
// Run example on each camera
for (unsigned int i = 0; i < numCameras; i++)
{
// Select camera
pCam = camList.GetByIndex(i);
cout << endl << "Running code for camera " << i << "..." << endl;
// Run example
result = result | RunSingleCamera(pCam);
cout << "Camera " << i << " complete..." << endl << endl;
}
//
// Release reference to the camera
//
// *** NOTES ***
// Had the CameraPtr object been created within the for-loop, it would not
// be necessary to manually break the reference because the shared pointer
// would have automatically cleaned itself up upon exiting the loop.
//
pCam = nullptr;
// Clear camera list before releasing system
camList.Clear();
// Release system
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return result;
}
int AcquireImages(CameraPtr pCam, INodeMap &nodeMap, INodeMap &nodeMapTLDevice)
Definition Acquisition.cpp:199
int main(int, char **)
Definition Acquisition.cpp:527
int RunSingleCamera(CameraPtr pCam)
Definition Acquisition.cpp:479
int PrintDeviceInfo(INodeMap &nodeMap)
Definition Acquisition.cpp:441
const unsigned int k_numImages
Definition AcquisitionMultipleCamerasWriteToFile.cpp:55
void PrintUsage()
Definition FileAccess_QuickSpin.cpp:1019
const char * argPrintUsage
Definition GigEVisionPerformance.cpp:64
const char * argBayerRG
Definition GigEVisionPerformance.cpp:59
char * PixelFormatToSet
Definition GigEVisionPerformance.cpp:46
void getCameraCategory(INodeMap &nodeMap, string categoryString)
Definition GigEVisionPerformance.cpp:186
const char * argMaxFrames
Definition GigEVisionPerformance.cpp:62
bool IsRelease
Definition GigEVisionPerformance.cpp:49
const char * argPacketDelay
Definition GigEVisionPerformance.cpp:61
CpuUtil::CpuUsageInfo cpuUsageInfo
Definition GigEVisionPerformance.cpp:41
int NumImagesToGrab
Definition GigEVisionPerformance.cpp:53
bool ParseArguments(int argc, char *argv[])
Definition GigEVisionPerformance.cpp:83
bool SetFrameRate(CameraPtr pCam)
Definition GigEVisionPerformance.cpp:593
void PrintCPUUsage()
Definition GigEVisionPerformance.cpp:504
int PacketSizeToSet
Definition GigEVisionPerformance.cpp:47
const char * argNumImages
Definition GigEVisionPerformance.cpp:56
bool UseDuration
Definition GigEVisionPerformance.cpp:50
int TestDuration
Definition GigEVisionPerformance.cpp:45
const char * argUserSetFrames
Definition GigEVisionPerformance.cpp:63
void PrintDataStreamInfo(const Spinnaker::CameraPtr pCamera)
Definition GigEVisionPerformance.cpp:225
const char * argRelease
Definition GigEVisionPerformance.cpp:58
bool EnableManualFramerate(CameraPtr pCam)
Definition GigEVisionPerformance.cpp:548
int PacketDelayToSet
Definition GigEVisionPerformance.cpp:48
float UserSetFramerate
Definition GigEVisionPerformance.cpp:52
bool UseMaxFramerate
Definition GigEVisionPerformance.cpp:51
const char * argPacketSize
Definition GigEVisionPerformance.cpp:60
const char * argDuration
Definition GigEVisionPerformance.cpp:57
void PrintAllNodes(CameraPtr pCam)
Definition GigEVisionPerformance.cpp:538
Used to hold a list of camera objects.
Definition CameraList.h:42
void Clear()
Clears the list of cameras and destroys their corresponding reference counted objects.
CameraPtr GetByIndex(unsigned int index) const
Returns a pointer to a camera object at the "index".
unsigned int GetSize() const
Returns the size of the camera list.
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
Error GetError() const
virtual const char * what() const
virtual override for what().
const char * GetErrorMessage() const
Accessor Functions.
SmartPointer for IFloat interface pointer.
Definition Pointer.h:421
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:75
Smart pointer template for NodeMaps with create function.
Definition NodeMap.h:69
virtual INode * GetNode(const GenICam::gcstring &key) const
Retrieves the node from the central map by name.
Definition GCString.h:43
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
Part of the QuickSpin API to provide access to camera information without having to first initialize ...
Definition TransportLayerStream.h:45
GenApi::IEnumerationT< StreamTypeEnum > & StreamType
Description: Stream type of the device.
Definition TransportLayerStream.h:69
GenApi::IInteger & StreamReceivedPacketCount
Description: Displays number of packets received on this stream.
Definition TransportLayerStream.h:195
GenApi::IInteger & StreamOutputBufferCount
Description: Number of buffers in the output buffer queue.
Definition TransportLayerStream.h:165
GenApi::IString & StreamID
Description: Device unique ID for the data stream, e.g.
Definition TransportLayerStream.h:63
GenApi::IInteger & StreamPacketsTimeoutCount
Description: Number of packets not received before the inter-packet timeout expired.
Definition TransportLayerStream.h:255
GenApi::IInteger & StreamStartedFrameCount
Description: Number of frames started in the acquisition engine.
Definition TransportLayerStream.h:123
GenApi::IInteger & StreamPacketsTemporarilyUnavailableCount
Description: Number of packets temporarily unavailable on the streaming device.
Definition TransportLayerStream.h:267
GenApi::IInteger & StreamPacketsPerFrameCount
Description: Number of packets per frame.
Definition TransportLayerStream.h:273
GenApi::IInteger & StreamDroppedFrameCount
Description: Number of frames dropped from the output buffer queue before being processed by the appl...
Definition TransportLayerStream.h:153
GenApi::IInteger & StreamAnnounceBufferMinimum
Description: Minimal number of buffers to announce to enable selected buffer handling mode.
Definition TransportLayerStream.h:111
GenApi::IBoolean & StreamCRCCheckEnable
Description: Enables or disables CRC checks on received images.
Definition TransportLayerStream.h:189
GenApi::IInteger & StreamIncompleteFrameCount
Description: Displays number of images with missing packet.
Definition TransportLayerStream.h:141
GenApi::IBoolean & StreamPacketResendEnable
Description: Enables or disables the packet resend mechanism.
Definition TransportLayerStream.h:207
GenApi::IInteger & StreamPacketsUnavailableCount
Description: Number of missing packets no more available on the streaming device.
Definition TransportLayerStream.h:279
GenApi::IInteger & StreamPacketResendRequestCount
Description: Displays number of packet resend requests transmitted to the camera.
Definition TransportLayerStream.h:225
GenApi::IInteger & StreamPacketResendTimeout
Description: Time in milliseconds to wait after the image trailer is received and before the image is...
Definition TransportLayerStream.h:213
GenApi::IInteger & StreamMissedPacketCount
Description: Displays number of packets missed by this stream.
Definition TransportLayerStream.h:201
GenApi::IEnumerationT< StreamBufferHandlingModeEnum > & StreamBufferHandlingMode
Description: Available buffer handling modes of this data stream: Visibility: Beginner.
Definition TransportLayerStream.h:105
GenApi::IInteger & StreamBufferCountResult
Description: Displays the number of buffers to be used on this stream upon acquisition start.
Definition TransportLayerStream.h:87
GenApi::IInteger & StreamPacketResendRequestTimeoutCount
Description: Number of resend requests not fully fulfilled before the resend request timeout expired.
Definition TransportLayerStream.h:231
GenApi::IInteger & StreamPacketsNotYetAvailableCount
Description: Number of packets not yet available on the streaming device.
Definition TransportLayerStream.h:261
GenApi::IInteger & StreamPacketsDuplicatedCount
Description: Number of duplicate packets received from the streaming device.
Definition TransportLayerStream.h:249
GenApi::IInteger & StreamInputBufferCount
Description: Number of buffers in the input buffer pool plus the buffers(s) currently being filled.
Definition TransportLayerStream.h:159
GenApi::IEnumerationT< StreamModeEnum > & StreamMode
Description: Stream mode of the device.
Definition TransportLayerStream.h:75
GenApi::IInteger & StreamChunkCountMaximum
Description: Maximum number of chunks to be expected in a buffer.
Definition TransportLayerStream.h:177
GenApi::IInteger & StreamPacketResendMaxRequests
Description: Maximum number of resend requests per image.
Definition TransportLayerStream.h:219
GenApi::IInteger & StreamLostFrameCount
Description: Number of times new data could not be acquired and was lost because there was no free bu...
Definition TransportLayerStream.h:147
GenApi::IInteger & StreamAnnouncedBufferCount
Description: Number of announced (known) buffers on this stream.
Definition TransportLayerStream.h:117
GenApi::IInteger & StreamDeliveredFrameCount
Description: Number of delivered frames since last acquisition start.
Definition TransportLayerStream.h:129
GenApi::IInteger & StreamPacketResendReceivedPacketCount
Description: Displays number of retransmitted packets received on this stream.
Definition TransportLayerStream.h:243
GenApi::IInteger & StreamReceivedFrameCount
Description: Number of successful GVSP data blocks received.
Definition TransportLayerStream.h:135
GenApi::IInteger & StreamPacketResendRequestedPacketCount
Description: Displays number of packets requested to be retransmitted on this stream.
Definition TransportLayerStream.h:237
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
bool StartCpuTracing(CpuUsageInfo *cpuUsage)
Definition CpuUtil.cpp:128
bool StopCpuTracing(CpuUsageInfo *cpuUsage)
Definition CpuUtil.cpp:133
std::string GetCpuStats(CpuUsageInfo *cpuUsage)
Definition CpuUtil.cpp:138
Definition Autovector.h:36
Definition GCString.h:31
Definition BasePtr.h:24
Definition CpuUtil.h: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