This example demonstrates some of the methods that can be used to extract polarization quadrant images and create Stokes', AoLP, and DoLP images from the ImageUtilityPolarization class. It then demonstrates how to use some of the available methods in the ImageUtility and ImageUtilityHeatmap classes to create normalized and heatmap images.
#include <iostream>
#include <string>
#include <array>
using namespace std;
{
cout << endl << "*** DEVICE INFORMATION ***" << endl << endl;
try
{
FeatureList_t features;
const CCategoryPtr category = nodeMap.GetNode(
"DeviceInformation");
if (IsReadable(category))
{
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 readable." << endl;
}
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 0;
}
{
if (IsReadable(ptrPixelFormat) && IsWritable(ptrPixelFormat))
{
CEnumEntryPtr ptrPixelFormatPolarized8 = ptrPixelFormat->GetEntryByName(
"Polarized8");
CEnumEntryPtr ptrPixelFormatBayerRGPolarized8 = ptrPixelFormat->GetEntryByName(
"BayerRGPolarized8");
if (IsReadable(ptrPixelFormatPolarized8))
{
const int64_t pixelFormatPolarized8 = ptrPixelFormatPolarized8->GetValue();
ptrPixelFormat->SetIntValue(pixelFormatPolarized8);
cout << "Pixel format set to " << ptrPixelFormat->GetCurrentEntry()->GetSymbolic() << "..." << endl;
}
else if (
IsReadable(ptrPixelFormatBayerRGPolarized8))
{
const int64_t pixelFormatBayerRGPolarized8 = ptrPixelFormatBayerRGPolarized8->GetValue();
ptrPixelFormat->SetIntValue(pixelFormatBayerRGPolarized8);
cout << "Pixel format set to " << ptrPixelFormat->GetCurrentEntry()->GetSymbolic() << "..." << endl;
}
else
{
cout << "Pixel format Polarized8 or BayerRGPolarized8 not readable (entry retrieval). Aborting..." << endl;
return -1;
}
}
else
{
cout << "Pixel format not writable (enum retrieval). Aborting..." << endl;
return -1;
}
{
cout << "Unable to get or set acquisition mode to single frame (enum retrieval). Aborting..." << endl << endl;
return -1;
}
CEnumEntryPtr ptrAcquisitionModeSingleFrame = ptrAcquisitionMode->GetEntryByName(
"SingleFrame");
{
cout << "Unable to get acquisition mode to single frame (entry retrieval). Aborting..." << endl << endl;
return -1;
}
const int64_t acquisitionModeSingleFrame = ptrAcquisitionModeSingleFrame->GetValue();
ptrAcquisitionMode->SetIntValue(acquisitionModeSingleFrame);
cout << "Acquisition mode set to single frame..." << endl;
return 0;
}
{
try
{
string fullFilename;
if (!serialNumber.
empty())
{
fullFilename = serialNumber.
c_str() + filename;
fullFilename.insert(serialNumber.
length(), 1,
'-');
}
else
{
fullFilename = filename;
}
pImage->Save(fullFilename.c_str());
cout << "Image saved at " << fullFilename << endl;
cout << "Width = " << pImage->GetWidth() << ", height = " << pImage->GetHeight()
<< ", pixel format = " << pImage->GetPixelFormatName() << endl
<< endl;
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 0;
}
{
switch (quadrant)
{
return "I0";
return "I45";
return "I90";
return "I135";
default:
return "UNKNOWN_QUAD";
}
}
{
try
{
ImageUtilityHeatmap::SetHeatmapColorGradient(
SPINNAKER_HEATMAP_COLOR_BLACK, SPINNAKER_HEATMAP_COLOR_WHITE);
ImageUtilityHeatmap::SetHeatmapRange(0, 100);
const auto heatmapImage = ImageUtilityHeatmap::CreateHeatmap(mono8Image);
SaveImage(heatmapImage, (baseFilename +
"_Heatmap.jpg"), deviceSerialNumber);
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 1;
}
{
try
{
array<PolarizationQuadrant, 4> polarizationQuadEnums = {
for (auto polarizationQuadEnum = polarizationQuadEnums.begin();
polarizationQuadEnum != polarizationQuadEnums.end();
++polarizationQuadEnum)
{
const auto polarizationQuadImage =
ImageUtilityPolarization::ExtractPolarQuadrant(pRawPolarizedImage, *polarizationQuadEnum);
SaveImage(polarizationQuadImage, (quadrantName +
".jpg"), deviceSerialNumber);
{
}
}
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 1;
}
{
try
{
const auto glareReducedImage = ImageUtilityPolarization::CreateGlareReduced(pRawPolarizedImage);
SaveImage(glareReducedImage,
"Glare_Reduced.jpg", deviceSerialNumber);
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 1;
}
const string baseFilename,
SourceDataRange srcDataRange = SPINNAKER_SOURCE_DATA_RANGE_IMAGE_DATA_RANGE)
{
try
{
const auto normalizedImage = ImageUtility::CreateNormalized(
SaveImage(normalizedImage, (baseFilename +
"_Normalized.jpg"), deviceSerialNumber);
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 1;
}
{
try
{
const auto stokesS0Image = ImageUtilityPolarization::CreateStokesS0(pRawPolarizedImage);
const auto stokesS1Image = ImageUtilityPolarization::CreateStokesS1(pRawPolarizedImage);
const auto stokesS2Image = ImageUtilityPolarization::CreateStokesS2(pRawPolarizedImage);
array<ImagePtr, 3> stokesImages = {stokesS0Image, stokesS1Image, stokesS2Image};
long long stokesAppendage = 0;
for (auto stokesImage = stokesImages.begin(); stokesImage != stokesImages.end(); ++stokesImage)
{
const string stokesName = "Stokes_S" + to_string(stokesAppendage++);
SaveImage(*stokesImage, (stokesName +
".raw"), deviceSerialNumber);
*stokesImage, stokesName, deviceSerialNumber, SourceDataRange::SPINNAKER_SOURCE_DATA_RANGE_ABSOLUTE_DATA_RANGE);
}
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 1;
}
{
try
{
const auto aolpImage = ImageUtilityPolarization::CreateAolp(pRawPolarizedImage);
SaveImage(aolpImage,
"AoLP.raw", deviceSerialNumber);
const auto dolpImage = ImageUtilityPolarization::CreateDolp(pRawPolarizedImage);
SaveImage(dolpImage,
"DoLP.raw", deviceSerialNumber);
const auto aolpNormalizedImage = ImageUtility::CreateNormalized(
aolpImage,
SaveImage(aolpNormalizedImage,
"AoLP_Normalized.jpg", deviceSerialNumber);
const auto dolpNormalizedImage = ImageUtility::CreateNormalized(
dolpImage,
SaveImage(dolpNormalizedImage,
"DoLP_Normalized.jpg", deviceSerialNumber);
{
}
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
return 1;
}
{
cout << endl << "*** IMAGE ACQUISITION ***" << endl << endl;
try
{
pCam->BeginAcquisition();
cout << "Acquiring an image from the polarized camera..." << endl;
CStringPtr ptrStringSerial = nodeMapTLDevice.GetNode(
"DeviceSerialNumber");
{
deviceSerialNumber = ptrStringSerial->GetValue();
cout << "Device serial number retrieved as " << deviceSerialNumber << "..." << endl;
}
cout << endl;
ImagePtr pRawPolarizedImage = pCam->GetNextImage(1000);
if (pRawPolarizedImage->IsIncomplete())
{
cout << "Image incomplete with image status " << pRawPolarizedImage->GetImageStatus() << "..." << endl
<< endl;
}
else
{
SaveImage(pRawPolarizedImage,
"Raw_Polarized_Image.jpg", deviceSerialNumber);
}
pRawPolarizedImage->Release();
cout << endl;
}
{
cout <<
"Error: " << e.
what() << endl;
return -1;
}
pCam->EndAcquisition();
return 0;
}
{
int result = 0;
try
{
INodeMap& nodeMapTLDevice = pCam->GetTLDeviceNodeMap();
pCam->Init();
{
}
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
int CreateAndSaveStokesImages(const ImagePtr &pRawPolarizedImage, gcstring &deviceSerialNumber)
Definition Polarization.cpp:387
static bool isPixelFormatColor
Definition Polarization.cpp:51
int CreateNormalizedImage(const ImagePtr &imageToNormalize, const string baseFilename, gcstring &deviceSerialNumber, SourceDataRange srcDataRange=SPINNAKER_SOURCE_DATA_RANGE_IMAGE_DATA_RANGE)
Definition Polarization.cpp:358
int ConfigureStream(INodeMap &nodeMap)
Definition Polarization.cpp:92
int ExtractAndSavePolarQuadImages(const ImagePtr &pRawPolarizedImage, gcstring &deviceSerialNumber)
Definition Polarization.cpp:282
int SaveImage(const ImagePtr &pImage, const string filename, gcstring &serialNumber)
Definition Polarization.cpp:179
int CreateAndSaveAolpDolpImages(const ImagePtr &pRawPolarizedImage, gcstring &deviceSerialNumber)
Definition Polarization.cpp:441
std::string GetQuadFileNameAppendage(const PolarizationQuadrant quadrant)
Definition Polarization.cpp:213
int CreateAndSaveGlareReducedImage(const ImagePtr &pRawPolarizedImage, gcstring &deviceSerialNumber)
Definition Polarization.cpp:331
int CreateHeatmapImages(const ImagePtr &mono8Image, const string baseFilename, gcstring &deviceSerialNumber)
Definition Polarization.cpp:232
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
virtual bool empty(void) const
virtual const char * c_str(void) const
virtual size_t length(void) const
A reference tracked pointer to an image object.
Definition ImagePtr.h:46
A reference tracked pointer to a system object.
Definition SystemPtr.h:44
@ PixelFormat_Mono8
Definition CameraDefs.h:731
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
PolarizationQuadrant
Polarization quadrant specifiers describing the four orientations of linear polarizing filters on pol...
Definition SpinnakerDefs.h:439
SourceDataRange
Image normalization source data options.
Definition SpinnakerDefs.h:409
@ SPINNAKER_POLARIZATION_QUADRANT_I90
The 90 degree of polarization.
Definition SpinnakerDefs.h:445
@ SPINNAKER_POLARIZATION_QUADRANT_I0
The 0 degree of polarization.
Definition SpinnakerDefs.h:441
@ SPINNAKER_POLARIZATION_QUADRANT_I45
The 45 degree of polarization.
Definition SpinnakerDefs.h:443
@ SPINNAKER_POLARIZATION_QUADRANT_I135
The 135 degree of polarization.
Definition SpinnakerDefs.h:447
@ SPINNAKER_SOURCE_DATA_RANGE_ABSOLUTE_DATA_RANGE
Normalize based on the theoretical max and min values for the source image.
Definition SpinnakerDefs.h:413
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