It can also be helpful to familiarize yourself with the ImageFormatControl_C and Exposure_C examples. As they are somewhat shorter and simpler, either provides a strong introduction to camera customization.
Chunk data provides information on various traits of an image. This includes identifiers such as frame ID, properties such as black level, and more. This information can be acquired from either the nodemap or the image itself.
It may be preferable to grab chunk data from each individual image, as it can be hard to verify whether data is coming from the correct image when using the nodemap. This is because chunk data retrieved from the nodemap is only valid for the current image; when spinCameraGetNextImage() or spinCameraGetNextImageEx() is called, chunk data will be updated to that of the new current image.
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define MAX_BUFF_LEN 256
{
}
{
{
printf(
"Unable to retrieve node readability (%s node) with error: %s [%d]\n\n",
nodeName,
err);
}
return pbReadable;
}
{
{
printf(
"Unable to retrieve node writability (%s node) with error: %s [%d]\n\n",
nodeName,
err);
}
return pbWritable;
}
{
} chunkDataType;
{
unsigned int i = 0;
printf("\n\n*** CONFIGURING CHUNK DATA ***\n\n");
{
printf(
"Unable to activate chunk mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (
IsWritable(hChunkModeActive,
"ChunkModeActive"))
{
{
printf(
"Unable to activate chunk mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
else
{
printf(
"Unable to write to chunk mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Chunk mode activated...\n");
size_t numEntries = 0;
{
printf(
"Unable to retrieve chunk selector entries. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
{
printf(
"Unable to retrieve number of entries. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
else
{
printf(
"Unable to read number of entries. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Enabling entries...\n");
for (i = 0; i < numEntries; i++)
{
{
printf("\tUnable to enable chunk entry (error %d)...\n\n", err);
continue;
}
{
{
printf("\t%s: unable to retrieve chunk entry display name (error %d)...\n", entryName, err);
}
}
else
{
continue;
}
int64_t value = 0;
{
printf("\t%s: unable to get chunk entry value (error %d)...\n", entryName, err);
continue;
}
{
{
printf("\t%s: unable to set chunk entry value (error %d)...\n", entryName, err);
continue;
}
}
else
{
printf("\t%s: unable to write to chunk entry value (error %d)...\n", entryName, err);
return err;
}
{
printf("\t%s: unable to get entry from nodemap (error %d)...\n", entryName, err);
continue;
}
{
{
printf("\t%s: unable to get chunk entry boolean value (error %d)...\n", entryName, err);
continue;
}
}
else
{
printf("\t%s: not writable\n", entryName);
continue;
}
if (!isEnabled || !
IsWritable(hChunkEnable,
"ChunkEnable"))
{
{
printf("\t%s: unable to set chunk entry boolean value (error %d)...\n", entryName, err);
continue;
}
}
printf("\t%s: enabled\n", entryName);
}
return err;
}
{
printf("\n\t\t");
for (int64_t i = 0; i < length - 1; ++i)
{
if (i != 0 && i % 8 == 0)
{
printf("\n\t\t");
}
printf("0x%02x ", (unsigned int)(array[i]));
}
printf("\n");
}
{
printf("Print chunk data from image...\n");
double exposureTime = 0.0;
{
printf(
"Unable to retrieve exposure time from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tExposure time: %f\n", exposureTime);
double compressionRatio = 0.0;
{
printf(
"Unable to retrieve compression ratio from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tCompression ratio: %f\n", compressionRatio);
int64_t frameID = 0;
{
printf(
"Unable to retrieve frame ID from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tFrame ID: %d\n", (int)frameID);
double gain = 0.0;
{
printf(
"Unable to retrieve gain from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tGain: %f\n", gain);
int64_t height = 0;
{
printf(
"Unable to retrieve height from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tHeight: %d\n", (int)height);
int64_t offsetX = 0;
{
printf(
"Unable to retrieve offset X from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tOffset X: %d\n", (int)offsetX);
int64_t offsetY = 0;
{
printf(
"Unable to retrieve offset Y from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tOffset Y: %d\n", (int)offsetY);
int64_t width = 0;
{
printf(
"Unable to retrieve width from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tWidth: %d\n", (int)width);
int64_t serialDataLength = 0;
{
printf(
"Unable to retrieve serial data length from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
if (serialDataLength > 0)
{
printf("\tSerial Data (%lld) Bytes:", serialDataLength);
{
printf(
"Unable to retrieve serial receive overflow value from image chunk data. Aborting with error: %s "
"[%d]\n\n",
err);
return err;
}
if (serialReceiveOverFlow)
{
printf("\t Warning: Device serial data buffer overflow\n");
}
uint8_t* pSerialData = 0;
{
if (pSerialData == NULL)
{
printf("Unable to retrieve serial data from image chunk data. Serial data was null\n\n");
}
printf(
"Unable to retrieve serial data from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
}
double blackLevel = 0.0;
{
printf(
"Unable to retrieve black level from image chunk data. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("\tBlack level: %f\n", blackLevel);
return err;
}
{
unsigned int i = 0;
size_t numFeatures = 0;
{
printf(
"Unable to retrieve chunk data control. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (!
IsReadable(hChunkDataControl,
"ChunkDataControl"))
{
printf("Unable to retrieve chunk data control. Aborting...\n\n");
}
{
printf("Unable to retrieve number of nodes (error %d)...\n\n", err);
return err;
}
printf("Printing chunk data from nodemap...\n");
for (i = 0; i < numFeatures; i++)
{
if (
IsReadable(hChunkDataControl,
"ChunkDataControl"))
{
{
printf("Unable to retrieve node (error %d)...\n\n", err);
continue;
}
}
else
{
printf("Unable to retrieve node (error %d)...\n\n", err);
continue;
}
{
strcpy(featureName, "Unknown name");
}
{
{
printf(
"Unable to retrieve node type. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
continue;
}
}
else
{
printf(
"Unable to retrieve node type. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
continue;
}
{
int64_t featureValue = 0;
printf("\t%s: %d\n", featureName, (int)featureValue);
}
{
double featureValue = 0.0;
printf("\t%s: %f\n", featureName, featureValue);
}
{
if (featureValue)
{
printf("\t%s: true\n", featureName);
}
else
{
printf("\t%s: false\n", featureName);
}
}
}
return err;
}
{
unsigned int i = 0;
printf("\n*** DEVICE INFORMATION ***\n\n");
{
return err;
}
size_t numFeatures = 0;
if (
IsReadable(hDeviceInformation,
"DeviceInformation"))
{
{
printf(
"Unable to retrieve number of nodes. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
else
{
printf(
"Unable to read device information. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
for (i = 0; i < numFeatures; i++)
{
{
continue;
}
{
strcpy(featureName, "Unknown name");
}
{
{
printf(
"Unable to retrieve node type. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
continue;
}
}
else
{
printf("%s: Node not readable\n", featureName);
continue;
}
{
strcpy(featureValue, "Unknown value");
}
printf("%s: %s\n", featureName, featureValue);
}
printf("\n");
return err;
}
{
printf("\n*** IMAGE ACQUISITION ***\n\n");
int64_t acquisitionModeContinuous = 0;
{
printf(
"Unable to set acquisition mode to continuous (node retrieval). Aborting with error: %s [%d]\n\n",
err);
return err;
}
if (
IsReadable(hAcquisitionMode,
"AcquisitionMode"))
{
{
printf(
"Unable to set acquisition mode to continuous (entry 'continuous' retrieval). Aborting with error "
"%d...\n\n",
err);
return err;
}
}
else
{
printf(
"Unable to read acquisition mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (
IsReadable(hAcquisitionModeContinuous,
"AcquisitionModeContinuous"))
{
{
printf(
"Unable to set acquisition mode to continuous (entry int value retrieval). Aborting with error "
"%d...\n\n",
err);
return err;
}
}
else
{
printf(
"Unable to read acquisition mode continuous. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (
IsWritable(hAcquisitionMode,
"AcquisitionMode"))
{
{
printf(
"Unable to set acquisition mode to continuous (entry int value setting). Aborting with error %d...\n\n",
err);
return err;
}
printf("Acquisition mode set to continuous...\n");
}
else
{
printf(
"Unable to write to acquisition mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to begin image acquisition. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Acquiring images...\n");
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
else
{
if (
IsReadable(hDeviceSerialNumber,
"DeviceSerialNumber"))
{
err =
spinStringGetValue(hDeviceSerialNumber, deviceSerialNumber, &lenDeviceSerialNumber);
{
printf(
"Unable to get device serial number. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
printf("Device serial number retrieved as %s...\n", deviceSerialNumber);
}
else
{
printf(
"Unable to get device serial number. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
}
printf("\n");
const unsigned int k_numImages = 10;
unsigned int imageCnt = 0;
{
printf(
"Unable to create image processor. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
{
printf(
"Unable to set image processor color processing method. Non-fatal error: %s [%d]\n\n",
err);
}
for (imageCnt = 0; imageCnt < k_numImages; imageCnt++)
{
{
continue;
}
{
printf(
"Unable to determine image completion. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
if (isIncomplete)
{
{
printf(
"Unable to retrieve image status. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
else
{
printf("Image incomplete with image status %d...\n", imageStatus);
}
}
if (hasFailed)
{
{
}
continue;
}
size_t width = 0;
size_t height = 0;
{
printf(
"Unable to retrieve image width. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
{
printf(
"Unable to retrieve image height. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
printf("Grabbed image %u, width = %u, height = %u\n", imageCnt, (unsigned int)width, (unsigned int)height);
{
}
{
}
if (lenDeviceSerialNumber == 0)
{
sprintf(filename, "ChunkData-C-%d.jpg", imageCnt);
}
else
{
sprintf(filename, "ChunkData-C-%s-%d.jpg", deviceSerialNumber, imageCnt);
}
{
}
else
{
printf("Image saved at %s\n", filename);
}
{
{
return err;
}
}
{
{
return err;
}
}
printf("\n");
{
}
{
}
}
{
printf(
"Unable to destroy image processor. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
{
}
return err;
}
{
size_t numEntries = 0;
unsigned int i = 0;
{
printf(
"Unable to retrieve chunk selector entries. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
{
printf(
"Unable to retrieve number of entries. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
else
{
printf(
"Unable to read number of entries. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Disabling entries...\n");
for (i = 0; i < numEntries; i++)
{
{
continue;
}
{
{
printf("\t%s: unable to retrieve chunk entry by display name (error %d)...\n", entryName, err);
}
}
else
{
continue;
}
int64_t value = 0;
{
printf("\t%s: unable to get chunk entry value (error %d)...\n", entryName, err);
continue;
}
{
{
printf("\t%s: unable to set chunk entry value (error %d)...\n", entryName, err);
continue;
}
}
else
{
printf("\t%s: unable to set chunk entry value (error %d)...\n", entryName, err);
return err;
}
{
printf("\t%s: unable to get entry from nodemap (error %d)...\n", entryName, err);
continue;
}
{
{
printf("\t%s: unable to get chunk entry boolean value (error %d)...\n", entryName, err);
continue;
}
}
else
{
printf("\t%s: not writable\n", entryName);
continue;
}
if (isEnabled)
{
{
printf("\t%s: unable to set chunk entry boolean value (error %d)...\n", entryName, err);
continue;
}
}
printf("\t%s: disabled\n", entryName);
}
printf("\n");
{
printf(
"Unable to get ChunkModeActive node. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
if (
IsWritable(hChunkModeActive,
"ChunkModeActive"))
{
{
printf(
"Unable to deactivate chunk mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
}
else
{
printf(
"Unable to write to chunk mode. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Chunk mode deactivated...\n");
return err;
}
{
{
printf(
"Unable to retrieve TL device nodemap. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
else
{
{
return err;
}
}
if (hDeviceModelName != NULL &&
IsReadable(hDeviceModelName,
"DeviceModelName"))
{
{
return err;
}
if (strstr(deviceModelName, "BX") != NULL)
{
printf("This example is not compatible with BX (Bumblebee) stereo cameras. Please see "
"StereoAcquisition (C++ Only) Example for ChunkData usage with this camera.\n");
}
}
{
printf(
"Unable to initialize camera. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to retrieve GenICam nodemap. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
return err;
}
{
return err;
}
{
return err;
}
{
printf(
"Unable to deinitialize camera. Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
return err;
}
{
unsigned int i = 0;
FILE* tempFile;
tempFile = fopen("test.txt", "w+");
if (tempFile == NULL)
{
printf("Failed to create file in current folder. Please check "
"permissions.\n");
printf("Press Enter to exit...\n");
getchar();
return -1;
}
fclose(tempFile);
remove("test.txt");
printf("Application build date: %s %s \n\n", __DATE__, __TIME__);
{
printf(
"Unable to retrieve system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
spinLibraryVersion hLibraryVersion;
printf(
"Spinnaker library version: %d.%d.%d.%d\n\n",
hLibraryVersion.major,
hLibraryVersion.minor,
hLibraryVersion.type,
hLibraryVersion.build);
{
printf(
"Unable to create camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to retrieve camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
size_t numCameras = 0;
{
printf(
"Unable to retrieve number of cameras. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Number of cameras detected: %u\n\n", (unsigned int)numCameras);
if (numCameras == 0)
{
{
printf(
"Unable to clear camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to destroy camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to release system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Not enough cameras!\n");
printf("Done! Press Enter to exit...\n");
getchar();
return -1;
}
for (i = 0; i < numCameras; i++)
{
printf("\nRunning example for camera %d...\n", i);
{
printf(
"Unable to retrieve camera from list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
errReturn = err;
}
else
{
{
errReturn = err;
}
}
{
errReturn = err;
}
printf("Camera %d example complete...\n\n", i);
}
{
printf(
"Unable to clear camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to destroy camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to release system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("\nDone! Press Enter to exit...\n");
getchar();
return errReturn;
}