This example measures CPU related performance statistics and print them out at the end.
#include <iostream>
#include <sstream>
#include <sys/types.h>
using namespace std;
{
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;
<< " <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;
}
{
cout << endl << "*** PARSING ARGUMENTS ***" << endl << endl;
cout << "Use '-?' to see list of supported arguments." << endl << endl;
if (argc == 1)
{
cout << "Grabbing 100 images using maximum framerate..." << endl << endl;
return true;
}
for (int argument = 1; argument < argc; ++argument)
{
{
return false;
}
{
if (argument + 1 <= argc)
{
argument++;
}
}
{
if (argument + 1 <= argc)
{
argument++;
}
}
{
if (argument + 1 <= argc)
{
argument++;
}
}
{
if (argument + 1 <= argc)
{
argument++;
}
}
{
if (argument + 1 <= argc)
{
argument++;
}
}
{
if (argument + 1 <= argc)
{
int bayerRG_bits = atoi(argv[argument + 1]);
switch (bayerRG_bits)
{
case 8:
break;
case 16:
break;
default:
cout << "User did not specify BayerRG 8 or BayerRG 16" << endl << endl;
}
argument++;
}
}
{
}
{
}
}
return true;
}
{
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)
{
{
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;
{
outSS <<
"Stream ID: " << camStreamInfo.
StreamID.ToString() << endl;
}
{
outSS <<
"Stream Type: " << camStreamInfo.
StreamType.ToString() << endl;
}
{
outSS <<
"Stream Mode: " << camStreamInfo.
StreamMode.ToString() << endl;
}
{
}
{
}
{
<< endl;
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
<< endl;
}
{
<< endl;
}
{
outSS << "Stream Packet Resend Request Success Count: "
}
{
outSS << "Stream Packet Resend Requested Packet Count: "
}
{
outSS << "Stream Packet Resend Received Packet Count: "
}
{
<< endl;
}
{
}
{
outSS << "Stream Packets Not Yet Available Count: "
}
{
outSS << "Stream Packets Temporarily Unavailable Count: "
}
{
}
{
<< endl;
}
cout << outSS.str() << endl;
}
{
}
}
int AcquireImages(
CameraPtr pCam, INodeMap& nodeMap, INodeMap& nodeMapGenTL,
int numImagesToAcquire,
int iteration)
{
int result = 0;
cout << endl << endl << "*** ACQUIRING " << numImagesToAcquire << " IMAGES ***" << 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 set acquisition mode to continuous (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;
for (
unsigned int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
try
{
pResultImage = pCam->GetNextImage(1000);
{
pResultImage->Release();
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
}
pCam->EndAcquisition();
cout << "Finished acquiring images..." << 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;
}
{
cout << endl << "*** CPU USAGE STATS ***" << endl << endl;
stringstream outSS;
outSS <<
"Kernel Time: " <<
cpuUsageInfo.kernelSystemTime.wHour <<
"H"
<<
":" <<
cpuUsageInfo.kernelSystemTime.wMilliseconds <<
"ms"
<< "\n";
outSS <<
"User Time: " <<
cpuUsageInfo.userSystemTime.wHour <<
"H"
<< "\n";
outSS << "Kernel Time: "
<< ((
cpuUsageInfo.kernelSystemTime.wHour * 60 * 60 * 1000) +
<< "ms"
<< "\n";
outSS << "User Time: "
<< "ms"
<< "\n";
outSS <<
"CPU Usage: " <<
cpuUsageInfo.cpuPercentage <<
"%\n";
outSS <<
"Total Time: " <<
cpuUsageInfo.elapsedTime <<
" seconds"
<< "\n";
cout << outSS.str() << endl;
}
{
INodeMap& nodeMapDevice = pCam->GetTLDeviceNodeMap();
INodeMap& nodeMapStream = pCam->GetTLStreamNodeMap();
}
{
if (ptrFrameRateEnable == nullptr)
{
}
{
ptrFrameRateEnable->SetValue(true);
cout << "AcquisitionFrameRateEnable set to True" << endl;
}
{
cout << "Unable to get or set AcquisitionFrameRateAuto..." << endl << endl;
return false;
}
CEnumEntryPtr ptrFrameRateAutoModeOff = ptrFrameRateAuto->GetEntryByName(
"Off");
{
cout << "Unable to get AcquisitionFrameRateAuto to OFF. Aborting..." << endl << endl;
return false;
}
const int64_t valueFrameRateAutoOff = ptrFrameRateAutoModeOff->GetValue();
ptrFrameRateAuto->SetIntValue(valueFrameRateAutoOff);
cout << "AcquisitionFrameRateAuto set to OFF" << endl;
return true;
}
{
{
try
{
cout << "Setting maximum framerate" << endl;
CFloatPtr AcquisitionFrameRateNode = nodeMap.GetNode(
"AcquisitionFrameRate");
{
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;
}
{
try
{
CFloatPtr AcquisitionFrameRateNode = nodeMap.GetNode(
"AcquisitionFrameRate");
{
cout <<
"Unable to set AcquisitionFrameRate to " <<
UserSetFramerate <<
". Aborting..." << endl << endl;
return false;
}
}
{
cout <<
"Exception setting framerate: " << e.
what() << endl;
}
return true;
}
return false;
}
{
int result = 0;
try
{
INodeMap& nodeMapGenTL = pCam->GetTLDeviceNodeMap();
cout << endl << endl << "*** INITIALIZING DEVICE ***" << endl << endl;
pCam->Init();
try
{
CIntegerPtr PacketSizeNode = nodeMap.GetNode(
"GevSCPSPacketSize");
{
cout <<
"Unable to set Packet Size to: " <<
PacketSizeToSet <<
". Aborting..." << endl << endl;
}
CIntegerPtr PacketDelayNode = nodeMap.GetNode(
"GevSCPD");
{
cout <<
"Unable to set Packet Delay to: " <<
PacketDelayToSet <<
". Aborting..." << endl << endl;
}
}
{
cout <<
"Exception setting packet size to " <<
PacketSizeToSet <<
". Exception: " << e.
what() << endl;
}
try
{
{
{
cout << "Unable to read PixalFormat. Aborting..." << endl << endl;
return false;
}
{
cout <<
"Unable to set PixalFormat to: " <<
PixelFormatToSet <<
". Aborting..." << endl << endl;
return false;
}
PixalFormatNode->SetIntValue(PixelFormat_entry->GetValue());
}
}
{
}
try
{
try
{
cout << endl << "Turning off ExposureAuto..." << endl;
{
cout << "Unable to turn off ExposureAuto. Aborting..." << endl << endl;
return false;
}
ExposureModeNode->SetIntValue(0);
}
{
cout <<
"Exception setting ExposureAuto to Off. Exception: " << e.
what() << endl;
}
cout << endl << "Setting minimum Exposure Time" << endl;
CFloatPtr ExposureTimeNode = nodeMap.GetNode(
"ExposureTime");
{
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;
}
{
cout <<
"Streaming for duration of: " <<
TestDuration <<
" seconds" << endl;
CFloatPtr AcquisitionFrameRateNode = nodeMap.GetNode(
"AcquisitionFrameRate");
{
cout << "Unable to read AcquisitionFrameRate. Aborting..." << endl << endl;
return false;
}
double FrameRate = AcquisitionFrameRateNode->GetValue();
}
cout <<
"This iteration will stream: " <<
NumImagesToGrab <<
" images" << endl;
pCam->DeInit();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
int main(
int argc,
char* argv[])
{
cout << "Application build date: " << __DATE__ << " " << __TIME__ << endl << endl;
{
return -1;
}
int result = 0;
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 << "No cameras detected." << endl;
cout << "Done!" << endl;
return -1;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running code for camera " << i << "..." << endl;
cout << "Camera " << i << " complete..." << endl << endl;
}
pCam = nullptr;
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
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
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.
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
Provides easier access to the current version of Spinnaker.
Definition SpinnakerDefs.h:657
unsigned int minor
Minor version of the library.
Definition SpinnakerDefs.h:662
unsigned int major
Major version of the library.
Definition SpinnakerDefs.h:659
unsigned int type
Version type of the library.
Definition SpinnakerDefs.h:665
unsigned int build
Build number of the library.
Definition SpinnakerDefs.h:668