MV_CC_RegisterImageCallBackEx 实时取流
时间: 2023-06-21 09:12:59 浏览: 900
海康相机SDK二次开发与Halcon混合编程代码和说明手册
5星 · 资源好评率100%
MV_CC_RegisterImageCallBackEx函数是用于注册图像数据回调函数的函数,它可以实现实时取流。该函数需要配合MV_CC_StartGrabbing和MV_CC_StopGrabbing函数一起使用,具体实现过程如下:
1. 调用MV_CC_OpenDevice打开设备;
2. 调用MV_CC_SetEnumValue设置参数;
3. 调用MV_CC_RegisterImageCallBackEx注册回调函数;
4. 调用MV_CC_StartGrabbing开始取流;
5. 在回调函数中处理图像数据;
6. 调用MV_CC_StopGrabbing停止取流;
7. 调用MV_CC_CloseDevice关闭设备。
以下是一个简单的示例代码,可供参考:
```c
#include "MvCameraControl.h"
void __stdcall ImageCallBackEx(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
// 处理图像数据
}
int main()
{
MV_CC_DEVICE_INFO_LIST stDeviceList;
memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
int nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
if (MV_OK != nRet)
{
printf("MV_CC_EnumDevices failed! nRet [%x]\n", nRet);
return -1;
}
MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[0];
// 打开设备
void* handle = NULL;
nRet = MV_CC_OpenDevice(pDeviceInfo, &handle);
if (MV_OK != nRet)
{
printf("MV_CC_OpenDevice failed! nRet [%x]\n", nRet);
return -1;
}
// 设置参数
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_OFF);
if (MV_OK != nRet)
{
printf("MV_CC_SetEnumValue TriggerMode failed! nRet [%x]\n", nRet);
MV_CC_CloseDevice(handle);
return -1;
}
// 注册回调函数
nRet = MV_CC_RegisterImageCallBackEx(handle, ImageCallBackEx, NULL);
if (MV_OK != nRet)
{
printf("MV_CC_RegisterImageCallBackEx failed! nRet [%x]\n", nRet);
MV_CC_CloseDevice(handle);
return -1;
}
// 开始取流
nRet = MV_CC_StartGrabbing(handle);
if (MV_OK != nRet)
{
printf("MV_CC_StartGrabbing failed! nRet [%x]\n", nRet);
MV_CC_CloseDevice(handle);
return -1;
}
// 等待图像数据回调
getchar();
// 停止取流
nRet = MV_CC_StopGrabbing(handle);
if (MV_OK != nRet)
{
printf("MV_CC_StopGrabbing failed! nRet [%x]\n", nRet);
MV_CC_CloseDevice(handle);
return -1;
}
// 关闭设备
nRet = MV_CC_CloseDevice(handle);
if (MV_OK != nRet)
{
printf("MV_CC_CloseDevice failed! nRet [%x]\n", nRet);
return -1;
}
return 0;
}
```
阅读全文