HIK 相机 设置缓存节点进行取流

news/2024/12/17 15:19:01/

场景:【硬触发】环境触发频率快时,相机内缓存图片(默认节点数量为1)有可能被不停刷新,导致无法及时捕捉到每次触发响应的图片。
方案:SDK中可以设置相机内部缓冲节点数量和取图策略。

nRet = MV_CC_SetImageNodeNum(handle, nImageNodeNum);
handle(相机句柄)
nImageNodeNum:节点数量(初始化为1)

MV_GrabStrategy_OneByOne  
从旧到新一帧一帧的获取图像(默认为该策略) MV_GrabStrategy_LatestImagesOnly  
获取列表中最新的一帧图像(同时清除列表中的其余图像) MV_GrabStrategy_LatestImages  
获取列表中最新的图像,个数由OutputQueueSize决定,范围为1-ImageNodeNum,设置成1等同于LatestImagesOnly,设置成ImageNodeNum等同于OneByOne MV_GrabStrategy_UpcomingImage  
等待下一帧图像 

示例:

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"// Wait for key press
void WaitForKeyPress(void)
{while(!_kbhit()){Sleep(10);}_getch();
}bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)
{if (NULL == pstMVDevInfo){printf("The Pointer of pstMVDevInfo is NULL!\n");return false;}if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE){int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);}else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE){printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chSerialNumber);printf("Device Number: %d\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.nDeviceNumber);}else{printf("Not support.\n");}return true;
}static  unsigned int __stdcall UpcomingThread(void* pUser)
{Sleep(3000);printf("Trigger Software Once for MV_GrabStrategy_UpcomingImage\n");MV_CC_SetCommandValue(pUser, "TriggerSoftware");return 0;
}int main()
{int nRet = MV_OK;void* handle = NULL;unsigned char * pData = NULL;do {// Enum deviceMV_CC_DEVICE_INFO_LIST stDeviceList = {0};nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);if (MV_OK != nRet){printf("Enum Devices fail! nRet [0x%x]\n", nRet);break;}if (stDeviceList.nDeviceNum > 0){for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++){printf("[device %d]:\n", i);MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];if (NULL == pDeviceInfo){break;} PrintDeviceInfo(pDeviceInfo);            }  } else{printf("Find No Devices!\n");break;} printf("Please Input camera index:");unsigned int nIndex = 0;scanf_s("%d", &nIndex);if (nIndex >= stDeviceList.nDeviceNum){printf("Input error!\n");break;}// Select device and create handlenRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);if (MV_OK != nRet){printf("Create Handle fail! nRet [0x%x]\n", nRet);break;}// Open devicenRet = MV_CC_OpenDevice(handle);if (MV_OK != nRet){printf("Open Device fail! nRet [0x%x]\n", nRet);break;}// Detection network optimal package size(It only works for the GigE camera)if (stDeviceList.pDeviceInfo[nIndex]->nTLayerType == MV_GIGE_DEVICE){int nPacketSize = MV_CC_GetOptimalPacketSize(handle);if (nPacketSize > 0){if(MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize) != MV_OK){printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);}}else{printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);}}// Set Trigger Mode and Set Trigger SourcenRet = MV_CC_SetEnumValueByString(handle, "TriggerMode", "On");if (MV_OK != nRet){printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);break;}nRet = MV_CC_SetEnumValueByString(handle, "TriggerSource", "Software");if (MV_OK != nRet){printf("Set Trigger Source fail! nRet [0x%x]\n", nRet);break;}unsigned int nImageNodeNum = 5;// Set number of image nodenRet = MV_CC_SetImageNodeNum(handle, nImageNodeNum);if (MV_OK != nRet){printf("Set number of image node fail! nRet [0x%x]\n", nRet);break;}printf("\n**************************************************************************\n");printf("* 0.MV_GrabStrategy_OneByOne;       1.MV_GrabStrategy_LatestImagesOnly;  *\n");printf("* 2.MV_GrabStrategy_LatestImages;   3.MV_GrabStrategy_UpcomingImage;     *\n");printf("**************************************************************************\n");printf("Please Input Grab Strategy:");unsigned int nGrabStrategy = 0;scanf_s("%d", &nGrabStrategy);// U3V device not support UpcomingImageif (nGrabStrategy == MV_GrabStrategy_UpcomingImage && MV_USB_DEVICE == stDeviceList.pDeviceInfo[nIndex]->nTLayerType){printf("U3V device not support UpcomingImage\n");break;}switch(nGrabStrategy){case MV_GrabStrategy_OneByOne:{printf("Grab using the MV_GrabStrategy_OneByOne default strategy\n");nRet = MV_CC_SetGrabStrategy(handle, MV_GrabStrategy_OneByOne);if (MV_OK != nRet){printf("Set Grab Strategy fail! nRet [0x%x]\n", nRet);break;}}break;case MV_GrabStrategy_LatestImagesOnly:{printf("Grab using strategy MV_GrabStrategy_LatestImagesOnly\n");nRet = MV_CC_SetGrabStrategy(handle, MV_GrabStrategy_LatestImagesOnly);if (MV_OK != nRet){printf("Set Grab Strategy fail! nRet [0x%x]\n", nRet);break;}}break;case MV_GrabStrategy_LatestImages:{printf("Grab using strategy MV_GrabStrategy_LatestImages\n");nRet = MV_CC_SetGrabStrategy(handle, MV_GrabStrategy_LatestImages);if (MV_OK != nRet){printf("Set Grab Strategy fail! nRet [0x%x]\n", nRet);break;}// Set Output Queue SizenRet = MV_CC_SetOutputQueueSize(handle, 2);if (MV_OK != nRet){printf("Set Output Queue Size fail! nRet [0x%x]\n", nRet);break;}}break;case MV_GrabStrategy_UpcomingImage:{printf("Grab using strategy MV_GrabStrategy_UpcomingImage\n");nRet = MV_CC_SetGrabStrategy(handle, MV_GrabStrategy_UpcomingImage);if (MV_OK != nRet){printf("Set Grab Strategy fail! nRet [0x%x]\n", nRet);break;}unsigned int nThreadID = 0;void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , UpcomingThread , handle, 0 , &nThreadID );if (NULL == hThreadHandle){break;}}break;default:printf("Input error!Use default strategy:MV_GrabStrategy_OneByOne\n");break;}// Start grab imagenRet = MV_CC_StartGrabbing(handle);if (MV_OK != nRet){printf("Start Grabbing fail! nRet [0x%x]\n", nRet);break;}// Send Trigger Software commandfor (unsigned int i = 0;i < nImageNodeNum;i++){nRet = MV_CC_SetCommandValue(handle, "TriggerSoftware");if (MV_OK != nRet){printf("Send Trigger Software command fail! nRet [0x%x]\n", nRet);break;}Sleep(500);}MV_FRAME_OUT stOutFrame = {0};if (nGrabStrategy != MV_GrabStrategy_UpcomingImage){while(true){nRet = MV_CC_GetImageBuffer(handle, &stOutFrame, 0);if (nRet == MV_OK){printf("Get One Frame: Width[%d], Height[%d], FrameNum[%d]\n", stOutFrame.stFrameInfo.nWidth, stOutFrame.stFrameInfo.nHeight, stOutFrame.stFrameInfo.nFrameNum);}else{printf("No data[0x%x]\n", nRet);break;}nRet = MV_CC_FreeImageBuffer(handle, &stOutFrame);if(nRet != MV_OK){printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);}}}else//Only for upcoming{nRet = MV_CC_GetImageBuffer(handle, &stOutFrame, 5000);if (nRet == MV_OK){printf("Get One Frame: Width[%d], Height[%d], FrameNum[%d]\n", stOutFrame.stFrameInfo.nWidth, stOutFrame.stFrameInfo.nHeight, stOutFrame.stFrameInfo.nFrameNum);nRet = MV_CC_FreeImageBuffer(handle, &stOutFrame);if(nRet != MV_OK){printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);}}else{printf("No data[0x%x]\n", nRet);}}// Stop grab imagenRet = MV_CC_StopGrabbing(handle);if (MV_OK != nRet){printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);break;}// Close devicenRet = MV_CC_CloseDevice(handle);if (MV_OK != nRet){printf("Close Device fail! nRet [0x%x]\n", nRet);break;}// Destroy handlenRet = MV_CC_DestroyHandle(handle);if (MV_OK != nRet){printf("Destroy Handle fail! nRet [0x%x]\n", nRet);break;}} while (0);if (nRet != MV_OK){if (handle != NULL){MV_CC_DestroyHandle(handle);handle = NULL;}}printf("Press a key to exit.\n");WaitForKeyPress();return 0;

http://www.ppmy.cn/news/1555883.html

相关文章

水表的数字表盘分割数据集labelme格式3023张13类别

数据集格式&#xff1a;labelme格式(不包含mask文件&#xff0c;仅仅包含jpg图片和对应的json文件) 图片数量(jpg文件个数)&#xff1a;3023 标注数量(json文件个数)&#xff1a;3023 标注类别数&#xff1a;13 标注类别名称:["readbox_1","center",&q…

哈尔滨工业大学《2024年801自动控制原理真题》 (完整版)

本文内容&#xff0c;全部选自自动化考研联盟的&#xff1a;《哈尔滨工业大学801自控考研资料》的真题篇。后续会持续更新更多学校&#xff0c;更多年份的真题&#xff0c;记得关注哦~ 目录 2024年真题 Part1&#xff1a;2024年完整版真题 2024年真题

前端安全实践:常见攻击的防范与处理

"用户信息被盗了&#xff01;"周一早上,运营总监急匆匆地冲进办公室。原来是有用户反馈自己的账号在不知情的情况下被他人登录了。作为前端负责人,我立即组织团队开展安全排查。 这次事件让我们意识到,前端安全不容忽视。虽然之前也做过一些安全防护,但显然还不够完…

外国人永久居留证查验接口如何集成?JavaScript翔云永居证查验

在全球化的今天&#xff0c;越来越多的外国友人选择在中国长期居住和工作&#xff0c;而获得一张外国人永久居留证&#xff08;简称“永居证”&#xff09;是融入中国社会的重要一步&#xff0c;持有永居证在华的外国友人将享受诸多便利和服务。因此&#xff0c;当涉及到需要对…

深入解析 Java “NoClassDefFoundError” 异常及解决方法

在 Java 开发过程中&#xff0c;NoClassDefFoundError 是一个令人头疼的运行时错误。该错误通常表示在编译时可用的类文件在运行时却无法找到。本文将从根源分析这一问题&#xff0c;探讨常见场景并提供实用的解决方法。 问题分析 java.lang.NoClassDefFoundError 是由 JVM 抛…

【Stable Diffusion】SD安装、常用模型(checkpoint、embedding、LORA)、提示词具、常用插件

Stable Diffusion&#xff0c;一款强大的AI模型&#xff0c;让我们能够创造出惊人的艺术作品。本文将为您介绍如何安装Stable Diffusion以及深入使用的学习教程。 1. 安装Stable Diffusion (需要的小伙伴可以文末自行扫描获取) Stable Diffusion的安装可能是第一步&#xff0…

GTF转为excel文件

1. 加载必需的 R 包 在处理基因组数据时&#xff0c;我们通常需要一些专门的 R 包来读取、操作和导出数据。以下是常用的包&#xff1a; library(rtracklayer) # 用于导入 GTF 文件数据 library(writexl) # 用于导出数据到 Excel 格式 (.xlsx) library(openxlsx) …