Inference is only available for Firefly deep learning cameras. See the related content section on the Firefly DL product page for relevant documentation.
It can also be helpful to familiarize yourself with the Acquisition, ChunkData and FileAccess_QuickSpin examples.
#include <iostream>
#include <fstream>
using namespace std;
{
};
{
};
: "Injected_Image_Detection.raw");
const char*
arrayLabelDetection[] = {
"background",
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant", "sheep",
"sofa", "train", "monitor"};
{
int result = 0;
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
const CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
{
category->GetFeatures(features);
for (FeatureList_t::const_iterator 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 available." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
bool result = true;
{
cout << "Unable to query FileSize. Aborting..." << endl;
return false;
}
if (ptrFileSize->GetValue() == 0)
{
cout << "No files found, skipping file deletion." << endl;
return true;
}
cout << "Deleting file..." << endl;
try
{
CEnumerationPtr ptrFileOperationSelector = nodeMap.GetNode(
"FileOperationSelector");
{
cout << "Unable to configure FileOperationSelector. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationDelete = ptrFileOperationSelector->GetEntryByName(
"Delete");
{
cout << "Unable to configure FileOperationSelector Delete. Aborting..." << endl;
return false;
}
ptrFileOperationSelector->SetIntValue(static_cast<int64_t>(ptrFileOperationDelete->GetNumericValue()));
CCommandPtr ptrFileOperationExecute = nodeMap.GetNode(
"FileOperationExecute");
{
cout << "Unable to configure FileOperationExecute. Aborting..." << endl;
return false;
}
ptrFileOperationExecute->Execute();
CEnumerationPtr ptrFileOperationStatus = nodeMap.GetNode(
"FileOperationStatus");
{
cout << "Unable to query FileOperationStatus. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationStatusSuccess = ptrFileOperationStatus->GetEntryByName(
"Success");
{
cout << "Unable to query FileOperationStatus Success. Aborting..." << endl;
return false;
}
if (ptrFileOperationStatus->GetCurrentEntry() != ptrFileOperationStatusSuccess)
{
cout << "Failed to delete file! File Operation Status : "
<< ptrFileOperationStatus->GetCurrentEntry()->GetSymbolic() << endl;
return false;
}
}
{
cout <<
"Unexpected exception : " << e.
what() << endl;
result = false;
}
return result;
}
{
bool result = true;
cout << "Opening file for writing..." << endl;
try
{
CEnumerationPtr ptrFileOperationSelector = nodeMap.GetNode(
"FileOperationSelector");
{
cout << "Unable to configure FileOperationSelector. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationOpen = ptrFileOperationSelector->GetEntryByName(
"Open");
{
cout << "Unable to configure FileOperationSelector Open. Aborting..." << endl;
return false;
}
ptrFileOperationSelector->SetIntValue(static_cast<int64_t>(ptrFileOperationOpen->GetNumericValue()));
{
cout << "Unable to configure ptrFileOpenMode. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOpenModeWrite = ptrFileOpenMode->GetEntryByName(
"Write");
{
cout << "Unable to configure FileOperationSelector Write. Aborting..." << endl;
return false;
}
ptrFileOpenMode->SetIntValue(static_cast<int64_t>(ptrFileOpenModeWrite->GetNumericValue()));
CCommandPtr ptrFileOperationExecute = nodeMap.GetNode(
"FileOperationExecute");
{
cout << "Unable to configure FileOperationExecute. Aborting..." << endl;
return false;
}
ptrFileOperationExecute->Execute();
CEnumerationPtr ptrFileOperationStatus = nodeMap.GetNode(
"FileOperationStatus");
{
cout << "Unable to query FileOperationStatus. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationStatusSuccess = ptrFileOperationStatus->GetEntryByName(
"Success");
{
cout << "Unable to query FileOperationStatus Success. Aborting..." << endl;
return false;
}
if (ptrFileOperationStatus->GetCurrentEntry() != ptrFileOperationStatusSuccess)
{
cout << "Failed to open file for writing!" << endl;
return false;
}
CBooleanPtr ptrFileWriteToFlash = nodeMap.GetNode(
"FileWriteToFlash");
{
{
ptrFileWriteToFlash->SetValue(true);
cout << "FileWriteToFlash is set to true" << endl;
}
else
{
ptrFileWriteToFlash->SetValue(false);
cout << "FileWriteToFlash is set to false" << endl;
}
}
CIntegerPtr ptrFileAccessLength = nodeMap.GetNode(
"FileAccessLength");
{
cout << "Unable to query/configure FileAccessLength. Aborting..." << endl;
return false;
}
CRegisterPtr ptrFileAccessBuffer = nodeMap.GetNode(
"FileAccessBuffer");
{
cout << "Unable to query FileAccessBuffer. Aborting..." << endl;
return false;
}
if (ptrFileAccessLength->GetValue() < ptrFileAccessBuffer->GetLength())
{
try
{
ptrFileAccessLength->SetValue(ptrFileAccessBuffer->GetLength());
}
{
cout <<
"Unable to set FileAccessLength to FileAccessBuffer length : " << e.
what();
}
}
CIntegerPtr ptrFileAccessOffset = nodeMap.GetNode(
"FileAccessOffset");
{
cout << "Unable to query/configure ptrFileAccessOffset. Aborting..." << endl;
return false;
}
ptrFileAccessOffset->SetValue(0);
}
{
cout <<
"Unexpected exception : " << e.
what();
result = false;
}
return result;
}
{
bool result = true;
try
{
CEnumerationPtr ptrFileOperationSelector = nodeMap.GetNode(
"FileOperationSelector");
{
cout << "Unable to configure FileOperationSelector. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationWrite = ptrFileOperationSelector->GetEntryByName(
"Write");
{
cout << "Unable to configure FileOperationSelector Write. Aborting..." << endl;
return false;
}
ptrFileOperationSelector->SetIntValue(static_cast<int64_t>(ptrFileOperationWrite->GetNumericValue()));
CCommandPtr ptrFileOperationExecute = nodeMap.GetNode(
"FileOperationExecute");
{
cout << "Unable to configure FileOperationExecute. Aborting..." << endl;
return false;
}
ptrFileOperationExecute->Execute();
CEnumerationPtr ptrFileOperationStatus = nodeMap.GetNode(
"FileOperationStatus");
{
cout << "Unable to query FileOperationStatus. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationStatusSuccess = ptrFileOperationStatus->GetEntryByName(
"Success");
{
cout << "Unable to query FileOperationStatus Success. Aborting..." << endl;
return false;
}
if (ptrFileOperationStatus->GetCurrentEntry() != ptrFileOperationStatusSuccess)
{
cout << "Failed to write to file!" << endl;
return false;
}
}
{
cout <<
"Unexpected exception : " << e.
what();
result = false;
}
return result;
}
{
bool result = true;
cout << "Closing file..." << endl;
try
{
CEnumerationPtr ptrFileOperationSelector = nodeMap.GetNode(
"FileOperationSelector");
{
cout << "Unable to configure FileOperationSelector. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationClose = ptrFileOperationSelector->GetEntryByName(
"Close");
{
cout << "Unable to configure FileOperationSelector Close. Aborting..." << endl;
return false;
}
ptrFileOperationSelector->SetIntValue((int64_t)ptrFileOperationClose->GetNumericValue());
CCommandPtr ptrFileOperationExecute = nodeMap.GetNode(
"FileOperationExecute");
{
cout << "Unable to configure FileOperationExecute. Aborting..." << endl;
return false;
}
ptrFileOperationExecute->Execute();
CEnumerationPtr ptrFileOperationStatus = nodeMap.GetNode(
"FileOperationStatus");
{
cout << "Unable to query FileOperationStatus. Aborting..." << endl;
return false;
}
CEnumEntryPtr ptrFileOperationStatusSuccess = ptrFileOperationStatus->GetEntryByName(
"Success");
{
cout << "Unable to query FileOperationStatus Success. Aborting..." << endl;
return false;
}
if (ptrFileOperationStatus->GetCurrentEntry() != ptrFileOperationStatusSuccess)
{
cout << "Failed to close file!" << endl;
return false;
}
}
{
cout <<
"Unexpected exception : " << e.
what();
result = false;
}
return result;
}
{
ifstream ifs(filename, ios::binary | ios::ate | ios::in);
if (ifs.fail())
{
cout << "Failed to open " << filename << endl;
std::vector<char> data;
return data;
}
const ifstream::pos_type pos = ifs.tellg();
std::vector<char> data(static_cast<unsigned int>(pos));
ifs.seekg(0, ios::beg);
ifs.read(&data[0], pos);
return data;
}
int UploadFileToCamera(INodeMap& nodeMap,
const std::string& fileSelectorEntryName,
const std::string& filePath)
{
cout << endl << endl << "*** CONFIGURING FILE SELECTOR ***" << endl << endl;
{
cout << "Unable to configure FileSelector. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrInferenceSelectorEntry = ptrFileSelector->GetEntryByName(fileSelectorEntryName.c_str());
{
cout << "Unable to query FileSelector entry " << fileSelectorEntryName << ". Aborting..." << endl;
return -1;
}
cout << "Setting FileSelector to " << ptrInferenceSelectorEntry->GetSymbolic() << "..." << endl;
ptrFileSelector->SetIntValue(static_cast<int64_t>(ptrInferenceSelectorEntry->GetNumericValue()));
{
cout << "Failed to delete existing file for selector entry " << ptrInferenceSelectorEntry->GetSymbolic()
<< ". Aborting..." << endl;
return -1;
}
{
{
cout << "Problem opening file node. Aborting..." << endl;
return -1;
}
{
cout << "Problem opening file node. Aborting..." << endl;
return -1;
}
}
CIntegerPtr ptrFileAccessLength = nodeMap.GetNode(
"FileAccessLength");
{
cout << "Unable to query FileAccessLength. Aborting..." << endl;
return -1;
}
CRegisterPtr ptrFileAccessBuffer = nodeMap.GetNode(
"FileAccessBuffer");
{
cout << "Unable to query FileAccessBuffer. Aborting..." << endl;
return -1;
}
CIntegerPtr ptrFileOperationResult = nodeMap.GetNode(
"FileOperationResult");
{
cout << "Unable to query FileOperationResult. Aborting..." << endl;
return -1;
}
if (fileBytes.size() == 0)
{
cout << "Failed to load file path : " << filePath << ". Aborting..." << endl;
return -1;
}
const int64_t totalBytesToWrite = fileBytes.size();
int64_t intermediateBufferSize = ptrFileAccessLength->GetValue();
const int64_t writeIterations =
(totalBytesToWrite / intermediateBufferSize) + (totalBytesToWrite % intermediateBufferSize == 0 ? 0 : 1);
if (totalBytesToWrite == 0)
{
cout << "Empty Image. No data will be written to camera. Aborting..." << endl;
return -1;
}
cout << "Start uploading \"" << filePath << "\" to device..." << endl;
cout << "Total Bytes to write : " << to_string(static_cast<long long>(totalBytesToWrite)) << endl;
cout << "FileAccessLength : " << to_string(static_cast<long long>(intermediateBufferSize)) << endl;
cout << "Write Iterations : " << to_string(static_cast<long long>(writeIterations)) << endl;
int64_t index = 0;
int64_t bytesLeftToWrite = totalBytesToWrite;
int64_t totalBytesWritten = 0;
bool paddingRequired = false;
int numPaddings = 0;
cout << "Writing data to device..." << endl;
char* pFileData = fileBytes.data();
for (unsigned int i = 0; i < writeIterations; i++)
{
if (intermediateBufferSize > bytesLeftToWrite)
{
const unsigned int remainder = bytesLeftToWrite % 4;
if (remainder != 0)
{
paddingRequired = true;
numPaddings = 4 - remainder;
}
}
const int64_t tmpBufferSize =
intermediateBufferSize <= bytesLeftToWrite ? intermediateBufferSize : (bytesLeftToWrite + numPaddings);
std::unique_ptr<unsigned char> tmpBuffer(new unsigned char[static_cast<unsigned int>(tmpBufferSize)]);
memcpy(
tmpBuffer.get(),
&pFileData[index],
static_cast<size_t>(
(intermediateBufferSize <= bytesLeftToWrite) ? intermediateBufferSize : bytesLeftToWrite));
if (paddingRequired)
{
for (int j = 0; j < numPaddings; j++)
{
unsigned char* pTmpBuffer = tmpBuffer.get();
pTmpBuffer[bytesLeftToWrite + j] = 255;
}
}
index = index + (intermediateBufferSize <= bytesLeftToWrite ? intermediateBufferSize : bytesLeftToWrite);
ptrFileAccessBuffer->Set(tmpBuffer.get(), tmpBufferSize);
if (intermediateBufferSize > bytesLeftToWrite)
{
ptrFileAccessLength->SetValue(bytesLeftToWrite);
}
{
cout << "Writing to stream failed! Aborting..." << endl;
return -1;
}
const int64_t sizeWritten = ptrFileOperationResult->GetValue();
totalBytesWritten += sizeWritten;
bytesLeftToWrite = totalBytesToWrite - totalBytesWritten;
cout << "Progress : " << (i * 100 / writeIterations) << " %" << '\r' << flush;
}
cout << "Writing complete" << endl;
{
cout << "Failed to close file!" << endl;
}
return 0;
}
{
cout << endl << endl << "*** CLEANING UP FILE SELECTOR ***" << endl << endl;
{
cout << "Unable to configure FileSelector. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrInferenceSelectorEntry = ptrFileSelector->GetEntryByName(fileSelectorEntryName.c_str());
{
cout << "Unable to query FileSelector entry " << fileSelectorEntryName << ". Aborting..." << endl;
return -1;
}
cout << "Setting FileSelector to " << ptrInferenceSelectorEntry->GetSymbolic() << endl;
ptrFileSelector->SetIntValue(static_cast<int64_t>(ptrInferenceSelectorEntry->GetNumericValue()));
{
cout << "Failed to delete existing file for selector entry " << ptrInferenceSelectorEntry->GetSymbolic()
<< ". Aborting..." << endl;
return -1;
}
return 0;
}
{
int result = 0;
{
cout << "Unable to retrieve chunk selector (enum retrieval). Aborting..." << endl;
return -1;
}
const CEnumEntryPtr ptrEntry = ptrChunkSelector->GetEntryByName(entryName);
{
return -1;
}
{
return -1;
}
ptrChunkSelector->SetIntValue(ptrEntry->GetValue());
cout << entryName << " ";
CBooleanPtr ptrChunkEnable = nodeMap.GetNode(
"ChunkEnable");
{
cout << "not readable" << endl;
return -1;
}
if (enable)
{
if (ptrChunkEnable->GetValue())
{
cout << "enabled" << endl;
}
{
ptrChunkEnable->SetValue(true);
cout << "enabled" << endl;
}
else
{
cout << "not writable" << endl;
result = -1;
}
}
else
{
if (!ptrChunkEnable->GetValue())
{
cout << "disabled" << endl;
}
{
ptrChunkEnable->SetValue(false);
cout << "disabled" << endl;
}
else
{
cout << "not writable" << endl;
result = -1;
}
}
return result;
}
{
int result = 0;
cout << endl << endl << "*** CONFIGURING CHUNK DATA ***" << endl << endl;
try
{
CBooleanPtr ptrChunkModeActive = nodeMap.GetNode(
"ChunkModeActive");
{
cout << "Unable to activate chunk mode. Aborting..." << endl;
return -1;
}
ptrChunkModeActive->SetValue(true);
cout << "Chunk mode activated..." << endl;
if (result == -1)
{
cout << "Unable to enable Inference Frame Id chunk data. Aborting..." << endl;
return result;
}
{
if (result == -1)
{
cout << "Unable to enable Inference Bounding Box chunk data. Aborting..." << endl;
return result;
}
}
else
{
if (result == -1)
{
cout << "Unable to enable Inference Result chunk data. Aborting..." << endl;
return result;
}
if (result == -1)
{
cout << "Unable to enable Inference Confidence chunk data. Aborting..." << endl;
return result;
}
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
cout << endl << endl << "*** DISABLING CHUNK DATA ***" << endl << endl;
int result = 0;
try
{
{
cout << "Unable to retrieve chunk selector. Aborting..." << endl;
return -1;
}
if (result == -1)
{
cout << "Unable to disable Inference Frame Id chunk data. Aborting..." << endl;
return result;
}
{
result =
SetChunkEnable(nodeMap,
"InferenceBoundingBoxResult",
false);
if (result == -1)
{
cout << "Unable to disable Inference Bounding Box chunk data. Aborting..." << endl;
return result;
}
}
else
{
if (result == -1)
{
cout << "Unable to disable Inference Result chunk data. Aborting..." << endl;
return result;
}
if (result == -1)
{
cout << "Unable to disable Inference Confidence chunk data. Aborting..." << endl;
return result;
}
}
CBooleanPtr ptrChunkModeActive = nodeMap.GetNode(
"ChunkModeActive");
{
cout << "Unable to deactivate chunk mode. Aborting..." << endl;
return -1;
}
ptrChunkModeActive->SetValue(false);
cout << "Chunk mode deactivated..." << endl;
CBooleanPtr ptrInferenceEnable = nodeMap.GetNode(
"InferenceEnable");
{
cout << "Unable to disable inference. Aborting..." << endl;
return -1;
}
ptrInferenceEnable->SetValue(false);
cout << "Inference disabled..." << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << "Printing chunk data from image..." << endl;
try
{
const ChunkData chunkData = pImage->GetChunkData();
cout << "\tInference Frame ID: " << inferenceFrameID << endl;
{
cout << "\tInference Bounding Box Result:" << endl;
if (boxCount == 0)
{
cout << "\tNo bounding box" << endl;
}
for (int16_t i = 0; i < boxCount; ++i)
{
{
cout << "\tBox[" << i + 1 << "]: "
: "N/A")
<< "Rectangle ("
<<
"X=" << box.
rect.topLeftXCoord <<
", "
<<
"Y=" << box.
rect.topLeftYCoord <<
", "
<<
"W=" << box.
rect.bottomRightXCoord - box.
rect.topLeftXCoord <<
", "
<<
"H=" << box.
rect.bottomRightYCoord - box.
rect.topLeftYCoord <<
")" << endl;
break;
cout << "\tBox[" << i + 1 << "]: "
: "N/A")
<< "Circle ("
<<
"X=" << box.
circle.centerXCoord <<
", "
<<
"Y=" << box.
circle.centerYCoord <<
", "
<<
"R=" << box.
circle.radius <<
")" << endl;
break;
cout << "\tBox[" << i + 1 << "]: "
: "N/A")
<< "Rotated Rectangle ("
<<
"angle=" << box.
rotatedRect.rotationAngle <<
")" << endl;
break;
default:
cout << "\tBox[" << i + 1 << "]: "
: "N/A")
<< "Unknown bounding box type (not supported)" << endl;
break;
}
}
}
else
{
cout << "\tInference Result: " << inferenceResult << " ("
: "N/A")
<< ")" << endl;
cout << "\tInference Confidence: " << inferenceConfidence << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
cout << endl << endl << "*** DISABLING TRIGGER ***" << endl << endl;
int result = 0;
try
{
{
cout << "Unable to configure TriggerMode. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrTriggerOff = ptrTriggerMode->GetEntryByName(
"Off");
{
cout << "Unable to query TriggerMode Off. Aborting..." << endl;
return -1;
}
cout << "Configure TriggerMode to " << ptrTriggerOff->GetSymbolic() << endl;
ptrTriggerMode->SetIntValue(static_cast<int64_t>(ptrTriggerOff->GetNumericValue()));
}
{
cout <<
"Unexpected exception : " << e.
what();
result = -1;
}
return result;
}
{
cout << endl << endl << "*** CONFIGURING TRIGGER ***" << endl << endl;
int result = 0;
try
{
{
cout << "Unable to configure TriggerSelector. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrFrameStart = ptrTriggerSelector->GetEntryByName(
"FrameStart");
{
cout << "Unable to query TriggerSelector FrameStart. Aborting..." << endl;
return -1;
}
cout << "Configure TriggerSelector to " << ptrFrameStart->GetSymbolic() << endl;
ptrTriggerSelector->SetIntValue(static_cast<int64_t>(ptrFrameStart->GetNumericValue()));
{
cout << "Unable to configure TriggerSource. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrInferenceReady = ptrTriggerSource->GetEntryByName(
"InferenceReady");
{
cout << "Unable to query TriggerSource InferenceReady. Aborting..." << endl;
return -1;
}
cout << "Configure TriggerSource to " << ptrInferenceReady->GetSymbolic() << endl;
ptrTriggerSource->SetIntValue(static_cast<int64_t>(ptrInferenceReady->GetNumericValue()));
{
cout << "Unable to configure TriggerMode. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrTriggerOn = ptrTriggerMode->GetEntryByName(
"On");
{
cout << "Unable to query TriggerMode On. Aborting..." << endl;
return -1;
}
cout << "Configure TriggerMode to " << ptrTriggerOn->GetSymbolic() << endl;
ptrTriggerMode->SetIntValue(static_cast<int64_t>(ptrTriggerOn->GetNumericValue()));
}
{
cout <<
"Unexpected exception : " << e.
what();
result = -1;
}
return result;
}
{
int result = 0;
if (isEnabled)
{
cout << endl
<< endl
<< "*** CONFIGURING INFERENCE ("
<< endl;
}
else
{
cout << endl << endl << "*** DISABLING INFERENCE ***" << endl << endl;
}
try
{
if (isEnabled)
{
CEnumerationPtr ptrInferenceNetworkTypeSelector = nodeMap.GetNode(
"InferenceNetworkTypeSelector");
if (!
IsReadable(ptrInferenceNetworkTypeSelector) ||
{
cout << "Unable to query InferenceNetworkTypeSelector. Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrInferenceNetworkType = ptrInferenceNetworkTypeSelector->GetEntryByName(networkTypeString);
{
cout << "Unable to set inference network type to " << networkTypeString
<< " (entry retrieval). Aborting..." << endl
<< endl;
return -1;
}
ptrInferenceNetworkTypeSelector->SetIntValue(
static_cast<int64_t>(ptrInferenceNetworkType->GetNumericValue()));
cout << "Inference network type set to " << networkTypeString << "..." << endl;
}
cout << (isEnabled ? "Enabling" : "Disabling") << " inference..." << endl;
CBooleanPtr ptrInferenceEnable = nodeMap.GetNode(
"InferenceEnable");
{
cout << "Unable to enable inference. Aborting..." << endl;
return -1;
}
ptrInferenceEnable->SetValue(isEnabled);
cout << "Inference " << (isEnabled ? "enabled..." : "disabled...") << endl;
}
{
cout <<
"Unexpected exception : " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
if (isEnabled)
{
cout << endl << endl << "*** CONFIGURING TEST PATTERN ***" << endl << endl;
}
else
{
cout << endl << endl << "*** DISABLING TEST PATTERN ***" << endl << endl;
}
try
{
CEnumerationPtr ptrTestPatternGeneratorSelector = nodeMap.GetNode(
"TestPatternGeneratorSelector");
if (!
IsReadable(ptrTestPatternGeneratorSelector) ||
{
cout << "Unable to query TestPatternGeneratorSelector. Aborting..." << endl;
return -1;
}
if (isEnabled)
{
ptrTestPatternGeneratorSelector->GetEntryByName("PipelineStart");
if (!
IsReadable(ptrTestPatternGeneratorPipelineStart))
{
cout << "Unable to query TestPatternGeneratorSelector PipelineStart. Aborting..." << endl;
return -1;
}
ptrTestPatternGeneratorSelector->SetIntValue(
static_cast<int64_t>(ptrTestPatternGeneratorPipelineStart->GetNumericValue()));
cout << "TestPatternGeneratorSelector set to " << ptrTestPatternGeneratorPipelineStart->GetSymbolic()
<< "..." << endl;
}
else
{
CEnumEntryPtr ptrTestPatternGeneratorSensor = ptrTestPatternGeneratorSelector->GetEntryByName(
"Sensor");
{
cout << "Unable to query TestPatternGeneratorSelector Sensor. Aborting..." << endl;
return -1;
}
ptrTestPatternGeneratorSelector->SetIntValue(
static_cast<int64_t>(ptrTestPatternGeneratorSensor->GetNumericValue()));
cout << "TestPatternGeneratorSelector set to " << ptrTestPatternGeneratorSensor->GetSymbolic() << "..."
<< endl;
}
{
cout << "Unable to query TestPattern. Aborting..." << endl;
return -1;
}
if (isEnabled)
{
CEnumEntryPtr ptrInjectedImage = ptrTestPattern->GetEntryByName(
"InjectedImage");
{
cout << "Unable to query TestPattern InjectedImage. Aborting..." << endl;
return -1;
}
ptrTestPattern->SetIntValue(static_cast<int64_t>(ptrInjectedImage->GetNumericValue()));
cout << "TestPattern set to " << ptrInjectedImage->GetSymbolic() << "..." << endl;
}
else
{
CEnumEntryPtr ptrTestPatternOff = ptrTestPattern->GetEntryByName(
"Off");
{
cout << "Unable to query TestPattern Off. Aborting..." << endl;
return -1;
}
ptrTestPattern->SetIntValue(static_cast<int64_t>(ptrTestPatternOff->GetNumericValue()));
cout << "TestPattern set to " << ptrTestPatternOff->GetSymbolic() << "..." << endl;
}
if (isEnabled)
{
CIntegerPtr ptrInjectedWidth = nodeMap.GetNode(
"InjectedWidth");
{
cout << "Unable to query InjectedWidth. Aborting..." << endl;
return -1;
}
CIntegerPtr ptrInjectedHeight = nodeMap.GetNode(
"InjectedHeight");
{
cout << "Unable to query InjectedHeight. Aborting..." << endl;
return -1;
}
}
}
{
cout <<
"Unexpected exception : " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
cout << endl << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
{
cout << "Unable to set acquisition mode to continuous (node retrieval). Aborting..." << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeContinuous = ptrAcquisitionMode->GetEntryByName(
"Continuous");
{
cout << "Unable to set acquisition mode to continuous (entry 'continuous' 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())
{
cout << "Image incomplete with image status " << pResultImage->GetImageStatus() << "..." << endl
<< endl;
}
else
{
cout << "Grabbed image " << imageCnt << ", width = " << pResultImage->GetWidth()
<< ", height = " << pResultImage->GetHeight() << "." << endl;
pResultImage->Save("image.jpg");
}
pResultImage->Release();
cout << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
}
pCam->EndAcquisition();
}
{
cout <<
"Error: " << e.
what() << endl;
result = -1;
}
return result;
}
{
int result = 0;
int err = 0;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
cout << endl << "Checking camera inference support..." << endl;
CBooleanPtr ptrInferenceEnable = nodeMap.GetNode(
"InferenceEnable");
{
cout << "Inference is not supported on this camera. Aborting..." << endl;
return -1;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
if (err < 0)
{
return err;
}
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");
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;
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;
}
for (unsigned int i = 0; i < numCameras; i++)
{
cout << endl << "Running example for camera " << i << "..." << endl;
cout << "Camera " << i << " 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: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
int ConfigureTrigger(INodeMap &nodeMap)
Definition BufferHandling.cpp:103
int DisplayChunkData(ImagePtr pImage)
Definition ChunkData.cpp:195
int ConfigureChunkData(INodeMap &nodeMap)
Definition ChunkData.cpp:71
int DisableChunkData(INodeMap &nodeMap)
Definition ChunkData.cpp:544
const char * arrayLabelClassification[]
Definition Inference.cpp:114
int SetChunkEnable(INodeMap &nodeMap, const gcstring &entryName, const bool enable)
Definition Inference.cpp:745
bool CameraOpenFile(INodeMap &nodeMap)
Definition Inference.cpp:246
bool CameraDeleteFile(INodeMap &nodeMap)
Definition Inference.cpp:168
const FileUploadPersistence chosenFileUploadPersistence
Definition Inference.cpp:84
bool CameraWriteToFile(INodeMap &nodeMap)
Definition Inference.cpp:379
bool CameraCloseFile(INodeMap &nodeMap)
Definition Inference.cpp:440
std::vector< char > LoadFileIntoMemory(const string &filename)
Definition Inference.cpp:502
const InferenceNetworkType chosenInferenceNetworkType
Definition Inference.cpp:74
int ConfigureTestPattern(INodeMap &nodeMap, bool isEnabled)
Definition Inference.cpp:1269
int UploadFileToCamera(INodeMap &nodeMap, const std::string &fileSelectorEntryName, const std::string &filePath)
Definition Inference.cpp:522
const std::string injectedImageFilePath
Definition Inference.cpp:101
int ConfigureInference(INodeMap &nodeMap, bool isEnabled)
Definition Inference.cpp:1198
int DeleteFileOnCamera(INodeMap &nodeMap, const std::string &fileSelectorEntryName)
Definition Inference.cpp:709
const unsigned int injectedImageHeight
Definition Inference.cpp:108
int DisableTrigger(INodeMap &nodeMap)
Definition Inference.cpp:1089
const std::string networkFilePath
Definition Inference.cpp:93
const char * arrayLabelDetection[]
Definition Inference.cpp:121
const std::vector< std::string > labelDetection(arrayLabelDetection, end(arrayLabelDetection))
FileUploadPersistence
Definition Inference.cpp:79
@ FLASH
Definition Inference.cpp:80
@ DDR
Definition Inference.cpp:81
const std::vector< std::string > labelClassification(arrayLabelClassification, end(arrayLabelClassification))
InferenceNetworkType
Definition Inference.cpp:58
@ DETECTION
This network determines the most likely class given a set of predetermined, trained options.
Definition Inference.cpp:65
@ CLASSIFICATION
This network determines the best option from a list of predetermined options; the camera gives a perc...
Definition Inference.cpp:71
const unsigned int injectedImageWidth
Definition Inference.cpp:107
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 chunk data which contains additional information about an image.
Definition ChunkData.h:42
int64_t GetInferenceFrameId() const
Description: Returns the frame ID associated with the most recent inference result.
int64_t GetInferenceResult() const
Description: Returns the chunk data inference result.
float64_t GetInferenceConfidence() const
Description: Returns the chunk data inference confidence percentage.
InferenceBoundingBoxResult GetInferenceBoundingBoxResult() const
Description: Returns the chunk inference bounding box result data.
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
An inference bounding boxes object which holds information about the detected bounding boxes.
Definition ChunkDataInference.h:92
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
InferenceBoxType boxType
Definition ChunkDataInference.h:74
InferenceBoxRotatedRect rotatedRect
Definition ChunkDataInference.h:80
int16_t GetBoxCount() const
Returns the number of bounding boxes.
InferenceBoxRect rect
Definition ChunkDataInference.h:78
InferenceBoxCircle circle
Definition ChunkDataInference.h:79
int16_t classId
Definition ChunkDataInference.h:75
float32_t confidence
Definition ChunkDataInference.h:76
InferenceBoundingBox GetBoxAt(const uint16_t index) const
Returns the bounding box at specified index.
virtual double GetMax()=0
Get maximum value allowed.
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
@ INFERENCE_BOX_TYPE_ROTATED_RECTANGLE
Definition ChunkDataInference.h:39
@ INFERENCE_BOX_TYPE_RECTANGLE
Definition ChunkDataInference.h:37
@ INFERENCE_BOX_TYPE_CIRCLE
Definition ChunkDataInference.h:38
Definition Autovector.h:36
Inference Bounding Boxes data structure.
Definition ChunkDataInference.h:73
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