434 lines
17 KiB
C++
434 lines
17 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>ItkStreamWaitOneFrameReady<64>ӿڣ<D3BF>ͨ<EFBFBD><CDA8>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This example shows users how to use IKapC library to grab images continuously with
|
|||
|
|
* directly linked camera and ItkStreamWaitOneFrameReady api. */
|
|||
|
|
|
|||
|
|
#include <Windows.h>
|
|||
|
|
#include <malloc.h>
|
|||
|
|
#include <stdio.h>
|
|||
|
|
#include <stdlib.h>
|
|||
|
|
#include <process.h>
|
|||
|
|
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
#include "../GeneralConfigureCamera/ConfigureCamera.h"
|
|||
|
|
#include "../GeneralGrab/GeneralGrab.h"
|
|||
|
|
|
|||
|
|
#pragma comment(lib, "IKapBoard.lib")
|
|||
|
|
#pragma comment(lib, "IKapC.lib")
|
|||
|
|
|
|||
|
|
// ָʾ<D6B8>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// indicate whether exit the program or not
|
|||
|
|
bool g_bExit = false;
|
|||
|
|
|
|||
|
|
/* @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>ͼ<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);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD>̵߳<DFB3>ִ<EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲɼ<DAB2>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
|
|||
|
|
* @param[in] pUser<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This function is the execution function of the work thread for image acquisition.
|
|||
|
|
* @param[in] pUser<EFBFBD><EFBFBD>Input parameter. */
|
|||
|
|
unsigned int __stdcall WorkThread(void* pUser);
|
|||
|
|
|
|||
|
|
int main(void)
|
|||
|
|
{
|
|||
|
|
/// \~chinese IKapC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ \~english Return value of IKapC functions
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
ItkCamera cam;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>buffer<65><72><EFBFBD><EFBFBD> \~english Set count of buffers
|
|||
|
|
cam.g_bufferCount = 10;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>֡<EFBFBD><D6A1> \~english Set count of frames wanted
|
|||
|
|
cam.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.g_SerialNumber = NULL;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> \~english Enable softTrigger
|
|||
|
|
cam.g_bSoftTriggerUsed = 1;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>chunkdataΪ<61>ر<EFBFBD> \~english disable chunkdata
|
|||
|
|
cam.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.g_saveFileName, "D:\\CImage.tif");
|
|||
|
|
|
|||
|
|
printf("Itek Console GrabWithoutGrabber_WaitOneFrameReady Example(C version)\n");
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ʼ<EFBFBD><CABC> IKapC <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD> \~english Initialize IKapC runtime environment
|
|||
|
|
res = ItkManInitialize();
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
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
|
|||
|
|
int tmpIndex = -1;
|
|||
|
|
fprintf(stderr, "total device count: %d, the index of which you want to open is:", numDevices);
|
|||
|
|
fflush(stderr);
|
|||
|
|
int scanTmp = scanf_s("%u", &tmpIndex);
|
|||
|
|
if (scanTmp != 1) {
|
|||
|
|
fprintf(stderr, "Invalid input. Expect an integer.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (tmpIndex >= numDevices)
|
|||
|
|
{
|
|||
|
|
fprintf(stderr, "index: %d is more than %d.\n", tmpIndex, numDevices - 1);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
{ int getCharTmp = getchar(); }
|
|||
|
|
|
|||
|
|
ConfigureCamera(&cam, tmpIndex);
|
|||
|
|
|
|||
|
|
if (cam.g_hBoard != INVALID_HANDLE_VALUE) {
|
|||
|
|
fprintf(stderr, "Please select camera without grabber.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ \~english Configure trigger method of the camera
|
|||
|
|
SetSoftTriggerWithoutGrabber(&cam);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>chunkdata \~english Configure chunkdata of the camera
|
|||
|
|
SetChunkData(&cam, cam.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);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>waitOneFrameReady<64><79>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \~english Set grab strategy for waitOneFrameReady api
|
|||
|
|
uint32_t grabstrategy = ITKSTREAM_VAL_GRAB_STRATEGY_ONE_BY_ONE;
|
|||
|
|
res = ItkStreamSetPrm(cam.g_hStream,ITKSTREAM_PRM_GRAB_STRATEGY,&grabstrategy);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Register callback functions
|
|||
|
|
RegisterCallbackWithoutGrabber(&cam);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ʼͼ<CABC><CDBC><EFBFBD>ɼ<EFBFBD> \~english Start grabbing images
|
|||
|
|
res = ItkStreamStart(cam.g_hStream, cam.g_grabCount);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD>ڻ<EFBFBD>ȡͼ<C8A1><CDBC> \~english Create a worker thread that is used to acquire the images
|
|||
|
|
unsigned int nThreadID = 0;
|
|||
|
|
void* hThreadHandle = (void*)_beginthreadex(NULL, 0, WorkThread, &cam, 0, &nThreadID);
|
|||
|
|
if (NULL == hThreadHandle)
|
|||
|
|
{
|
|||
|
|
printf("fail to create workThread to grab image.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (cam.g_bSoftTriggerUsed) {
|
|||
|
|
printf("Please intput t to softTrigger a frame and input e to exit: ");
|
|||
|
|
while (true) {
|
|||
|
|
char T = 0;
|
|||
|
|
int tmp = scanf_s("%c", &T, (unsigned)sizeof(T));
|
|||
|
|
if (T == 't') {
|
|||
|
|
res = ItkDevExecuteCommand(cam.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(); }
|
|||
|
|
|
|||
|
|
g_bExit = true;
|
|||
|
|
|
|||
|
|
/// \~chinese ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD> \~english stop workThread
|
|||
|
|
WaitForSingleObject(hThreadHandle, INFINITE);
|
|||
|
|
CloseHandle(hThreadHandle);
|
|||
|
|
|
|||
|
|
/// \~chinese ֹͣͼ<D6B9><CDBC><EFBFBD>ɼ<EFBFBD> \~english Stop grabbing images
|
|||
|
|
ItkStreamStop(cam.g_hStream);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Unregister callback functions
|
|||
|
|
UnRegisterCallbackWithoutGrabber(&cam);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD> \~english Free data stream and buffers
|
|||
|
|
ItkDevFreeStream(cam.g_hStream);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸 \~english Close camera device
|
|||
|
|
res = ItkDevClose(cam.g_hCamera);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ͷ<EFBFBD><CDB7>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ڴ<EFBFBD> \~english Release the memory for storing the buffer data
|
|||
|
|
if (cam.g_bufferData != NULL)
|
|||
|
|
free(cam.g_bufferData);
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ͷ<EFBFBD><CDB7>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Buffer<65><72>ַ<EFBFBD><D6B7><EFBFBD>ڴ<EFBFBD> \~english Release the memory that the user requests for setting the Buffer address
|
|||
|
|
/*if (cam.g_user_buffer!=NULL)
|
|||
|
|
free(cam.g_user_buffer);*/
|
|||
|
|
|
|||
|
|
/// \~chinese <20>ͷ<EFBFBD> IKapC <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD> \~english Release IKapC runtime environment
|
|||
|
|
ItkManTerminate();
|
|||
|
|
|
|||
|
|
pressEnterToExit();
|
|||
|
|
return EXIT_SUCCESS;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD> \~english Register callback functions
|
|||
|
|
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);
|
|||
|
|
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_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);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unsigned int __stdcall WorkThread(void* pUser)
|
|||
|
|
{
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
ITKBUFFER hBuffer = NULL;
|
|||
|
|
ITK_BUFFER_INFO bufferInfo = {0};
|
|||
|
|
pItkCamera cam = (pItkCamera)pUser;
|
|||
|
|
if (NULL == cam)
|
|||
|
|
{
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
do
|
|||
|
|
{
|
|||
|
|
/// \~chinese timeout_ms <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>֡<EFBFBD><D6A1><EFBFBD>ڣ<EFBFBD><DAA3>˴<EFBFBD><CBB4><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \~english timeout_ms needs to be greater than the actual camera frame period, which needs to be modified according to the actual situation
|
|||
|
|
res = ItkStreamWaitOneFrameReady(cam->g_hStream, &hBuffer, 5000);
|
|||
|
|
if (g_bExit)
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
printf("On end of frame of camera with serialNumber:%s. \n",
|
|||
|
|
cam->g_devInfo.SerialNumber);
|
|||
|
|
|
|||
|
|
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, (uint32_t)bufferInfo.ValidImageSize);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC> \~english Save image
|
|||
|
|
/*
|
|||
|
|
res = ItkBufferSave(hBuffer,cam->g_saveFileName,ITKBUFFER_VAL_TIFF);
|
|||
|
|
CHECK(res);
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ItkStreamClearBuffer<65><72>Buffer<65>ͷ<EFBFBD> \~english need to call ItkStreamClearBuffer to release buffer
|
|||
|
|
res = ItkStreamClearBuffer(cam->g_hStream, hBuffer);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (nullptr != hConvert)
|
|||
|
|
ItkBufferFree(hConvert);
|
|||
|
|
}
|
|||
|
|
} while (!g_bExit);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
|