This example is similar to the Acquisition example, except that threads are used to allow for simultaneous acquisitions.
#include <iostream>
#include <sstream>
#ifndef _WIN32
#include <pthread.h>
#endif
using namespace std;
{
int result = 0;
cout << "[" << camSerial << "] Printing device information ..." << endl << endl;
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)
{
cout << "[" << camSerial << "] " << pfeatureNode->GetName() << " : "
<< (IsReadable(pValue) ? pValue->ToString() : "Node not readable") << endl;
}
}
else
{
cout << "[" << camSerial << "] "
<< "Device control information not readable." << endl;
}
cout << endl;
return result;
}
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
INodeMap& nodeMap = pCam->GetNodeMap();
if (!IsReadable(ptrDeviceType))
{
return -1;
}
if (ptrDeviceType->GetIntValue() != DeviceType_GigEVision)
{
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;
}
{
}
{
}
#if defined(_WIN32)
{
#else
{
#endif
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
CStringPtr ptrStringSerial = nodeMapTLDevice.GetNode(
"DeviceSerialNumber");
std::string serialNumber = "";
{
serialNumber = ptrStringSerial->GetValue();
}
cout << endl
<< "[" << serialNumber << "] "
<< "*** IMAGE ACQUISITION THREAD STARTING"
<< " ***" << endl
<< endl;
pCam->Init();
#ifdef _DEBUG
#else
#endif
{
#if defined(_WIN32)
return 0;
#else
return (void*)0;
#endif
}
{
cout << "Unable to set acquisition mode to continuous (node retrieval; camera " << serialNumber
<< "). Aborting..." << endl
<< endl;
#if defined(_WIN32)
return 0;
#else
return (void*)0;
#endif
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to get acquisition mode to continuous (entry 'continuous' retrieval " << serialNumber
<< "). Aborting..." << endl
<< endl;
#if defined(_WIN32)
return 0;
#else
return (void*)0;
#endif
}
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "[" << serialNumber << "] "
<< "Acquisition mode set to continuous..." << endl;
pCam->BeginAcquisition();
cout << "[" << serialNumber << "] "
<< "Started acquiring images..." << endl;
cout << endl;
for (
unsigned int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
try
{
ImagePtr pResultImage = pCam->GetNextImage(1000);
if (pResultImage->IsIncomplete())
{
cout << "[" << serialNumber << "] "
<< "Image incomplete with image status " << pResultImage->GetImageStatus() << "..." << endl
<< endl;
}
else
{
ImagePtr convertedImage = processor.
Convert(pResultImage, PixelFormat_Mono8);
std::ostringstream filename;
filename << "AcquisitionMultipleThread-";
if (serialNumber != "")
{
filename << serialNumber.c_str();
}
filename << "-" << imageCnt << ".jpg";
convertedImage->Save(filename.str().c_str());
cout << "[" << serialNumber << "] "
<< "Grabbed image " << imageCnt << ", width = " << pResultImage->GetWidth()
<< ", height = " << pResultImage->GetHeight() << ". Image saved at " << filename.str() << endl;
}
pResultImage->Release();
cout << endl;
}
{
cout << "[" << serialNumber << "] "
<<
"Error: " << e.
what() << endl;
}
}
pCam->EndAcquisition();
#ifdef _DEBUG
#endif
pCam->DeInit();
#if defined(_WIN32)
return 1;
#else
return (void*)1;
#endif
}
{
cout <<
"Error: " << e.
what() << endl;
#if defined(_WIN32)
return 0;
#else
return (void*)0;
#endif
}
}
{
int result = 0;
unsigned int camListSize = 0;
try
{
#if defined(_WIN32)
HANDLE* grabThreads = new HANDLE[camListSize];
#else
pthread_t* grabThreads = new pthread_t[camListSize];
#endif
for (unsigned int i = 0; i < camListSize; i++)
{
#if defined(_WIN32)
grabThreads[i] = CreateThread(
nullptr, 0,
AcquireImages, &pCamList[i], 0,
nullptr);
assert(grabThreads[i] != nullptr);
#else
int err = pthread_create(&(grabThreads[i]),
nullptr, &
AcquireImages, &pCamList[i]);
assert(err == 0);
#endif
}
#if defined(_WIN32)
WaitForMultipleObjects(
camListSize,
grabThreads,
TRUE,
INFINITE
);
for (unsigned int i = 0; i < camListSize; i++)
{
DWORD exitcode;
BOOL rc = GetExitCodeThread(grabThreads[i], &exitcode);
if (!rc)
{
cout << "Handle error from GetExitCodeThread() returned for camera at index " << i << endl;
result = -1;
}
else if (!exitcode)
{
cout << "Grab thread for camera at index " << i
<< " exited with errors."
"Please check onscreen print outs for error details"
<< endl;
result = -1;
}
}
#else
for (unsigned int i = 0; i < camListSize; i++)
{
void* exitcode;
int rc = pthread_join(grabThreads[i], &exitcode);
if (rc != 0)
{
cout << "Handle error from pthread_join returned for camera at index " << i << endl;
result = -1;
}
else if ((int)(intptr_t)exitcode == 0)
{
cout << "Grab thread for camera at index " << i
<< " exited with errors."
"Please check onscreen print outs for error details"
<< endl;
result = -1;
}
}
#endif
for (unsigned int i = 0; i < camListSize; i++)
{
pCamList[i] = 0;
#if defined(_WIN32)
CloseHandle(grabThreads[i]);
#endif
}
delete[] pCamList;
delete[] grabThreads;
}
{
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;
}
cout << endl << "Running example for all cameras..." << endl;
cout << "Example complete..." << endl << endl;
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:520
int ResetGVCPHeartbeat(CameraPtr pCam)
Definition Acquisition.cpp:138
int ConfigureGVCPHeartbeat(CameraPtr pCam, bool enableHeartbeat)
Definition Acquisition.cpp:68
int PrintDeviceInfo(INodeMap &nodeMap)
Definition Acquisition.cpp:434
int DisableGVCPHeartbeat(CameraPtr pCam)
Definition Acquisition.cpp:143
const unsigned int k_numImages
Definition AcquisitionMultipleCamerasWriteToFile.cpp:55
int RunMultipleCameras(CameraList camList)
Definition AcquisitionMultipleThread.cpp:362
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().
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:75
Image post processing class for converting a source image to another pixel format.
Definition ImageProcessor.h:159
void SetColorProcessing(ColorProcessingAlgorithm colorAlgorithm)
Sets the color processing algorithm used at the time of the Convert() call, therefore the most recent...
ImagePtr Convert(const ImagePtr &srcImage, PixelFormatEnums destFormat) const
Converts the source image buffer to the specified destination pixel format and returns the result in ...
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
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
Definition Autovector.h:36
Provides easier access to the current version of Spinnaker.
Definition SpinnakerDefs.h:645
unsigned int minor
Minor version of the library.
Definition SpinnakerDefs.h:650
unsigned int major
Major version of the library.
Definition SpinnakerDefs.h:647
unsigned int type
Version type of the library.
Definition SpinnakerDefs.h:653
unsigned int build
Build number of the library.
Definition SpinnakerDefs.h:656