#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <assert.h>
using namespace std;
{
{
}
};
{
bool result = true;
for (unsigned int cameraCnt = 0; cameraCnt < numCameras; cameraCnt++)
{
stringstream sstream;
string tmpFilename;
sstream >> tmpFilename;
cout << "Creating " << tmpFilename << "..." << endl;
imageInfos.at(cameraCnt).imageFile = std::make_shared<fstream>(
tmpFilename.c_str(), fstream::trunc | fstream::in | fstream::out | fstream::binary);
{
assert(false);
result = false;
}
}
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;
}
{
bool result = true;
cout << endl << endl << "*** CONFIGURING CAMERAS... ***" << endl << endl;
try
{
for (unsigned int cameraCnt = 0; cameraCnt < numCameras; cameraCnt++)
{
{
cout << "Unable to get acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return false;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to set acquisition mode to continuous (entry 'continuous' retrieval). Aborting..."
<< endl
<< endl;
return false;
}
int64_t acquisitionModeContinuous = ptrAcquisitionModeContinuous->GetValue();
{
cout << "Unable to set acquisition mode to continuous (node retrieval). Aborting..." << endl << endl;
return false;
}
ptrAcquisitionMode->SetIntValue(acquisitionModeContinuous);
cout << "Camera[" << cameraCnt << "]: Acquisition mode set to continuous..." << endl;
{
cout << "Unable to set Pixel Format mode (node retrieval). Aborting..." << endl << endl;
return false;
}
CEnumEntryPtr ptrPixelFormatBayerRG8 = ptrPixelFormat->GetEntryByName(
"BayerRG8");
CEnumEntryPtr ptrMono8 = ptrPixelFormat->GetEntryByName(
"Mono8");
{
ptrPixelFormat->SetIntValue(ptrPixelFormatBayerRG8->GetValue());
imageInfos.at(cameraCnt).pixelFormat = PixelFormatEnums::PixelFormat_BayerRG8;
cout << "Camera[" << cameraCnt
<< "]: Pixel format set to: " << ptrPixelFormat->GetCurrentEntry()->GetName() << endl;
}
{
ptrPixelFormat->SetIntValue(ptrMono8->GetValue());
imageInfos.at(cameraCnt).pixelFormat = PixelFormatEnums::PixelFormat_Mono8;
cout << "Camera[" << cameraCnt << "]: Pixel format set to "
<< ptrPixelFormat->GetCurrentEntry()->GetName() << endl;
}
else
{
cout << "Unable to set pixel format (enum entry retrieval). Aborting..." << endl << endl;
return false;
}
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = false;
}
return result;
}
{
bool result = true;
uint64_t missedImageCnts = 0;
cout << endl << endl << "*** ACQUIRING AND SAVING IMAGES TO A FILE ***" << endl << endl;
try
{
for (unsigned int cameraCnt = 0; cameraCnt < numCameras; cameraCnt++)
{
camList.
GetByIndex(cameraCnt)->BeginAcquisition();
cout << "Camera[" << cameraCnt << "]: Started acquiring images" << endl;
}
for (
unsigned int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
for (unsigned int cameraCnt = 0; cameraCnt < numCameras; cameraCnt++)
{
try
{
if (pResultImage->IsIncomplete())
{
cout << "Image incomplete with image status " << pResultImage->GetImageStatus() << "..." << endl
<< endl;
}
else
{
char* imageData = static_cast<char*>(pResultImage->GetData());
imageInfos.at(cameraCnt).imageFile->write(imageData, pResultImage->GetImageSize());
{
cout << "Error writing to file for camera " << cameraCnt << " !" << endl;
return false;
}
if (imageCnt == 0)
{
imageInfos.at(cameraCnt).imageHeight = pResultImage->GetHeight();
imageInfos.at(cameraCnt).imageWidth = pResultImage->GetWidth();
}
}
pResultImage->Release();
}
{
cout <<
"Error: " << e.
what() << endl;
result = false;
}
}
}
for (unsigned int cameraCnt = 0; cameraCnt < numCameras; cameraCnt++)
{
camList.
GetByIndex(cameraCnt)->GetTLStreamNodeMap().GetNode(
"StreamDroppedFrameCount");
{
if (pDroppedImages->GetValue() > 0)
{
missedImageCnts += pDroppedImages->GetValue();
cout << pDroppedImages->GetValue() << " images "
<< " missed at camera " << cameraCnt << endl;
}
}
else
{
cout << "Unable to determine the dropped frame count from the nodemap at camera " << cameraCnt << endl
<< endl;
}
cout << "Camera[" << cameraCnt << "]: Stop acquiring images " << endl;
}
cout << endl;
cout << "We missed a total of " << missedImageCnts << " images!" << endl << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = false;
}
return result;
}
{
bool result = true;
try
{
for (unsigned int cameraCnt = 0; cameraCnt < numCameras; cameraCnt++)
{
string tempFilename =
imageInfos.at(cameraCnt).imageFileName;
cout << "Opening " << tempFilename.c_str() << "..." << endl;
std::shared_ptr<fstream> rawFile =
imageInfos.at(cameraCnt).imageFile;
if (!rawFile->good())
{
cout <<
"Error opening file: " <<
imageInfos.at(cameraCnt).imageFileName.c_str() <<
" Aborting..."
<< endl;
return false;
}
cout << "Splitting images" << endl;
rawFile->seekg(0);
for (
int imageCnt = 0; imageCnt <
k_numImages; imageCnt++)
{
string readImageFilename;
stringstream sstream;
std::shared_ptr<char> pBuffer(new char[imageSize], std::default_delete<char[]>());
rawFile->read(pBuffer.get(), imageSize);
0,
0,
pBuffer.get());
sstream >> readImageFilename;
pImage->Save(readImageFilename.c_str());
if (!rawFile->good())
{
cout << "Error reading from image " << imageCnt << " for camera " << cameraCnt << ". Aborting..."
<< endl;
return false;
}
cout << "Camera[" << cameraCnt << "]: Retrieved image " << imageCnt << endl;
}
cout << endl << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
return false;
}
return result;
}
{
int result = 0;
try
{
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Printing device info for camera " << i << "..." << endl;
cout << endl << "Initializing camera " << i << "..." << endl;
}
{
cout << "There was an error creating the files. Aborting..." << endl;
return -1;
}
{
return -1;
}
{
return -1;
}
{
return -1;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Deinitializing camera " << i << "..." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
FILE* tempFile = fopen(testFile.c_str(), "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(testFile.c_str());
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;
}
result = result |
RunCameras(camList, numCameras);
system->ReleaseInstance();
cout << endl << "Done! Press Enter to exit..." << endl;
getchar();
return result;
}
int main(int, char **)
Definition Acquisition.cpp:527
int PrintDeviceInfo(INodeMap &nodeMap)
Definition Acquisition.cpp:441
int RunCameras(CameraList &camList, unsigned int numCameras)
Definition AcquisitionMultipleCamerasWriteToFile.cpp:419
bool AcquireImagesAndSaveToFile(CameraList &camList, unsigned int numCameras)
Definition AcquisitionMultipleCamerasWriteToFile.cpp:237
const string kDestinationDirectory
Definition AcquisitionMultipleCamerasWriteToFile.cpp:52
bool CreateFiles(unsigned int numCameras)
Definition AcquisitionMultipleCamerasWriteToFile.cpp:77
bool RetrieveImagesFromFiles(unsigned int numCameras, string fileFormat="bmp")
Definition AcquisitionMultipleCamerasWriteToFile.cpp:338
vector< ImageInfo > imageInfos
Definition AcquisitionMultipleCamerasWriteToFile.cpp:74
const unsigned int k_numImages
Definition AcquisitionMultipleCamerasWriteToFile.cpp:55
bool ConfigureCameras(CameraList &camList, unsigned int numCameras)
Definition AcquisitionMultipleCamerasWriteToFile.cpp:147
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.
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
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
PixelFormatEnums
Definition CameraDefs.h:946
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
Definition AcquisitionMultipleCamerasWriteToFile.cpp:60
size_t imageHeight
Definition AcquisitionMultipleCamerasWriteToFile.cpp:62
string imageFileName
Definition AcquisitionMultipleCamerasWriteToFile.cpp:64
size_t imageWidth
Definition AcquisitionMultipleCamerasWriteToFile.cpp:61
std::shared_ptr< fstream > imageFile
Definition AcquisitionMultipleCamerasWriteToFile.cpp:65
PixelFormatEnums pixelFormat
Definition AcquisitionMultipleCamerasWriteToFile.cpp:63
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