651 lines
27 KiB
C++
651 lines
27 KiB
C++
|
|
// main.cpp
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IKapC<70><43><EFBFBD><EFBFBD>IKapBoard<72>⣬<EFBFBD><E2A3AC>ITEK<45><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>ͼ<EFBFBD><CDBC>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This example shows users how to use IKapC library and IKapBoard Library to grab images continuously with
|
|||
|
|
* ITEK cameras. */
|
|||
|
|
|
|||
|
|
#include <Windows.h>
|
|||
|
|
#include <malloc.h>
|
|||
|
|
#include <stdio.h>
|
|||
|
|
#include <stdlib.h>
|
|||
|
|
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
#include "../GeneralConfigureCamera/ConfigureCamera.h"
|
|||
|
|
#include "../GeneralGrabWithGrabber/GeneralGrabWithGrabber.h"
|
|||
|
|
#include "../GeneralGrab/GeneralGrab.h"
|
|||
|
|
|
|||
|
|
#pragma comment(lib, "IKapBoard.lib")
|
|||
|
|
#pragma comment(lib, "IKapC.lib")
|
|||
|
|
#pragma comment(lib, "shlwapi.lib")
|
|||
|
|
|
|||
|
|
/* @brief<65><66>ע<EFBFBD><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Register callback functions. */
|
|||
|
|
void RegisterCallbackWithGrabber(pItkCamera pCam);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Unregister callback functions. */
|
|||
|
|
void UnRegisterCallbackWithGrabber(pItkCamera pCam);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When starting
|
|||
|
|
* grabbing images, the function will be called.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void CALLBACK OnGrabStart(void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡ͼ<D6A1><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When a frame of
|
|||
|
|
* image grabbing ready, the function will be called.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void CALLBACK OnFrameReady(void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ʱʱ<CAB1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When grabbing
|
|||
|
|
* images time out, the function will be called.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void CALLBACK OnTimeout(void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>֡ʱ<D6A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When grabbing
|
|||
|
|
* frame lost, the function will be called.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void CALLBACK OnFrameLost(void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD>ֹͣʱ<D6B9><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When stopping
|
|||
|
|
* grabbing images, the function will be called.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void CALLBACK OnGrabStop(void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66>ע<EFBFBD><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Register callback functions. */
|
|||
|
|
void RegisterCallbackWithoutGrabber(pItkCamera pCam);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Unregister callback functions. */
|
|||
|
|
void UnRegisterCallbackWithoutGrabber(pItkCamera pCam);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When data stream
|
|||
|
|
* starts, the function will be called.
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD>Event type.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void IKAPC_CC cbStartOfStream(uint32_t eventType, void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When data stream
|
|||
|
|
* ends, the function will be called.
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD>Event type.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void IKAPC_CC cbEndOfStream(uint32_t eventType, void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡ͼ<D6A1><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When grabbing a
|
|||
|
|
* frame of image finished, the function will be called.
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD>Event type.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void IKAPC_CC cbOnEndOfFrame(uint32_t eventType, void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ʱʱ<CAB1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When grabbing
|
|||
|
|
* images time out, the function will be called.
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD>Event type.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void IKAPC_CC cbOnTimeOut(uint32_t eventType, void* pContext);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϊһ<CEAA><D2BB><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>֡ʱ<D6A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is registered as a callback function. When grabbing
|
|||
|
|
* frame lost, the function will be called.
|
|||
|
|
* @param[in] eventType<EFBFBD><EFBFBD>Event type.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
void IKAPC_CC cbOnFrameLost(uint32_t eventType, void* pContext);
|
|||
|
|
|
|||
|
|
int main()
|
|||
|
|
{
|
|||
|
|
/// \~chinese IKapC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ \~english Return value of IKapC functions
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
/// \~chinese IKapBoard <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ \~english Return value of IKapBoard functions
|
|||
|
|
int ret = IK_RTN_OK;
|
|||
|
|
|
|||
|
|
int camCount = 0;
|
|||
|
|
|
|||
|
|
/*******************************/
|
|||
|
|
/// \~chinese <20><>ʼ<EFBFBD><CABC> IKapC <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> \~english Initialize IKapC runtime environment, Only need to run once
|
|||
|
|
res = ItkManInitialize();
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD>ӵ<EFBFBD>PC<50><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> \~english Get the current number of camera devices connected to PC, Only need to run once
|
|||
|
|
uint32_t numDevices = 0;
|
|||
|
|
res = ItkManGetDeviceCount(&numDevices);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
// <20><>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>豸ʱ<E8B1B8><CAB1>
|
|||
|
|
//
|
|||
|
|
// When there is no connected devices.
|
|||
|
|
if (numDevices == 0) {
|
|||
|
|
fprintf(stderr, "No device.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
printCameraInfo(numDevices);
|
|||
|
|
/*******************************/
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸 \~english Open camera with 0 index and configure camera device
|
|||
|
|
fprintf(stderr, "total device count: %d, the count of which you want to open is:", numDevices);
|
|||
|
|
fflush(stderr);
|
|||
|
|
int scanTmp = scanf_s("%u", &camCount);
|
|||
|
|
if (scanTmp != 1) {
|
|||
|
|
fprintf(stderr, "Invalid input. Expect an integer.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
{ int getCharTmp = getchar(); }
|
|||
|
|
|
|||
|
|
if (camCount <= 0) {
|
|||
|
|
fprintf(stderr, "count: %d is not more than 0.\n", camCount);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
if (camCount > (int)numDevices)
|
|||
|
|
{
|
|||
|
|
fprintf(stderr, "count: %d is more than %d.\n", camCount, numDevices);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
ItkCamera* cam = new ItkCamera[camCount];
|
|||
|
|
|
|||
|
|
for (int i = 0; i < camCount; i++) {
|
|||
|
|
{ /// \~chinese <20><><EFBFBD><EFBFBD>buffer<65><72><EFBFBD><EFBFBD> \~english Set count of buffers
|
|||
|
|
cam[i].g_bufferCount = 10;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>֡<EFBFBD><D6A1> \~english Set count of frames wanted
|
|||
|
|
cam[i].g_grabCount = ITKSTREAM_CONTINUOUS;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>g_SerialNumberΪNULL<4C><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ConfigureCamera<72><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>index<65><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \~english Set
|
|||
|
|
/// g_SerialNumber to NULL, ConfigureCamera function will use index to open camera later
|
|||
|
|
cam[i].g_SerialNumber = NULL;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ر<EFBFBD> \~english Disable softTrigger
|
|||
|
|
cam[i].g_bSoftTriggerUsed = 0;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>chunkdataΪ<61>ر<EFBFBD> \~english disable chunkdata
|
|||
|
|
cam[i].benableChunkData = false;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> \~english Set filename of image to be saved
|
|||
|
|
sprintf_s(cam[i].g_saveFileName, "D:\\CImage%d.tif", i);
|
|||
|
|
}
|
|||
|
|
int tmpIndex = -1;
|
|||
|
|
fprintf(stderr, "index of camera you want to open is:");
|
|||
|
|
fflush(stderr);
|
|||
|
|
int scanTmp = scanf_s("%u", &tmpIndex);
|
|||
|
|
if (scanTmp != 1) {
|
|||
|
|
fprintf(stderr, "Invalid input. Expect an integer.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
{ int getCharTmp = getchar(); }
|
|||
|
|
|
|||
|
|
if (tmpIndex >= (int)numDevices)
|
|||
|
|
{
|
|||
|
|
fprintf(stderr, "index: %d is more than %d.\n", tmpIndex, numDevices - 1);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
if (tmpIndex < 0)
|
|||
|
|
{
|
|||
|
|
fprintf(stderr, "index: %d is less than %d.\n", tmpIndex, 0);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
for (size_t i = 0; i < camCount; i++)
|
|||
|
|
{
|
|||
|
|
if (cam[i].g_index== tmpIndex)
|
|||
|
|
{
|
|||
|
|
fprintf(stderr, "index: %d is opened.\n", tmpIndex);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ConfigureCamera(&cam[i], tmpIndex);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (size_t i = 0; i < camCount; i++) {
|
|||
|
|
if (cam[i].g_hBoard != INVALID_HANDLE_VALUE) {
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ \~english Configure trigger method of the camera
|
|||
|
|
SetSoftTriggerWithGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD>òɼ<C3B2><C9BC><EFBFBD><EFBFBD>豸 \~english Configure frame grabber device
|
|||
|
|
ConfigureFrameGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Register callback functions.
|
|||
|
|
RegisterCallbackWithGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ʼͼ<CABC><CDBC><EFBFBD>ɼ<EFBFBD> \~english Start grabbing images
|
|||
|
|
StartGrabImage(&cam[i]);
|
|||
|
|
|
|||
|
|
if (cam[i].g_bSoftTriggerUsed) {
|
|||
|
|
printf("Please intput t to softTrigger a frame and input e to exit: ");
|
|||
|
|
while (true) {
|
|||
|
|
char T = 0;
|
|||
|
|
int scanTmp = scanf_s("%c", &T, (unsigned)sizeof(T));
|
|||
|
|
if (T == 't') {
|
|||
|
|
if (strcmp(cam[i].g_devInfo.DeviceClass, "CoaXPress") == 0 ||
|
|||
|
|
strcmp(cam[i].g_devInfo.DeviceClass, "CameraLink") == 0) {
|
|||
|
|
ret = IKapSetInfo(cam[i].g_hBoard, IKP_SOFTWARE_TRIGGER_START, 1);
|
|||
|
|
} else {
|
|||
|
|
res = ItkDevExecuteCommand(cam[i].g_hCamera, "TriggerSoftware");
|
|||
|
|
}
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
} else if (T == 'e') {
|
|||
|
|
break;
|
|||
|
|
} else if (T != '\n') {
|
|||
|
|
printf("Please intput t to softTrigger a frame and input e to exit: ");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ \~english Configure trigger method of the camera
|
|||
|
|
SetSoftTriggerWithoutGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>chunkdata \~english Configure chunkdata of the camera
|
|||
|
|
SetChunkData(&cam[i], cam[i].benableChunkData);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD> \~english Create data stream and buffer
|
|||
|
|
CreateStreamAndBuffer(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Register callback functions
|
|||
|
|
RegisterCallbackWithoutGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ʼͼ<CABC><CDBC><EFBFBD>ɼ<EFBFBD> \~english Start grabbing images
|
|||
|
|
res = ItkStreamStart(cam[i].g_hStream, cam[i].g_grabCount);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (cam[i].g_bSoftTriggerUsed) {
|
|||
|
|
printf("Please intput t to softTrigger a frame and input e to exit: ");
|
|||
|
|
while (true) {
|
|||
|
|
char T = 0;
|
|||
|
|
int scanTmp = scanf_s("%c", &T, (unsigned)sizeof(T));
|
|||
|
|
if (T == 't') {
|
|||
|
|
res = ItkDevExecuteCommand(cam[i].g_hCamera, "TriggerSoftware");
|
|||
|
|
} else if (T == 'e') {
|
|||
|
|
break;
|
|||
|
|
} else if (T != '\n') {
|
|||
|
|
printf("Please intput t to softTrigger a frame and input e to exit: ");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ȴ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD> \~english Wait for grabbing images finished
|
|||
|
|
{ int getCharTmp = getchar(); }
|
|||
|
|
|
|||
|
|
for (size_t i = 0; i < camCount; i++) {
|
|||
|
|
if (cam[i].g_hBoard != INVALID_HANDLE_VALUE) {
|
|||
|
|
/// \~chinese ֹͣͼ<D6B9><CDBC><EFBFBD>ɼ<EFBFBD> \~english Stop grabbing images
|
|||
|
|
ret = IKapStopGrab(cam[i].g_hBoard);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Unregister callback functions
|
|||
|
|
UnRegisterCallbackWithGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>رղɼ<D5B2><C9BC><EFBFBD><EFBFBD>豸 \~english Close frame grabber device
|
|||
|
|
ret = IKapClose(cam[i].g_hBoard);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸 \~english Close camera device
|
|||
|
|
res = ItkDevClose(cam[i].g_hCamera);
|
|||
|
|
CHECK_IKAPC(res);
|
|||
|
|
} else {
|
|||
|
|
/// \~chinese ֹͣͼ<D6B9><CDBC><EFBFBD>ɼ<EFBFBD> \~english Stop grabbing images
|
|||
|
|
ItkStreamStop(cam[i].g_hStream);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Unregister callback functions
|
|||
|
|
UnRegisterCallbackWithoutGrabber(&cam[i]);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD> \~english Free data stream and buffers
|
|||
|
|
ItkDevFreeStream(cam[i].g_hStream);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸 \~english Close camera device
|
|||
|
|
res = ItkDevClose(cam[i].g_hCamera);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (cam[i].g_bufferData != NULL)
|
|||
|
|
free(cam[i].g_bufferData);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
delete[] cam;
|
|||
|
|
/// \~chinese <20>ͷ<EFBFBD> IKapC <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD> \~english Release IKapC runtime environment
|
|||
|
|
ItkManTerminate();
|
|||
|
|
|
|||
|
|
pressEnterToExit();
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Register callback functions
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9>static<69><63><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ó<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3>ڸó<DAB8>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ǰ<EFBFBD><C7B0>ʹ<EFBFBD><CAB9> IKapUnRegisterCallback() ȡ<><C8A1>ע<EFBFBD><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ͷŵ<CDB7><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣
|
|||
|
|
/// \~english Use a static function declared with 'static' to register a callback, if using a member function, be aware of the lifetime of the object that owns the member function and unregister the callback by IKapUnRegisterCallback() before the object is destroyed, or if the callback is triggered after the object has been released, it will cause an exception
|
|||
|
|
void RegisterCallbackWithGrabber(pItkCamera pCam)
|
|||
|
|
{
|
|||
|
|
int ret = IK_RTN_OK;
|
|||
|
|
|
|||
|
|
ret = IKapRegisterCallback(pCam->g_hBoard, IKEvent_GrabStart, OnGrabStart, pCam);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
/// \~chinese ֡<><D6A1><EFBFBD>ɻص<C9BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>Ӧִ<D3A6>к<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1s/֡<><D6A1> <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʧ
|
|||
|
|
/// \~english in OnFrameReady callback function, should not execute time-consuming operation, and finish in time of 1s/framerate, or could cause framelost
|
|||
|
|
ret = IKapRegisterCallback(pCam->g_hBoard, IKEvent_FrameReady, OnFrameReady, pCam);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
ret = IKapRegisterCallback(pCam->g_hBoard, IKEvent_FrameLost, OnFrameLost, pCam);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
ret = IKapRegisterCallback(pCam->g_hBoard, IKEvent_TimeOut, OnTimeout, pCam);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
ret = IKapRegisterCallback(pCam->g_hBoard, IKEvent_GrabStop, OnGrabStop, pCam);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UnRegisterCallbackWithGrabber(pItkCamera pCam)
|
|||
|
|
{
|
|||
|
|
int ret = IK_RTN_OK;
|
|||
|
|
|
|||
|
|
ret = IKapUnRegisterCallback(pCam->g_hBoard, IKEvent_GrabStart);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
ret = IKapUnRegisterCallback(pCam->g_hBoard, IKEvent_FrameReady);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
ret = IKapUnRegisterCallback(pCam->g_hBoard, IKEvent_FrameLost);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
ret = IKapUnRegisterCallback(pCam->g_hBoard, IKEvent_TimeOut);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
ret = IKapUnRegisterCallback(pCam->g_hBoard, IKEvent_GrabStop);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CALLBACK OnGrabStart(void* pContext)
|
|||
|
|
{
|
|||
|
|
printf("Start grabbing image.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CALLBACK OnFrameReady(void* pContext)
|
|||
|
|
{
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
int ret = IK_RTN_OK;
|
|||
|
|
|
|||
|
|
pItkCamera cam = (pItkCamera)pContext;
|
|||
|
|
printf("Grab frame ready of camera with serialNumber:%s.\n", cam->g_devInfo.SerialNumber);
|
|||
|
|
unsigned char* pUserBuffer = NULL;
|
|||
|
|
int64_t nFrameSize = 0;
|
|||
|
|
int nFrameCount = 0;
|
|||
|
|
int nFrameIndex = 0;
|
|||
|
|
IKAPBUFFERSTATUS status;
|
|||
|
|
|
|||
|
|
ret = IKapGetInfo(cam->g_hBoard, IKP_FRAME_COUNT, &nFrameCount);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
ret = IKapGetInfo(cam->g_hBoard, IKP_CURRENT_BUFFER_INDEX, &nFrameIndex);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
ret = IKapGetBufferStatus(cam->g_hBoard, nFrameIndex, &status);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ͼ<EFBFBD><EFBFBD><F1BBBAB3><EFBFBD><EFBFBD><EFBFBD>ʱ \~english When the buffer is full
|
|||
|
|
if (status.uFull == 1) {
|
|||
|
|
/// \~chinese <20><>ȡһ֡ͼ<D6A1><CDBC><EFBFBD>Ĵ<EFBFBD>С \~english Get the size of a frame of image
|
|||
|
|
ret = IKapGetInfo64(cam->g_hBoard, IKP_FRAME_SIZE, &nFrameSize);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MultiExposureTimeCount<6E><74><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>Ҳɼ<D2B2><C9BC><EFBFBD><EFBFBD><EFBFBD>IKP_MULTIPLE_LIGHT_COUNT<4E><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>MultiExposureTimeCount<6E><74>ͬ<EFBFBD><CDAC>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6><EFBFBD><EFBFBD>ع<D8B9>ܣ<EFBFBD><DCA3>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪN<CEAA><4E><EFBFBD>ع<EFBFBD>ʱ<EFBFBD>䣬[0~1*Height/N-1]<5D>ж<EFBFBD>ӦExposureSelectΪ1ʱ<31><CAB1>ExposureTime<6D><65>[1*Height/N~2*Height/N-1]<5D>ж<EFBFBD>ӦExposureSelectΪ2ʱ<32><CAB1>ExposureTime<6D><65>...<2E><>[(N-1)*Height/N~Height-1]<5D>ж<EFBFBD>ӦExposureSelectΪNʱ<4E><CAB1>ExposureTime. \~english If the MultiExposureTimeCount feature value is greater than 1, the multiple exposure function is turned on, The collected images were all divided into N exposure times, line [0~1 * Height / N-1] corresponds to the ExposureTime at a ExposureSelect of 1, line [1 * Height / N~2 * Height / N-1] corresponds to ExposureTime at ExposureSelect 2,..., line [(N-1) * Height / N~Height-1] corresponds to ExposureTime at ExposureSelect N.
|
|||
|
|
/// \~chinese <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ \~english Get the buffer address
|
|||
|
|
ret = IKapGetBufferAddress(cam->g_hBoard, nFrameIndex, (void**)&pUserBuffer);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC> \~english Save image
|
|||
|
|
/*
|
|||
|
|
ret=IKapSaveBuffer(cam->g_hBoard,nFrameIndex,cam->g_saveFileName,IKP_DEFAULT_COMPRESSION);
|
|||
|
|
CHECK_IKAPBOARD(ret);
|
|||
|
|
|
|||
|
|
*/
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CALLBACK OnTimeout(void* pContext)
|
|||
|
|
{
|
|||
|
|
printf("Grab image timeout.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CALLBACK OnFrameLost(void* pContext)
|
|||
|
|
{
|
|||
|
|
printf("Grab frame lost.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CALLBACK OnGrabStop(void* pContext)
|
|||
|
|
{
|
|||
|
|
printf("Stop grabbing image.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Register callback functions
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9>static<69><63><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ó<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3>ڸó<DAB8>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ǰ<EFBFBD><C7B0>ʹ<EFBFBD><CAB9> ItkStreamUnregisterCallback() ȡ<><C8A1>ע<EFBFBD><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ͷŵ<CDB7><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣
|
|||
|
|
/// \~english Use a static function declared with 'static' to register a callback, if using a member function, be aware of the lifetime of the object that owns the member function and unregister the callback by ItkStreamUnregisterCallback() before the object is destroyed, or if the callback is triggered after the object has been released, it will cause an exception
|
|||
|
|
void RegisterCallbackWithoutGrabber(pItkCamera pCam)
|
|||
|
|
{
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
res = ItkStreamRegisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_START_OF_STREAM, cbStartOfStream, pCam);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkStreamRegisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_END_OF_STREAM, cbEndOfStream, pCam);
|
|||
|
|
CHECK(res);
|
|||
|
|
/// \~chinese ֡<><D6A1><EFBFBD>ɻص<C9BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>Ӧִ<D3A6>к<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1s/֡<><D6A1> <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʧ
|
|||
|
|
/// \~english in cbOnEndOfFrame callback function, should not execute time-consuming operation, and finish in time of 1s/framerate, or could cause framelost
|
|||
|
|
res = ItkStreamRegisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_END_OF_FRAME, cbOnEndOfFrame, pCam);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkStreamRegisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_TIME_OUT, cbOnTimeOut, pCam);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkStreamRegisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_FRAME_LOST, cbOnFrameLost, pCam);
|
|||
|
|
CHECK(res);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Unregister callback functions
|
|||
|
|
void UnRegisterCallbackWithoutGrabber(pItkCamera pCam)
|
|||
|
|
{
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
res = ItkStreamUnregisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_START_OF_STREAM);
|
|||
|
|
res = ItkStreamUnregisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_END_OF_STREAM);
|
|||
|
|
res = ItkStreamUnregisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_END_OF_FRAME);
|
|||
|
|
res = ItkStreamUnregisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_TIME_OUT);
|
|||
|
|
res = ItkStreamUnregisterCallback(pCam->g_hStream, ITKSTREAM_VAL_EVENT_TYPE_FRAME_LOST);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IKAPC_CC cbStartOfStream(uint32_t eventType, void* pContext)
|
|||
|
|
{
|
|||
|
|
pItkCamera cam = (pItkCamera)pContext;
|
|||
|
|
printf("On start of stream of camera with serialNumber:%s. \n", cam->g_devInfo.SerialNumber);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IKAPC_CC cbEndOfStream(uint32_t eventType, void* pContext)
|
|||
|
|
{
|
|||
|
|
pItkCamera cam = (pItkCamera)pContext;
|
|||
|
|
printf("On end of stream of camera with serialNumber:%s. \n", cam->g_devInfo.SerialNumber);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IKAPC_CC cbOnEndOfFrame(uint32_t eventType, void* pContext)
|
|||
|
|
{
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
ITKBUFFER hBuffer = NULL;
|
|||
|
|
pItkCamera cam = (pItkCamera)pContext;
|
|||
|
|
ITK_BUFFER_INFO bufferInfo = { 0 };
|
|||
|
|
printf("On end of frame of camera with serialNumber:%s. \n", cam->g_devInfo.SerialNumber);
|
|||
|
|
|
|||
|
|
// \~chinese <20><>ȡ<EFBFBD><C8A1>ǰbuffer \~english get current buffer
|
|||
|
|
res = ItkStreamGetCurrentBuffer(cam->g_hStream, &hBuffer);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
// \~chinese <20><>ȡ<EFBFBD><C8A1>ǰbuffer<65><72>Ϣ \~english get current buffer info
|
|||
|
|
res = ItkBufferGetInfo(hBuffer, &bufferInfo);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ͼ<EFBFBD><EFBFBD><F1BBBAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><F1BBBAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB7>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡ͼ<D6A1><CDBC>ʱ \~english When buffer is full or buffer is not full but cannot grab a complete frame of image
|
|||
|
|
if (bufferInfo.State == ITKBUFFER_VAL_STATE_FULL || bufferInfo.State == ITKBUFFER_VAL_STATE_UNCOMPLETED) {
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡchunk<6E><6B><EFBFBD>ݣ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ChunkModeActive<76>ѿ<EFBFBD><D1BF><EFBFBD><EFBFBD><EFBFBD>ChunkSelector<6F><72><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> \~english Get chunk data provided that ChunkModeActive is on and the following corresponding parameters in ChunkSelector are enabled
|
|||
|
|
if (cam->benableChunkData)
|
|||
|
|
{
|
|||
|
|
int64_t nChunkWidth = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkWidth", &nChunkWidth);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
int64_t nChunkHeight = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkHeight", &nChunkHeight);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
int64_t nChunkOffsetX = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkOffsetX", &nChunkOffsetX);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
int64_t nChunkOffsetY = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkOffsetY", &nChunkOffsetY);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
char strChunkPixelFormat[128] = { 0 };
|
|||
|
|
uint32_t strLen = sizeof(strChunkPixelFormat);
|
|||
|
|
res = ItkBufferToChunkString(hBuffer, "ChunkPixelFormat",
|
|||
|
|
strChunkPixelFormat, &strLen);
|
|||
|
|
|
|||
|
|
int64_t nChunkTimestamp = 0;
|
|||
|
|
res =
|
|||
|
|
ItkBufferGetChunkInt64(hBuffer, "ChunkTimestamp", &nChunkTimestamp);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
double dchunkGain = 0;
|
|||
|
|
res = ItkBufferGetChunkDouble(hBuffer, "ChunkGain", &dchunkGain);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese ֻ<>в<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD> \~english Only the color cameras have these parameters
|
|||
|
|
/*{
|
|||
|
|
double dchunkRedGain = 0;
|
|||
|
|
res =
|
|||
|
|
ItkBufferGetChunkDouble(hBuffer, "ChunkRedGain", &dchunkRedGain);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
double dChunkG1Gain = 0;
|
|||
|
|
res = ItkBufferGetChunkDouble(hBuffer, "ChunkG1Gain", &dChunkG1Gain);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
double dChunkG2Gain = 0;
|
|||
|
|
res = ItkBufferGetChunkDouble(hBuffer, "ChunkG2Gain", &dChunkG2Gain);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
double dChunkBlueGain = 0;
|
|||
|
|
res = ItkBufferGetChunkDouble(hBuffer, "ChunkBlueGain",
|
|||
|
|
&dChunkBlueGain);
|
|||
|
|
CHECK(res);
|
|||
|
|
} */
|
|||
|
|
|
|||
|
|
int64_t nChunkExposureTime = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkExposureTime",
|
|||
|
|
&nChunkExposureTime);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
int64_t nChunkBrightnessInfo = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkBrightnessInfo",
|
|||
|
|
&nChunkBrightnessInfo);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
int64_t nChunkFrameCounter = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkFrameCounter",
|
|||
|
|
&nChunkFrameCounter);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
int64_t nChunkExtTriggerCount = 0;
|
|||
|
|
res = ItkBufferGetChunkInt64(hBuffer, "ChunkExtTriggerCount",
|
|||
|
|
&nChunkExtTriggerCount);
|
|||
|
|
CHECK(res);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ITKBUFFER hConvert = nullptr;
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ظ<EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ת<EFBFBD><D7AA> \~english Judge if need convert
|
|||
|
|
|
|||
|
|
if (bufferInfo.NeedAutoConvert) {
|
|||
|
|
res = ItkBufferNew(1024, 1204, ITKBUFFER_VAL_FORMAT_MONO8, &hConvert);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkBufferConvert(hBuffer, hConvert, 0, ITKBUFFER_VAL_CONVERT_OPTION_AUTO_FORMAT);
|
|||
|
|
CHECK(res);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>MultiExposureTimeCount<6E><74><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6><EFBFBD><EFBFBD>ع<D8B9>ܣ<EFBFBD><DCA3>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪN<CEAA><4E><EFBFBD>ع<EFBFBD>ʱ<EFBFBD>䣬[0~1*Height/N-1]<5D>ж<EFBFBD>ӦExposureSelectΪ1ʱ<31><CAB1>ExposureTime<6D><65>[1*Height/N~2*Height/N-1]<5D>ж<EFBFBD>ӦExposureSelectΪ2ʱ<32><CAB1>ExposureTime<6D><65>...<2E><>[(N-1)*Height/N~Height-1]<5D>ж<EFBFBD>ӦExposureSelectΪNʱ<4E><CAB1>ExposureTime. \~english If the MultiExposureTimeCount feature value is greater than 1, the multiple exposure function is turned on, The collected images were all divided into N exposure times, line [0~1 * Height / N-1] corresponds to the ExposureTime at a ExposureSelect of 1, line [1 * Height / N~2 * Height / N-1] corresponds to ExposureTime at ExposureSelect 2,..., line [(N-1) * Height / N~Height-1] corresponds to ExposureTime at ExposureSelect N.
|
|||
|
|
|
|||
|
|
res = ItkBufferRead(hBuffer, 0, cam->g_bufferData, bufferInfo.ValidImageSize);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC> \~english Save image
|
|||
|
|
/*
|
|||
|
|
res = ItkBufferSave(hBuffer,cam->g_saveFileName,ITKBUFFER_VAL_TIFF);
|
|||
|
|
CHECK(res);
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
if (nullptr != hConvert)
|
|||
|
|
ItkBufferFree(hConvert);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IKAPC_CC cbOnTimeOut(uint32_t eventType, void* pContext)
|
|||
|
|
{
|
|||
|
|
pItkCamera cam = (pItkCamera)pContext;
|
|||
|
|
printf("on time out of camera with serialNumber:%s. \n", cam->g_devInfo.SerialNumber);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void IKAPC_CC cbOnFrameLost(uint32_t eventType, void* pContext)
|
|||
|
|
{
|
|||
|
|
pItkCamera cam = (pItkCamera)pContext;
|
|||
|
|
printf("on frame lost of camera with serialNumber:%s. \n", cam->g_devInfo.SerialNumber);
|
|||
|
|
}
|