Simple Image Loop Example Code.
This example shows you how to create a simple image loop to grab and process image frames one at a time.
#if defined(_WIN32) || defined(_WINDOWS)
#include "stdafx.h"
#else
#include <stdio.h>
#endif
#include "stdint.h"
#include "stdlib.h"
#define FLI_TEST_MAX_SUPPORTED_CAMERAS (4)
#define MSEC_TO_NSEC(__msec) ((uint64_t)__msec * 1000000)
#define NSEC_TO_MSEC(__nsec) (__nsec / 1000000)
static int32_t SetFrameInfo(int32_t iDeviceHandle,
FPROCAP *pCaps);
static int32_t s_iDeviceHandle;
uint32_t uiNumDetectedDevices;
static FPRODEVICEINFO s_camDeviceInfo[FLI_TEST_MAX_SUPPORTED_CAMERAS];
static uint64_t s_uiExposureTimeNSec;
int main()
{
int32_t iResult;
int32_t iGrabResult;
uint32_t i;
uint8_t *pFrame;
uint32_t uiFramSizeInBytes;
uint32_t uiSizeGrabbed;
uint32_t uiCamCapSize;
pFrame = NULL;
s_uiExposureTimeNSec= MSEC_TO_NSEC(50);
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))
{
if (iResult >= 0)
iResult = SetFrameInfo(s_iDeviceHandle,&s_camCapabilities);
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)
{
uiSizeGrabbed = uiFramSizeInBytes;
iGrabResult =
FPROFrame_GetVideoFrame(s_iDeviceHandle, pFrame, &uiSizeGrabbed, NSEC_TO_MSEC(s_uiExposureTimeNSec));
if (iGrabResult >= 0)
{
printf("Got frame %d.\n",i);
if (uiSizeGrabbed == uiFramSizeInBytes)
{
}
else
{
printf("Got incorrect size for frame %d: got 0x%x, wanted 0x%x\n",i, uiSizeGrabbed, uiFramSizeInBytes);
}
}
else
{
printf("ERROR returned from FPROFrame_GetVideoFrame\n");
}
}
}
}
}
else
{
printf("ERROR getting frame memory.... leaving\n");
}
}
}
}
if (pFrame)
free(pFrame);
return 0;
}
int32_t
SetFrameInfo(int32_t iDeviceHandle,
FPROCAP *pCaps)
{
int32_t iResult;
iResult = 0;
if (iResult >= 0)
if (iResult >= 0)
return(iResult);
}