当前位置:网站首页>视觉上位系统设计开发(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; }
}
边栏推荐
- Mmdetection learning rate and batch_ Size relationship
- 5-1 blocking / non blocking, synchronous / asynchronous
- Chapter 14 class part 1
- 406. Reconstruct the queue according to height
- [graphics] efficient target deformation animation based on OpenGL es 3.0
- Apache ant extension tutorial
- [opengl] advanced chapter of texture - principle of flowmap
- CentOS7部署哨兵Redis(带架构图,清晰易懂)
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
- What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
猜你喜欢

Vs+qt application development, set software icon icon

4-33--4-35

el-switch 赋值后状态不变化
![[probably the most complete in Chinese] pushgateway entry notes](/img/5a/6dcb75f5d713ff513ad6842ff53cc3.png)
[probably the most complete in Chinese] pushgateway entry notes

Construction of operation and maintenance system

Vs+qt multithreading implementation -- run and movetothread

Byte practice plane longitude 2

4-20-4-23 concurrent server, TCP state transition;

Série yolov5 (i) - - netron, un outil de visualisation de réseau

Functional modules and application scenarios covered by the productization of user portraits
随机推荐
Several sentences extracted from the book "leather bag"
Yolov5系列(一)——网络可视化工具netron
App global exception capture
406. 根据身高重建队列
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
Relationship between truncated random distribution and original distribution
Search in the two-dimensional array of leetcode sword offer (10)
[ue4] HISM large scale vegetation rendering solution
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
[graphics] real shading in Unreal Engine 4
解决pushgateway数据多次推送会覆盖的问题
el-switch 赋值后状态不变化
[engine development] rendering architecture and advanced graphics programming
C string format (decimal point retention / decimal conversion, etc.)
TPS61170QDRVRQ1
Leetcode the smallest number of the rotation array of the offer of the sword (11)
Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Byte practice surface longitude
Troubleshooting method of CPU surge