Simple API Unpacking and Merging Example Code.
This example shows you how to create a simple image loop and use the API to unpack and merge the image planes.
#include "stdint.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include <string>
#define FLI_TEST_MAX_SUPPORTED_CAMERAS (4)
static int32_t SetFrameInfo(int32_t iDeviceHandle, uint32_t uiWidth, uint32_t uiHeight);
static std::string MakeProcessedFileName(std::string& rstrFileName, uint32_t uiFrameNumber, const char* pSuffix, const char* pExt);
static void SaveProcessedFile(std::string strFileName, uint8_t* pMetaData, uint32_t uiMetaSize, uint8_t* pImageData, uint64_t uiImageByteSize);
static int32_t CheckReferenceMetaData(FILE* pFile);
static int32_t SendHWMergeReferenceFiles(int32_t iHandle, char* pDSNUFileName, char* pPRNUFileName, uint32_t uiWidth, uint32_t uiHeight);
static int32_t s_iDeviceHandle;
uint32_t uiNumDetectedDevices;
static FPRODEVICEINFO s_camDeviceInfo[FLI_TEST_MAX_SUPPORTED_CAMERAS];
int main()
{
int32_t iResult;
int32_t iGrabResult;
uint32_t i;
uint8_t *pFrame;
uint32_t uiFramSizeInBytes;
std::string strFileName;
uint32_t uiCapNum;
pFrame = NULL;
uiNumDetectedDevices = FLI_TEST_MAX_SUPPORTED_CAMERAS;
if ((iResult >= 0) && (uiNumDetectedDevices > 0))
{
s_iDeviceHandle = -1;
iResult =
FPROCam_Open(&s_camDeviceInfo[0], &s_iDeviceHandle);
if ((iResult >= 0) && (s_iDeviceHandle >= 0))
{
memset(&fproUnpacked, 0, sizeof(fproUnpacked));
memset(&fproStats, 0, sizeof(fproStats));
memset(&refFrames, 0, sizeof(refFrames));
if (iResult >= 0)
if (iResult >= 0)
if (iResult >= 0)
{
pFrame = (uint8_t *)malloc(uiFramSizeInBytes);
if (pFrame)
{
if (iResult >= 0)
{
iGrabResult = 0;
for (i = 0; (i < 10) && (iResult >= 0) && (iGrabResult >= 0); ++i)
{
if (iResult >= 0)
{
#if 1
ShowStats(&fproStats);
#else
#endif
if (iGrabResult >= 0)
{
printf("Got frame %d.\n",i);
#if 1
strFileName = "API_Unpack_Sample.rcd";
{
SaveProcessedFile(MakeProcessedFileName(strFileName, i,
"_MERGED_TIFF",
".tiff"), NULL, 0, (uint8_t*)fproUnpacked.
pMergedImage, fproUnpacked.
uiMergedBufferSize);
SaveProcessedFile(MakeProcessedFileName(strFileName, i,
"_MERGED_FITS",
".fits"), NULL, 0, (uint8_t*)fproUnpacked.
pMergedImage, fproUnpacked.
uiMergedBufferSize);
else
}
#endif
}
}
}
}
}
else
{
printf("ERROR getting frame memory.... leaving\n");
}
}
}
}
else
{
printf("ERROR: No cameras detected!\n\n");
}
if (pFrame)
free(pFrame);
return 0;
}
int32_t
SetFrameInfo(int32_t iDeviceHandle, uint32_t uiWidth, uint32_t uiHeight)
{
int32_t iResult;
iResult = 0;
if (iResult >= 0)
if (iResult >= 0)
return(iResult);
}
std::string MakeProcessedFileName(std::string & rstrFileName, uint32_t uiFrameNumber, const char* pSuffix, const char* pExt)
{
std::string strNew;
std::string strExt;
char cNumBuff[32];
size_t iIndex;
iIndex = rstrFileName.find_last_of('.', rstrFileName.length());
if (iIndex != std::string::npos)
{
strNew = rstrFileName.substr(0,iIndex);
snprintf(cNumBuff, sizeof(cNumBuff), "_%d_", uiFrameNumber);
strNew += cNumBuff;
strNew += pSuffix;
}
else
{
strNew = rstrFileName + pSuffix;
}
strNew += pExt;
return(strNew);
}
void SaveProcessedFile(std::string rstrFileName, uint8_t* pMetaData, uint32_t uiMetaSize, uint8_t* pImageData, uint64_t uiImageByteSize)
{
FILE* pFile;
int32_t iResult;
#if defined(_WIN32) || defined(_WINDOWS)
fopen_s(&pFile, rstrFileName.c_str(), "w+b");
#else
pFile= fopen(rstrFileName.c_str(), "w+b");
#endif
if (pFile)
{
iResult = 0;
if (pMetaData)
{
if (fwrite(pMetaData, 1, uiMetaSize, pFile) != uiMetaSize)
{
printf("Error writing Meta Data to file %s\n", rstrFileName.c_str());
iResult = -1;
}
}
if (iResult >= 0)
{
if (fwrite(pImageData, 1, (size_t)uiImageByteSize, pFile) != uiImageByteSize)
{
printf("Error writing Image Data to file %s\n", rstrFileName.c_str());
}
}
fclose(pFile);
}
else
{
printf("Error opening output file %s\n", rstrFileName.c_str());
}
}
int32_t CheckReferenceMetaData(FILE* pFile)
{
int32_t iResult;
size_t uiBytesRead;
uint32_t uiMetaSize;
uint32_t uiFileSize;
uint8_t uiMetaCheck[6];
iResult = -1;
fseek(pFile, 0L, SEEK_END);
uiFileSize = ftell(pFile);
fseek(pFile, 0L, SEEK_SET);
#if defined(_WIN32) || defined(_WINDOWS)
uiBytesRead = fread_s(uiMetaCheck, 6, 1, 6, pFile);
#else
uiBytesRead= fread(uiMetaCheck, 1, 6, pFile);
#endif
if (uiBytesRead == 6)
{
if ((uiMetaCheck[0] == 'M') && (uiMetaCheck[1] == 'e') && (uiMetaCheck[2] == 't') && (uiMetaCheck[3] == 'a'))
{
uiMetaSize = ((uint32_t)uiMetaCheck[4] & 0xFF) << 8;
uiMetaSize |= (uint32_t)uiMetaCheck[5] & 0xFF;
if (uiMetaSize < uiFileSize)
{
iResult= 0;
fseek(pFile, uiMetaSize, SEEK_SET);
}
}
}
return(iResult);
}
{
if (pStats)
{
printf("Mean: %f\n"
"Median: %f\n"
"Mode: %f\n"
"Std Dev: %f\n"
"Brightest: %d, (%d,%d)\n"
"Dimmest: %d, (%d,%d)\n",
}
else
{
printf("Unallocated\n");
}
}
{
if (NULL == pStats)
return;
printf("Low Stats: ");
printf("Not Requested\n");
else
{
printf("\n");
}
printf("\nHigh Stats: ");
printf("Not Requested\n");
else
{
printf("\n");
}
printf("\nMerged Stats: ");
printf("Not Requested\n");
else
{
printf("\n");
}
printf("\n");
}
int32_t SendHWMergeReferenceFiles(int32_t iHandle, char* pDSNUFileName, char* pPRNUFileName, uint32_t uiWidth, uint32_t uiHeight)
{
int32_t iResult;
FILE* pDSNUFile;
FILE* pPRNUFile;
uint32_t uiFrameSize;
size_t uiBytesRead;
iResult = -1;
pDSNUFile = NULL;
pPRNUFile = NULL;
#if defined(_WIN32) || defined(_WINDOWS)
fopen_s(&pDSNUFile, pDSNUFileName, "r+b");
fopen_s(&pPRNUFile, pPRNUFileName, "r+b");
#else
pDSNUFile= fopen(pDSNUFileName, "r+b");
pPRNUFile= fopen(pPRNUFileName, "r+b");
#endif
iResult = CheckReferenceMetaData(pDSNUFile);
if (iResult >= 0)
iResult = CheckReferenceMetaData(pPRNUFile);
if (iResult >= 0)
{
iResult = 0;
{
uiFrameSize = uiWidth * uiHeight * sizeof(uint16_t);
#if defined(_WIN32) || defined(_WINDOWS)
uiBytesRead = fread_s(refFrames.
pAdditiveLowGain, uiFrameSize, 1, uiFrameSize, pDSNUFile);
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
if (iResult >= 0)
{
#if defined(_WIN32) || defined(_WINDOWS)
uiBytesRead = fread_s(refFrames.
pAdditiveHighGain, uiFrameSize, 1, uiFrameSize, pDSNUFile);
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
}
if (iResult >= 0)
{
#if defined(_WIN32) || defined(_WINDOWS)
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
}
if (iResult >= 0)
{
#if defined(_WIN32) || defined(_WINDOWS)
#else
#endif
if (uiBytesRead != uiFrameSize)
iResult = -1;
}
if (iResult >= 0)
{
}
}
else
{
iResult = -1;
}
if (pDSNUFile)
fclose(pDSNUFile);
if (pPRNUFile)
fclose(pPRNUFile);
}
return(iResult);
}
Finger Lakes Instrumentation Camera API.
LIBFLIPRO_API FPROAlgo_SetHardwareMergeEnables(int32_t iHandle, FPRO_HWMERGEENABLE mergeEnables)
Enable/disable hardware merging options.
LIBFLIPRO_API FPROSensor_GetCapabilityList(int32_t iHandle, uint32_t *pCapList, uint32_t *pNumCaps)
Retrieves the capabilities list for the connected camera.
LIBFLIPRO_API FPROCam_Open(FPRODEVICEINFO *pDevInfo, int32_t *pHandle)
Connects to the camera specified by the pDevInfo parameter.
LIBFLIPRO_API FPROCam_Close(int32_t iHandle)
Disconnects from the camera an releases the handle.
LIBFLIPRO_API FPROAlgo_SetHardwareMergeReferenceFrames(int32_t iHandle, FPRO_REFFRAMES *pRefFrames)
Sets the reference frames used in PCIE Fibre hardware image merging.
@ IFORMAT_RCD
FLI native RCD Frame.
Definition: libflipro.h:1351
@ IFORMAT_TIFF
TIFF Formatted image.
Definition: libflipro.h:1352
@ IFORMAT_FITS
FITS formatted image.
Definition: libflipro.h:1353
@ FPROCAP_NUM
Number of supported capabilities.
Definition: libflipro.h:877
@ FPROCAP_MAX_PIXEL_WIDTH
Max allowed image width in pixels.
Definition: libflipro.h:860
@ FPROCAP_MAX_PIXEL_HEIGHT
Max allowed image height in pixels.
Definition: libflipro.h:861
LIBFLIPRO_API FPROFrame_SetImageDataEnable(int32_t iHandle, bool bEnable)
Enables image data imaging.
LIBFLIPRO_VOID FPROFrame_FreeUnpackedBuffers(FPROUNPACKEDIMAGES *pUPBuffers)
Frees the Unpacked Buffers within the given structure.
LIBFLIPRO_VOID FPROFrame_FreeUnpackedStatistics(FPROUNPACKEDSTATS *pStats)
Frees the Unpacked Statistics Buffers within the given structure.
LIBFLIPRO_API FPROFrame_ComputeFrameSize(int32_t iHandle)
Computes the size in bytes of the image frame.
LIBFLIPRO_API FPROCtrl_SetExposure(int32_t iHandle, uint64_t uiExposureTime, uint64_t uiFrameDelay, bool bImmediate)
Sets the exposure time of the image sensor.
@ HWMERGE_FRAME_BOTH
Normal merge, both low and high gain planes are corrected and merged.
Definition: libflipro.h:1565
LIBFLIPRO_API FPROFrame_CaptureStart(int32_t iHandle, uint32_t uiFrameCount)
Initiates the capture of the configured image.
LIBFLIPRO_API FPROFrame_SetImageArea(int32_t iHandle, uint32_t uiColOffset, uint32_t uiRowOffset, uint32_t uiWidth, uint32_t uiHeight)
Sets the area of the image sensor to be used to produce image frame data.
LIBFLIPRO_API FPROFrame_CaptureAbort(int32_t iHandle)
Aborts the active image capture.
LIBFLIPRO_API FPROFrame_GetVideoFrameUnpacked(int32_t iHandle, uint8_t *pFrameData, uint32_t *pSize, uint32_t uiTimeoutMS, FPROUNPACKEDIMAGES *pUPBuffers, FPROUNPACKEDSTATS *pStats)
Retrieves an image frame from the camera and optionally unpacks and merges the image planes.
LIBFLIPRO_API FPROCam_GetCameraList(FPRODEVICEINFO *pDeviceInfo, uint32_t *pNumDevices)
FPROCam_GetCameraList.
Definition: libflipro.h:365
Definition: libflipro.h:1607
FPRO_IMAGE_FORMAT eMergeFormat
The image file format for the merged image. The Actual PCIE card only supports RCD and TIFF....
Definition: libflipro.h:1609
FPRO_HWMERGEFRAMES eMergeFrames
Specifies the frames to merge.
Definition: libflipro.h:1610
bool bMergeEnable
True if merging enabled. This must be true for the other enables to have any effect....
Definition: libflipro.h:1608
Definition: libflipro.h:1761
FPROPIXELINFO pixDimmest
The location and value of the dimmest pixel in the plane.
Definition: libflipro.h:1772
double dblMedian
The median of the pixel values in the plane.
Definition: libflipro.h:1767
double dblMode
The mode of the pixel values in the plane.
Definition: libflipro.h:1768
FPROPIXELINFO pixBrightest
The location and value of the brightest pixel in the plane.
Definition: libflipro.h:1771
double dblMean
The mean of the pixel values in the plane.
Definition: libflipro.h:1766
double dblStandardDeviation
The standard deviation of the pixels in the plane.
Definition: libflipro.h:1769
int32_t X
The x coordinate.
Definition: libflipro.h:1712
int32_t Y
The y coordinate.
Definition: libflipro.h:1713
uint32_t uiValue
The pixel value.
Definition: libflipro.h:1731
FPROPOINT ptPosition
The x and y coordinate of the pixel within the plane.
Definition: libflipro.h:1730
Definition: libflipro.h:1321
uint16_t * pMultiplicativeLowGain
Low Gain Multiply Reference Frame.
Definition: libflipro.h:1327
int16_t * pAdditiveHighGain
High Gain Additive Reference Frame.
Definition: libflipro.h:1326
int16_t * pAdditiveLowGain
Low Gain Additive Reference Frame.
Definition: libflipro.h:1325
uint32_t uiWidth
Width of the frames in pixels.
Definition: libflipro.h:1322
uint32_t uiHeight
Height of the frames in pixels.
Definition: libflipro.h:1323
uint16_t * pMultiplicativeHighGain
High Gain Multiply Reference Frame.
Definition: libflipro.h:1328
Definition: libflipro.h:1671
bool bHighImageRequest
The High Image request Flag. Set to 'true' to unpack the high gain image plane.
Definition: libflipro.h:1685
FPRO_IMAGE_FORMAT eMergeFormat
On entry to the FPROFrame_GetVideoFrameUnpacked() API, it is the requested format for the unpacked/me...
Definition: libflipro.h:1693
uint8_t * pMergedMetaData
This meta data reflects the image data in the pMergedImage buffer.
Definition: libflipro.h:1687
bool bMetaDataRequest
The Meta Data request Flag. Set to 'true' to unpack meta data.
Definition: libflipro.h:1673
uint8_t * pLowMetaData
This meta data reflects the image data in the pLowImage buffer.
Definition: libflipro.h:1675
uint16_t * pLowImage
The Low Image Buffer.
Definition: libflipro.h:1676
uint64_t uiMergedBufferSize
The Size of the pMergedImage buffer in bytes. This will be different than uiMergedImageSize * sizeof(...
Definition: libflipro.h:1690
bool bMergedImageRequest
The Merged Image request Flag. Set to 'true' to merge the low and high gain image planes.
Definition: libflipro.h:1691
uint64_t uiHighBufferSize
The Size of the pHighImage buffer in bytes. This may be different than uiHighImageSize * sizeof(uint1...
Definition: libflipro.h:1684
uint8_t * pHighMetaData
This meta data reflects the image data in the pHighImage buffer.
Definition: libflipro.h:1681
uint16_t * pHighImage
The High Image Buffer.
Definition: libflipro.h:1682
uint32_t uiMetaDataSize
The Size of the pMetaData buffer in bytes.
Definition: libflipro.h:1672
bool bLowImageRequest
The Low Image request Flag. Set to 'true' to unpack the low gain image plane.
Definition: libflipro.h:1679
uint16_t * pMergedImage
The Merged Image Buffer.
Definition: libflipro.h:1688
uint64_t uiLowBufferSize
The Size of the pLowImage buffer in bytes. This may be different than uiLowImageSize * sizeof(uint16_...
Definition: libflipro.h:1678
Definition: libflipro.h:1797
FPROPLANESTATS statsMergedImage
The statistics for the merged image.
Definition: libflipro.h:1804
FPROPLANESTATS statsLowImage
The statistics for the low image.
Definition: libflipro.h:1798
bool bMergedRequest
Set to true to request the statistics for this image plane when unpacking.
Definition: libflipro.h:1805
bool bLowRequest
Set to true to request the statistics for this image plane when unpacking.
Definition: libflipro.h:1799
FPROPLANESTATS statsHighImage
The statistics for the high image.
Definition: libflipro.h:1801
bool bHighRequest
Set to true to request the statistics for this image plane when unpacking.
Definition: libflipro.h:1802