672 lines
21 KiB
C++
672 lines
21 KiB
C++
|
|
// ReconnectDemo.cpp
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GigEVision<6F><6E>USB3Vision<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ɻص<C9BB><D8B5><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵȴ<DFB5><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߺ<EFBFBD><DFBA>ٲ<EFBFBD><D9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߡ<EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>This example shows the user how to reconnect GigEVision or USB3Vision camera. After the end of frame is printed, unplug the data cable and wait for the camera to drop and then plug in the data cable. */
|
|||
|
|
|
|||
|
|
#include <Windows.h>
|
|||
|
|
#include <fstream>
|
|||
|
|
#include <malloc.h>
|
|||
|
|
#include <stdio.h>
|
|||
|
|
#include <stdlib.h>
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
#include "IKapC.h"
|
|||
|
|
#pragma comment(lib, "IKapC.lib")
|
|||
|
|
|
|||
|
|
// ͼ<><EFBFBD><F1BBBAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
|||
|
|
// <20><><EFBFBD>棡<EFBFBD><E6A3A1><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><F1BBBAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>Ϊ1<CEAA><31><EFBFBD><EFBFBD><EFBFBD>ܻᷢ<DCBB><E1B7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// The number of frames requested by buffer.
|
|||
|
|
// WARNING! If STREAM_BUFFER_COUNT is set to 1, BufferOverFlow may happen!
|
|||
|
|
#define STREAM_BUFFER_COUNT 10
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Camera device handle.
|
|||
|
|
ITKDEVICE g_hCamera = NULL;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Data stream handle.
|
|||
|
|
ITKSTREAM g_hStream = NULL;
|
|||
|
|
|
|||
|
|
// <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʼȡ<CABC><C8A1>
|
|||
|
|
//
|
|||
|
|
// start stream or not
|
|||
|
|
bool bIsStartStream = false;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// File name of image.
|
|||
|
|
const char* g_saveFileName = "C:\\CImage.tif";
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Buffer data.
|
|||
|
|
char* g_bufferData = NULL;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//
|
|||
|
|
// info of camera opened.
|
|||
|
|
ITKDEV_INFO g_di = { 0 };
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD>жϺ<D0B6><CFBA><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
* @param[in] errc<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Determine whether the function is called successfully.
|
|||
|
|
* @param[in] errc<EFBFBD><EFBFBD>Function return value. */
|
|||
|
|
#define CHECK(errc) \
|
|||
|
|
if (ITKSTATUS_OK != errc) \
|
|||
|
|
printErrorAndExit(errc)
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Users enter Enter to exit the program. */
|
|||
|
|
void pressEnterToExit(void);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
* @param[in] errc<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Print error message and exit the program.
|
|||
|
|
* @param[in] errc<EFBFBD><EFBFBD>Function return value. */
|
|||
|
|
void printErrorAndExit(ITKSTATUS errc);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Configure camera device. */
|
|||
|
|
void ConfigureCamera(int index = 0);
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Create data stream and buffer. */
|
|||
|
|
void CreateStreamAndBuffer();
|
|||
|
|
|
|||
|
|
/* @brief<65><66>ע<EFBFBD><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Register callback functions. */
|
|||
|
|
void RegisterCallback();
|
|||
|
|
|
|||
|
|
/* @brief<65><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*
|
|||
|
|
* @brief<EFBFBD><EFBFBD>Unregister callback functions. */
|
|||
|
|
void UnRegisterCallback();
|
|||
|
|
|
|||
|
|
/* @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);
|
|||
|
|
|
|||
|
|
/* @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><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 device
|
|||
|
|
* removed singal ignored, the function will be called.
|
|||
|
|
* @param[in] pContext<EFBFBD><EFBFBD>Input parameter.
|
|||
|
|
* @param[in] eventInfo<EFBFBD><EFBFBD>Output parameter. */
|
|||
|
|
void IKAPC_CC cbOnReconnect(void* pContext, ITKEVENTINFO eventInfo);
|
|||
|
|
|
|||
|
|
int main(void) {
|
|||
|
|
// IKapC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
|
|||
|
|
//
|
|||
|
|
// Return value of IKapC functions.
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// The number of available devices.
|
|||
|
|
uint32_t numDevices = 0;
|
|||
|
|
|
|||
|
|
// <20><>Ҫ<EFBFBD><EFBFBD><F2BFAAB5>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// The index of device to be opened.
|
|||
|
|
uint32_t devIndex = 0;
|
|||
|
|
|
|||
|
|
printf("Itek Console Find Camera Example (C version)\n");
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC> IKapC <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Initialize IKapC runtime environment.
|
|||
|
|
res = ItkManInitialize();
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
// ö<>ٿ<EFBFBD><D9BF><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>豸ǰ<E8B1B8><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ItkManGetDeviceCount() <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Enumerate the number of available devices. Before opening the device,
|
|||
|
|
// ItkManGetDeviceCount() function must be called.
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ӡ<EFBFBD><D3A1><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//
|
|||
|
|
// Print information of connected cameras.
|
|||
|
|
uint32_t i = 0;
|
|||
|
|
for (; i < numDevices; ++i) {
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD>塣
|
|||
|
|
//
|
|||
|
|
// Camera information structure.
|
|||
|
|
ITKDEV_INFO di;
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//
|
|||
|
|
// Get device information.
|
|||
|
|
ItkManGetDeviceInfo(i, &di);
|
|||
|
|
|
|||
|
|
// <20><>ӡ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ
|
|||
|
|
//
|
|||
|
|
// Print information.
|
|||
|
|
printf("i:%d \n Device Full Name:%s\n Friendly Name:%s\n Vendor Name:%s\n "
|
|||
|
|
"Model Name:%s\n Serial Name:%s\n Device Class:%s\n "
|
|||
|
|
"Device Version:%s\n User Defined Name:%s\n\n",
|
|||
|
|
i, di.FullName, di.FriendlyName, di.VendorName, di.ModelName,
|
|||
|
|
di.SerialNumber, di.DeviceClass, di.DeviceVersion,
|
|||
|
|
di.UserDefinedName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~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(); }
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>
|
|||
|
|
//
|
|||
|
|
// Configure camera device.
|
|||
|
|
ConfigureCamera(tmpIndex);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Create data stream and buffer.
|
|||
|
|
CreateStreamAndBuffer();
|
|||
|
|
|
|||
|
|
// ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Register callback functions.
|
|||
|
|
RegisterCallback();
|
|||
|
|
|
|||
|
|
// <20><>ʼͼ<CABC><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Start grabbing images.
|
|||
|
|
res = ItkStreamStart(g_hStream, -1);
|
|||
|
|
CHECK(res);
|
|||
|
|
bIsStartStream = true;
|
|||
|
|
|
|||
|
|
// <20>ȴ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Wait for grabbing images finished.
|
|||
|
|
{ int getCharTmp = getchar(); }
|
|||
|
|
|
|||
|
|
// ֹͣͼ<D6B9><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Stop grabbing images.
|
|||
|
|
ItkStreamStop(g_hStream);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Unregister callback functions.
|
|||
|
|
UnRegisterCallback();
|
|||
|
|
|
|||
|
|
ItkDevFreeStream(g_hStream);
|
|||
|
|
|
|||
|
|
// <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>
|
|||
|
|
//
|
|||
|
|
// Close camera device.
|
|||
|
|
res = ItkDevClose(g_hCamera);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (g_bufferData != NULL)
|
|||
|
|
free(g_bufferData);
|
|||
|
|
|
|||
|
|
// <20>ͷ<EFBFBD> IKapC <20><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Release IKapC runtime environment.
|
|||
|
|
ItkManTerminate();
|
|||
|
|
|
|||
|
|
pressEnterToExit();
|
|||
|
|
return EXIT_SUCCESS;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Print error message and exit the program.
|
|||
|
|
void printErrorAndExit(ITKSTATUS errc) {
|
|||
|
|
fprintf(stderr, "Error Code:%08x\n", errc);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Users enter Enter to exit the program.
|
|||
|
|
void pressEnterToExit(void) {
|
|||
|
|
fprintf(stderr, "\nPress enter to exit.\n");
|
|||
|
|
while (getchar() != '\n')
|
|||
|
|
;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>
|
|||
|
|
//
|
|||
|
|
// Configure camera device.
|
|||
|
|
void ConfigureCamera(int index) {
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
uint32_t numCameras = 0;
|
|||
|
|
|
|||
|
|
// ö<>ٿ<EFBFBD><D9BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ItkManGetDeviceCount() <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Enumerate the number of available cameras. Before opening the camera,
|
|||
|
|
// ItkManGetDeviceCount() function must be called.
|
|||
|
|
res = ItkManGetDeviceCount(&numCameras);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
// <20><>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
//
|
|||
|
|
// When there is no connected cameras.
|
|||
|
|
if (numCameras == 0) {
|
|||
|
|
printf("No camera.\n");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (index >= numCameras)
|
|||
|
|
{
|
|||
|
|
printf("index:%d is more than numCameras:%d.\n", index, numCameras);
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>GigEVision<6F><6E>USB3Vision<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Open GigEVision or USB3Vision camera.
|
|||
|
|
for (uint32_t i = 0; i < numCameras; i++) {
|
|||
|
|
if (i == index) {
|
|||
|
|
|
|||
|
|
ITKDEV_INFO di;
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//
|
|||
|
|
// Get camera device information.
|
|||
|
|
res = ItkManGetDeviceInfo(i, &di);
|
|||
|
|
printf("Using camera: serial: %s, name: %s, interface: %s.\n",
|
|||
|
|
di.SerialNumber, di.FullName, di.DeviceClass);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>豸ΪGigEVision<6F><6E>USB3Vision<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD>ȷʱ<C8B7><CAB1>
|
|||
|
|
//
|
|||
|
|
// When the device is GigEVision or USB3Vision camera and the serial
|
|||
|
|
// number is proper.
|
|||
|
|
if ((strcmp(di.DeviceClass, "GigEVision") == 0 ||
|
|||
|
|
strcmp(di.DeviceClass, "USB3Vision") == 0) &&
|
|||
|
|
strcmp(di.SerialNumber, "") != 0) {
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Open camera.
|
|||
|
|
res = ItkDevOpen(i, ITKDEV_VAL_ACCESS_MODE_EXCLUSIVE, &g_hCamera);
|
|||
|
|
CHECK(res);
|
|||
|
|
g_di = di;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD> \~english Create data stream and
|
|||
|
|
/// buffer
|
|||
|
|
void CreateStreamAndBuffer() {
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \~english The number of data
|
|||
|
|
/// stream
|
|||
|
|
uint32_t streamCount = 0;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \~english Get the number of data
|
|||
|
|
/// stream
|
|||
|
|
res = ItkDevGetStreamCount(g_hCamera, &streamCount);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (streamCount == 0) {
|
|||
|
|
fprintf(stderr, "Camera does not have image stream channel.");
|
|||
|
|
ItkManTerminate();
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ \~english Allocate data stream
|
|||
|
|
/// source
|
|||
|
|
res = ItkDevAllocStreamEx(g_hCamera, 0, STREAM_BUFFER_COUNT, &g_hStream);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
ITKBUFFER hBuffer = NULL;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ϊ0<CEAA><30>buffer \~english get buffer of index 0
|
|||
|
|
res = ItkStreamGetBuffer(g_hStream, 0, &hBuffer);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡbuffer<65><72><EFBFBD><EFBFBD>Ϣ \~english get buffer info
|
|||
|
|
ITK_BUFFER_INFO bufferInfo = { 0 };
|
|||
|
|
res = ItkBufferGetInfo(hBuffer, &bufferInfo);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ洢 \~english Create buffer data
|
|||
|
|
/// saving
|
|||
|
|
g_bufferData = (char*)malloc(bufferInfo.ImageSize);
|
|||
|
|
if (g_bufferData == NULL) {
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// 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 RegisterCallback() {
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
res = ItkStreamRegisterCallback(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_START_OF_STREAM,
|
|||
|
|
cbStartOfStream, g_hStream);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkStreamRegisterCallback(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_END_OF_STREAM,
|
|||
|
|
cbEndOfStream, g_hStream);
|
|||
|
|
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(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_END_OF_FRAME,
|
|||
|
|
cbOnEndOfFrame, g_hStream);
|
|||
|
|
CHECK(res);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkStreamRegisterCallback(g_hStream, ITKSTREAM_VAL_EVENT_TYPE_TIME_OUT,
|
|||
|
|
cbOnTimeOut, g_hStream);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkStreamRegisterCallback(
|
|||
|
|
g_hStream, ITKSTREAM_VAL_EVENT_TYPE_FRAME_LOST, cbOnFrameLost, g_hStream);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkDevRegisterCallback(g_hCamera, "DeviceRemove", cbOnReconnect, g_hCamera);
|
|||
|
|
CHECK(res);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Unregister callback functions.
|
|||
|
|
void UnRegisterCallback() {
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
res = ItkStreamUnregisterCallback(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_START_OF_STREAM);
|
|||
|
|
res = ItkStreamUnregisterCallback(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_END_OF_STREAM);
|
|||
|
|
res = ItkStreamUnregisterCallback(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_END_OF_FRAME);
|
|||
|
|
res =
|
|||
|
|
ItkStreamUnregisterCallback(g_hStream, ITKSTREAM_VAL_EVENT_TYPE_TIME_OUT);
|
|||
|
|
res = ItkStreamUnregisterCallback(g_hStream,
|
|||
|
|
ITKSTREAM_VAL_EVENT_TYPE_FRAME_LOST);
|
|||
|
|
res = ItkDevUnregisterCallback(g_hCamera, "DeviceRemove");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><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>
|
|||
|
|
//
|
|||
|
|
// This function is registered as a callback function. When data stream starts,
|
|||
|
|
// the function will be called.
|
|||
|
|
void IKAPC_CC cbStartOfStream(uint32_t eventType, void* pContext) {
|
|||
|
|
printf("On start of stream. \n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><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>
|
|||
|
|
//
|
|||
|
|
// This function is registered as a callback function. When data stream ends,
|
|||
|
|
// the function will be called.
|
|||
|
|
void IKAPC_CC cbEndOfStream(uint32_t eventType, void* pContext) {
|
|||
|
|
printf("On end of stream. \n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><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>
|
|||
|
|
//
|
|||
|
|
// This function is registered as a callback function. When grabbing a frame of
|
|||
|
|
// image finished, the function will be called.
|
|||
|
|
void IKAPC_CC cbOnEndOfFrame(uint32_t eventType, void* pContext) {
|
|||
|
|
|
|||
|
|
printf("on end of frame.\n");
|
|||
|
|
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
ITKBUFFER hBuffer = NULL;
|
|||
|
|
ITK_BUFFER_INFO bufferInfo = { 0 };
|
|||
|
|
ITKSTREAM hStream = (ITKSTREAM)(pContext);
|
|||
|
|
|
|||
|
|
// \~chinese <20><>ȡ<EFBFBD><C8A1>ǰbuffer \~english get current buffer
|
|||
|
|
res = ItkStreamGetCurrentBuffer(hStream, &hBuffer);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
// \~chinese <20><>ȡ<EFBFBD><C8A1>ǰbuffer<65><72>Ϣ \~english get current buffer info
|
|||
|
|
res = ItkBufferGetInfo(hBuffer, &bufferInfo);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
// <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>ʱ<EFBFBD><CAB1>
|
|||
|
|
//
|
|||
|
|
// 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) {
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Save image.
|
|||
|
|
|
|||
|
|
/*res = ItkBufferSave(hBuffer,g_saveFileName,ITKBUFFER_VAL_TIFF);
|
|||
|
|
CHECK(res);
|
|||
|
|
res = ItkBufferSave(hBuffer, g_saveFileNameraw, ITKBUFFER_VAL_RAW);
|
|||
|
|
CHECK(res);*/
|
|||
|
|
|
|||
|
|
res = ItkBufferRead(hBuffer, 0, g_bufferData, (uint32_t)bufferInfo.ValidImageSize);
|
|||
|
|
CHECK(res);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><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>
|
|||
|
|
//
|
|||
|
|
// This function is registered as a callback function. When grabbing images time
|
|||
|
|
// out, the function will be called.
|
|||
|
|
void IKAPC_CC cbOnTimeOut(uint32_t eventType, void* pContext) {
|
|||
|
|
printf("on time out.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><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>
|
|||
|
|
//
|
|||
|
|
// This function is registered as a callback function. When grabbing frame lost,
|
|||
|
|
// the function will be called.
|
|||
|
|
void IKAPC_CC cbOnFrameLost(uint32_t eventType, void* pContext) {
|
|||
|
|
printf("on frame lost.\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><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><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
//
|
|||
|
|
// This function is registered as a callback function. When device removed
|
|||
|
|
// signal ignored, the function will be called.
|
|||
|
|
void IKAPC_CC cbOnReconnect(void* pContext, ITKEVENTINFO eventInfo) {
|
|||
|
|
printf("on device removed.\n");
|
|||
|
|
|
|||
|
|
ITKSTATUS res = ITKSTATUS_OK;
|
|||
|
|
|
|||
|
|
if (bIsStartStream) {
|
|||
|
|
res = ItkStreamStop(g_hStream);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Unregister callback functions.
|
|||
|
|
UnRegisterCallback();
|
|||
|
|
|
|||
|
|
ItkDevFreeStream(g_hStream);
|
|||
|
|
}
|
|||
|
|
// <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>
|
|||
|
|
//
|
|||
|
|
// Close camera device.
|
|||
|
|
res = ItkDevClose(g_hCamera);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (g_bufferData != NULL)
|
|||
|
|
free(g_bufferData);
|
|||
|
|
|
|||
|
|
uint32_t numCameras = 0;
|
|||
|
|
|
|||
|
|
do {
|
|||
|
|
// ö<>ٿ<EFBFBD><D9BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ItkManGetDeviceCount()
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Enumerate the number of available cameras. Before opening the camera,
|
|||
|
|
// ItkManGetDeviceCount() function must be called.
|
|||
|
|
res = ItkManGetDeviceCount(&numCameras);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
if (numCameras == 0) {
|
|||
|
|
printf("numCameras:%d\n", numCameras);
|
|||
|
|
Sleep(200);
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//
|
|||
|
|
// printf camera info.
|
|||
|
|
for (uint32_t i = 0; i < numCameras; i++) {
|
|||
|
|
|
|||
|
|
ITKDEV_INFO di;
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD><CFA2>
|
|||
|
|
//
|
|||
|
|
// Get camera device information.
|
|||
|
|
res = ItkManGetDeviceInfo(i, &di);
|
|||
|
|
printf("index:%d camera: serial: %s, name: %s, interface: %s.\n", i,
|
|||
|
|
di.SerialNumber, di.FullName, di.DeviceClass);
|
|||
|
|
|
|||
|
|
if (strcmp(di.SerialNumber, g_di.SerialNumber) == 0) {
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Open camera.
|
|||
|
|
res = ItkDevOpen(i, ITKDEV_VAL_ACCESS_MODE_EXCLUSIVE, &g_hCamera);
|
|||
|
|
if (res != ITKSTATUS_OK) {
|
|||
|
|
printf("Open index:%d fail.\n", i);
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ \~english
|
|||
|
|
/// Allocate data stream source
|
|||
|
|
res =
|
|||
|
|
ItkDevAllocStreamEx(g_hCamera, 0, STREAM_BUFFER_COUNT, &g_hStream);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
ITKBUFFER hBuffer = NULL;
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ϊ0<CEAA><30>buffer \~english get
|
|||
|
|
/// buffer of index 0
|
|||
|
|
res = ItkStreamGetBuffer(g_hStream, 0, &hBuffer);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><>ȡbuffer<65><72><EFBFBD><EFBFBD>Ϣ \~english get buffer
|
|||
|
|
/// info
|
|||
|
|
ITK_BUFFER_INFO bufferInfo = { 0 };
|
|||
|
|
res = ItkBufferGetInfo(hBuffer, &bufferInfo);
|
|||
|
|
CHECK(res);
|
|||
|
|
|
|||
|
|
/// \~chinese <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ洢 \~english Create
|
|||
|
|
/// buffer data saving
|
|||
|
|
g_bufferData = (char*)malloc(bufferInfo.ImageSize);
|
|||
|
|
if (g_bufferData == NULL) {
|
|||
|
|
pressEnterToExit();
|
|||
|
|
exit(EXIT_FAILURE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Register callback functions.
|
|||
|
|
RegisterCallback();
|
|||
|
|
|
|||
|
|
// <20><>ʼͼ<CABC><CDBC><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>
|
|||
|
|
//
|
|||
|
|
// Start grabbing images.
|
|||
|
|
res = ItkStreamStart(g_hStream, -1);
|
|||
|
|
CHECK(res);
|
|||
|
|
bIsStartStream = true;
|
|||
|
|
printf("reopen success.\n");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
Sleep(200);
|
|||
|
|
} while (true);
|
|||
|
|
}
|