当前位置:网站首页>视觉上位系统设计开发(halcon-winform)-5.相机
视觉上位系统设计开发(halcon-winform)-5.相机
2022-07-03 15:08:00 【11eleven】
视觉的硬件输入核心相机,相机的种类很多,基本都配备可供调用的SDK,用来设置一些基本参数,以及触发图像输出。本文以海康虚拟相机为例进行说明。
海康的官方DEMO如下:
int nRet;
// ch:创建设备列表 || en: Create device list
System.GC.Collect();
cbDeviceList.Items.Clear();
nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList);
if (MyCamera.MV_OK != nRet)
{
MessageBox.Show("Enum Devices Fail");
return;
}
// ch:在窗体列表中显示设备名 || Display the device'name on window's list
for (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 item
if (m_pDeviceList.nDeviceNum != 0)
{
cbDeviceList.SelectedIndex = 0;
}
初始化设备。
//ch:获取选择的设备信息 | en:Get selected device information
MyCamera.MV_CC_DEVICE_INFO device =
(MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[cbDeviceList.SelectedIndex],
typeof(MyCamera.MV_CC_DEVICE_INFO));
nRet = m_pMyCamera.MV_CC_CreateDevice_NET(ref device);
if (MyCamera.MV_OK != nRet)
{
return;
}
// ch:打开设备 | en:Open device
nRet = m_pMyCamera.MV_CC_OpenDevice_NET();
if (MyCamera.MV_OK != nRet)
{
MessageBox.Show("Open Device Fail");
return;
}
// ch:设置触发模式为off || en:set trigger mode as off
m_pMyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", 2);
m_pMyCamera.MV_CC_SetEnumValue_NET("TriggerMode", 0);
打开设备,并进行触发模式的设置。一般分为两种模式,连续触发,即每一帧都进行返回,触发模式则是触发一次返回一次。一般应用场景下回选择触发模式。
if (m_bGrabbing)
{
m_bGrabbing = false;
// ch:停止抓图 || en:Stop grab image
m_pMyCamera.MV_CC_StopGrabbing_NET();
// ch: 控件操作 || en: Control operation
SetCtrlWhenStopGrab();
}
// ch:关闭设备 || en: Close device
m_pMyCamera.MV_CC_CloseDevice_NET();
程序关闭或者相机不使用时记得关闭,否则设备将被占用,下次将无法使用,只能重置来初始化。
完整DEMO可在海康的MVS软件下找到。
相机管理的设计思路与之前通信的思路大致相同,提供相机加入的功能,封装相机的SDK提供设备列表,对相机SN进行绑定,最后根据配置进行加载。
public class CameraDeviceModel
{
public long Id { set; get; }
/// <summary>
/// 设备SN
/// </summary>
public string Sn { set; get; }
public string Name { set; get; }
public bool IsActive { set; get; } = true;
public string CameraType { set; get; }
/// <summary>
/// 通信类型
/// </summary>
public CameraCommunicationTypeEnum CommunicationType { set; get; } = CameraCommunicationTypeEnum.Gige;
public CameraTypeEnum Type { set; get; }
public CameraCollectTypeEnum CameraCollectType { set; get; } = CameraCollectTypeEnum.Trigger;
public FileFormatEnum FileFormat { set; get; } = FileFormatEnum.BMP;
/// <summary>
/// 曝光时间
/// </summary>
public decimal ExposureTime { set; get; }
public decimal Gain { set; get; }// 增益
/// <summary>
/// 帧率
/// </summary>
public decimal FrameRate { set; get; }
}
边栏推荐
- [opengl] face pinching system
- [engine development] rendering architecture and advanced graphics programming
- CentOS7部署哨兵Redis(带架构图,清晰易懂)
- 【Transformer】入门篇-哈佛Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文The Annotated Transformer
- [probably the most complete in Chinese] pushgateway entry notes
- Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
- SQL server安装位置改不了
- Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
- Web server code parsing - thread pool
猜你喜欢
零拷贝底层剖析
【pytorch学习笔记】Datasets and Dataloaders
【Transformer】入门篇-哈佛Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文The Annotated Transformer
Open under vs2019 UI file QT designer flash back problem
Besides lying flat, what else can a 27 year old do in life?
[ue4] geometry drawing pipeline
Yolov5 series (I) -- network visualization tool netron
[graphics] real shading in Unreal Engine 4
Remote server background hangs nohup
C string format (decimal point retention / decimal conversion, etc.)
随机推荐
[probably the most complete in Chinese] pushgateway entry notes
使用Tengine解决负载均衡的Session问题
[opengl] geometry shader
Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
Class part2
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
App全局异常捕获
[pytorch learning notes] transforms
Detailed comments on MapReduce instance code on the official website
Remote server background hangs nohup
Influxdb2 sources add data sources
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
使用JMeter对WebService进行压力测试
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
[wechat applet] wxss template style
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
mysql innodb 存储引擎的特性—行锁剖析
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Troubleshooting method of CPU surge