赞
踩
由于工作关系,本人最近新研究的海康的网口及USB3.0接口的工业相机,现将相关内容进行整理记录。
64位VS2019 +C#
Halcon19.11
海康MVS_STD_3.3.0(官网下载自己想要的版本)
引用海康相机动态库(MvCameraControl.Net.dll),在VS项目文件中添加引用,如下图
引用MVS安装目录下MVS\Development\DotNet\MvCameraControl.Net.dll这个文件。
创建SvPointGrey类,在类里引入如下的命名空间:
using MvCamCtrl.NET;
代码如下:
- using System;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Threading.Tasks;
- using HalconDotNet;
- using MvCamCtrl.NET;
- namespace SimploVision
- {
- public class SvPointGrey
- {
- private MyCamera Camera;
- private MyCamera.MV_CC_DEVICE_INFO CameraInfo;
- //连接并开启相机
- public override void Initial()
- {
- base.Initial();
- try
- {
- Camera = new MyCamera();
- var infoList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
- MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE, ref infoList);
-
- var result = -1;
- for (int i = 0; i < infoList.nDeviceNum; i++)
- {
- var deviceInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(infoList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
- if (((MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(deviceInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO))).chSerialNumber == SN)
- {
- Camera.MV_CC_CreateDevice_NET(ref deviceInfo);
- CameraInfo = deviceInfo;
- result = Camera.MV_CC_OpenDevice_NET();
- }
- }
-
- if (result != 0)
- {
- throw new Exception($"相機{SN}連接失敗");
- }
-
- result = 0;
- if (Colorful == "黑白")
- {
- result += Camera.MV_CC_SetPixelFormat_NET((uint)MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8);
- }
- else
- {
- result += Camera.MV_CC_SetEnumValueByString_NET("PixelFormat", "BayerBG8");
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。