首先引用海康威视的MVS中的MvCameraControl.Net

然后 using MvCamCtrl.NET;

查找设备程序:

其中的ComboBox cbDeviceList是显示设备序列号的下拉列表

public void DeviceListAcq(ComboBox cbDeviceList){int nRet;// ch:创建设备列表 en:Create Device ListSystem.GC.Collect();cbDeviceList.Items.Clear();nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList);if (0 != nRet){ShowErrorMsg("Enumerate devices fail!", 0);return;}// ch:在窗体列表中显示设备名 | en:Display device name in the form listfor (int i = 0; i < m_pDeviceList.nDeviceNum; i++){MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE){IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0);MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO));if (gigeInfo.chUserDefinedName != ""){cbDeviceList.Items.Add("GigE: " + gigeInfo.chUserDefinedName + " (" + gigeInfo.chSerialNumber + ")");}else{cbDeviceList.Items.Add("GigE: " + gigeInfo.chManufacturerName + " " + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")");}}else if (device.nTLayerType == MyCamera.MV_USB_DEVICE){IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0);MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO));if (usbInfo.chUserDefinedName != ""){cbDeviceList.Items.Add("USB: " + usbInfo.chUserDefinedName + " (" + usbInfo.chSerialNumber + ")");}else{cbDeviceList.Items.Add("USB: " + usbInfo.chManufacturerName + " " + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")");}}}// ch:选择第一项 | en:Select the first itemif (m_pDeviceList.nDeviceNum != 0){cbDeviceList.SelectedIndex = 0;}}

打开设备程序:

 //打开设备public bool b_NoDevice;public void OpenDevice(ComboBox cbDeviceList){if (m_pDeviceList.nDeviceNum == 0 || cbDeviceList.SelectedIndex == -1){ShowErrorMsg("No device, please select", 0);b_NoDevice = true;return;}int nRet = -1;// ch:获取选择的设备信息 | en:Get selected device informationMyCamera.MV_CC_DEVICE_INFO device =(MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[cbDeviceList.SelectedIndex],typeof(MyCamera.MV_CC_DEVICE_INFO));// ch:打开设备 | en:Open deviceif (null == m_pMyCamera){m_pMyCamera = new MyCamera();if (null == m_pMyCamera){return;}}nRet = m_pMyCamera.MV_CC_CreateDevice_NET(ref device);if (MyCamera.MV_OK != nRet){return;}nRet = m_pMyCamera.MV_CC_OpenDevice_NET();if (MyCamera.MV_OK != nRet){m_pMyCamera.MV_CC_DestroyDevice_NET();ShowErrorMsg("Device open fail!", nRet);return;}// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE){int nPacketSize = m_pMyCamera.MV_CC_GetOptimalPacketSize_NET();if (nPacketSize > 0){nRet = m_pMyCamera.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);if (nRet != MyCamera.MV_OK){Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);}}else{Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);}}// ch:设置采集连续模式 | en:Set Continues Aquisition Modem_pMyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", 2);// ch:工作在连续模式 | en:Acquisition On Continuous Modem_pMyCamera.MV_CC_SetEnumValue_NET("TriggerMode", 0);    // ch:连续模式 | en:Continuousb_NoDevice = false;}

连续采图程序:

//连续采集public void ContinuesGrab(ComboBox cbDeviceList){int nRet;// ch:开始采集 | en:Start GrabbingnRet = m_pMyCamera.MV_CC_StartGrabbing_NET();if (MyCamera.MV_OK != nRet){ShowErrorMsg("Trigger Fail!", nRet);return;}//实时采集m_pMyCamera.MV_CC_SetEnumValue_NET("TriggerMode", 0);m_bGrabbing = true;// ch:显示 | en:DisplaynRet = m_pMyCamera.MV_CC_Display_NET(pictureBox1.Handle);if (MyCamera.MV_OK != nRet){ShowErrorMsg("Display Fail!", nRet);}}//停止采集public void StopGrab(){int nRet = -1;// ch:停止采集 | en:Stop GrabbingnRet = m_pMyCamera.MV_CC_StopGrabbing_NET();if (nRet != MyCamera.MV_OK){ShowErrorMsg("Stop Grabbing Fail!", nRet);}m_bGrabbing = false;}

单步采图程序:

public Bitmap ReadImage(){int nRet;UInt32 nPayloadSize = 0;MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();nRet = m_pMyCamera.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);if (MyCamera.MV_OK != nRet){ShowErrorMsg("Get PayloadSize failed", nRet);return null;}nPayloadSize = stParam.nCurValue;if (nPayloadSize > m_nBufSizeForDriver){m_nBufSizeForDriver = nPayloadSize;m_pBufForDriver = new byte[m_nBufSizeForDriver];// ch:同时对保存图像的缓存做大小判断处理 | en:Determine the buffer size to save image// ch:BMP图片大小:width * height * 3 + 2048(预留BMP头大小) | en:BMP image size: width * height * 3 + 2048 (Reserved for BMP header)m_nBufSizeForSaveImage = m_nBufSizeForDriver * 3 + 2048;m_pBufForSaveImage = new byte[m_nBufSizeForSaveImage];}IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement(m_pBufForDriver, 0);MyCamera.MV_FRAME_OUT_INFO_EX stFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();// ch:超时获取一帧,超时时间为1秒 | en:Get one frame timeout, timeout is 1 secnRet = m_pMyCamera.MV_CC_GetOneFrameTimeout_NET(pData, m_nBufSizeForDriver, ref stFrameInfo, 1000);if (MyCamera.MV_OK != nRet){ShowErrorMsg("No Data!", nRet);return null;}MyCamera.MvGvspPixelType enDstPixelType;if (IsMonoData(stFrameInfo.enPixelType)){enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8;}else if (IsColorData(stFrameInfo.enPixelType)){enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed;}else{ShowErrorMsg("No such pixel type!", 0);return null;}IntPtr pImage = Marshal.UnsafeAddrOfPinnedArrayElement(m_pBufForSaveImage, 0);MyCamera.MV_SAVE_IMAGE_PARAM_EX stSaveParam = new MyCamera.MV_SAVE_IMAGE_PARAM_EX();MyCamera.MV_PIXEL_CONVERT_PARAM stConverPixelParam = new MyCamera.MV_PIXEL_CONVERT_PARAM();stConverPixelParam.nWidth = stFrameInfo.nWidth;stConverPixelParam.nHeight = stFrameInfo.nHeight;stConverPixelParam.pSrcData = pData;stConverPixelParam.nSrcDataLen = stFrameInfo.nFrameLen;stConverPixelParam.enSrcPixelType = stFrameInfo.enPixelType;stConverPixelParam.enDstPixelType = enDstPixelType;stConverPixelParam.pDstBuffer = pImage;stConverPixelParam.nDstBufferSize = m_nBufSizeForSaveImage;nRet = m_pMyCamera.MV_CC_ConvertPixelType_NET(ref stConverPixelParam);if (MyCamera.MV_OK != nRet){return null;}if (enDstPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8){//************************Mono8 转 Bitmap*******************************Bitmap bmp = new Bitmap(stFrameInfo.nWidth, stFrameInfo.nHeight, stFrameInfo.nWidth * 1, PixelFormat.Format8bppIndexed, pImage);ColorPalette cp = bmp.Palette;// init palettefor (int i = 0; i < 256; i++){cp.Entries[i] = Color.FromArgb(i, i, i);}// set palette backbmp.Palette = cp;return bmp;}else{//*********************RGB8 转 Bitmap**************************for (int i = 0; i < stFrameInfo.nHeight; i++){for (int j = 0; j < stFrameInfo.nWidth; j++){byte chRed = m_pBufForSaveImage[i * stFrameInfo.nWidth * 3 + j * 3];m_pBufForSaveImage[i * stFrameInfo.nWidth * 3 + j * 3] = m_pBufForSaveImage[i * stFrameInfo.nWidth * 3 + j * 3 + 2];m_pBufForSaveImage[i * stFrameInfo.nWidth * 3 + j * 3 + 2] = chRed;}}try{Bitmap bmp = new Bitmap(stFrameInfo.nWidth, stFrameInfo.nHeight, stFrameInfo.nWidth * 3, PixelFormat.Format24bppRgb, pImage);return bmp;}catch{}}return null;}private Boolean IsMonoData(MyCamera.MvGvspPixelType enGvspPixelType){switch (enGvspPixelType){case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8:case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10:case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12:case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12_Packed:return true;default:return false;}}/*************************************************************************  @fn     IsColorData()*  @brief  判断是否是彩色数据*  @param  enGvspPixelType         [IN]           像素格式*  @return 成功,返回0;错误,返回-1 ************************************************************************/private Boolean IsColorData(MyCamera.MvGvspPixelType enGvspPixelType){switch (enGvspPixelType){case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR8:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG8:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB8:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG8:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_YUYV_Packed:case MyCamera.MvGvspPixelType.PixelType_Gvsp_YCBCR411_8_CBYYCRYY:return true;default:return false;}}

海康威视连续采图与单步采图_c#相关推荐

  1. 图片素材类网站必备以图搜图、智能搜图识图图像搜索系统imgso,让素材网站更智能专业

    很多背景墙.墙纸.壁纸.电视墙.装修设计素材网都必配以图搜图.这个以图搜图识图的好处不言而喻,是很多素材网必备功能. 推荐一款专业的以图搜图系统imgso,它是一个以图搜图专业系统,让你的网站拥有站内 ...

  2. ESL第十七章 无向图模型 学习/推断/成对马尔可夫独立/全局马尔可夫性、协方差图/高斯图/修改回归算法/图结构估计/图lasso、【受限】玻尔兹曼机/泊松对数线性建模/迭代比例过滤/对比散度

    目录 17.1 导言 17.2 马尔可夫图及其性质 17.3 连续变量的无向图模型 17.3.1 图结构已知的参数估计 17.3.2 估计图结构 17.4 离散变量的无向图模型 17.4.1 图结构已 ...

  3. 让wordpress网站拥有以图搜图,智能搜图、图像搜索系统imgso,让网站更智能专业

    专业素材网站的搜图功能: 很多背景墙.墙纸.壁纸.电视墙.装修设计素材网都必配以图搜图.这个以图搜图识图的好处不言而喻,是很多素材网.图片网.三维网等等必备功能. 推荐一款专业的以图搜图系统imgso ...

  4. Intel Realsense D435 opencv 为什么将color图转换成灰度图后,再与depth图水平堆叠,其结果一片黑色?(数据未map到0-255)

    相关代码 # -*- coding: utf-8 -*- """ @File : obstacle_detection.py @Time : 2019/12/11 10: ...

  5. 基于图查询系统的图计算引擎

    柯学翰, 陈榕 上海交通大学软件学院并行与分布式系统研究所,上海 200240 摘要:在目前的研究中,图查询和图计算系统是相互独立的,但在实际应用中两者通常是同时存在的.为解决相互独立的系统带来的存储 ...

  6. 分别用邻接矩阵和邻接表实现图的深度优先遍历和广度优先遍历_数据结构与算法:三十张图弄懂「图的两种遍历方式」...

    原创: 进击的HelloWorld1 引言遍历是指从某个节点出发,按照一定的的搜索路线,依次访问对数据结构中的全部节点,且每个节点仅访问一次. 在二叉树基础中,介绍了对于树的遍历.树的遍历是指从根节点 ...

  7. 深度优先遍历访问的边集合_数据结构与算法: 三十张图弄懂「图的两种遍历方式」...

    1 引言 遍历是指从某个节点出发,按照一定的的搜索路线,依次访问对数据结构中的全部节点,且每个节点仅访问一次. 在二叉树基础中,介绍了对于树的遍历.树的遍历是指从根节点出发,按照一定的访问规则,依次访 ...

  8. Plotly.js使用详细介绍(折线图、饼状图、点图、水平条形图、桑基图、树状图、等值线图)

    目录 0 写在前面 1 HTML代码 2 折线图 2.1 基本折线图 2.2 复杂折线图 2.2.1 轨迹 2.2.2 布局 3 饼状图 3.1 基本饼状图 3.2 饼图子图 3.3 甜甜圈图 4 点 ...

  9. 4米乘以12米CAD图_设备时序图的绘制方法

    每日一省:你觉得工作上还有哪些需要改进的地方? 在方案说明书中常用C/T来作为设备性能参数,说明设备的生产能力.C/T是指设备完成一个完整动作周期所需要的时间.设备的理论C/T是通过时序图的分析得到的 ...

最新文章

  1. 产品经理要读什么书?怎么读?
  2. python与人工智能编程-最适合人工智能开发的5种编程语言,Python排第一
  3. [AHOI 2016初中组]迷宫
  4. 通过adb命令查看当前activity(更新版)
  5. 设计模式(一)---简单工厂模式
  6. 前端学习(2154):webpack横幅plugin的使用
  7. 《Android源码设计模式》--装饰模式
  8. k8s学习: 创建 mysql 任务
  9. shader变体是什么_shader 里面的分支
  10. 73种网页常用js代码
  11. 小米图标大小设置方法_miui12如何设置图标大小
  12. Android 开机Logo、铃声、震动修改方案
  13. Windows Azure Cloud Service (6) Reboot and Reimage
  14. 免费在线逻辑图 + 示例
  15. 男子订民宿被毁约5个家庭漂泊街头 房东:住满了,没办法
  16. CSS - 响应式布局(二)响应式栅格系统
  17. 汽车牌照自动识别系统
  18. 程序员之天梯排行榜,你在哪一级?
  19. ios 文本翻转_UIButton,UILabel文字旋转(倾斜)
  20. 字节跳动招聘研究型实习生

热门文章

  1. 数字电路中的竞争与冒险
  2. 深入浅出解释FFT(六)——深入理解fft变换
  3. 计算机二级c语基础知识,计算机二级C语基础知识整理.doc
  4. 将时间保存到pb_Nature Geoscience:沉积岩容矿Cu-Pb-Zn矿床受控于克拉通边缘稳定性...
  5. linux中cc和S的区别,为什么在linux命令(iostat)中每秒读取(r/s)一直为零?
  6. 反弹模型(bounce model)----adot, H, Hdot变化图
  7. CMB标量功率谱第一个谱指数跑动项n(1)跑动带来的影响
  8. 二流四流神经网路(模型融合矩阵乘法理论实践)
  9. deepspeaker(TensorFlow)百度声纹识别和对比代码和模型
  10. 跳出数据计算拯救人工智能之打败机器学习方法详解