1206 lines
46 KiB
C#
1206 lines
46 KiB
C#
using Basler.Pylon;
|
||
using Community;
|
||
using HalconDotNet;
|
||
using MvCamCtrl.NET;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
|
||
namespace Model.Vision
|
||
{
|
||
/// <summary>
|
||
/// 海康威视相机对象
|
||
/// </summary>
|
||
public class HikCamera : FeiYuCamere
|
||
{
|
||
|
||
/// <summary>
|
||
/// 相机对象
|
||
/// </summary>
|
||
public Camera camera = null;
|
||
|
||
private IntPtr latestFrameAddress = IntPtr.Zero; // 图像格式转换后的首地址,用于pylon转halcon,visionpro等图像变量
|
||
/// <summary>
|
||
/// 计时器 用于获取取图所用时间
|
||
/// </summary>
|
||
private Stopwatch stopWatch = new Stopwatch();
|
||
|
||
/// <summary>
|
||
/// if >= Sfnc2_0_0,说明是USB3的相机
|
||
/// </summary>
|
||
static Version Sfnc2_0_0 = new Version(2, 0, 0);
|
||
|
||
|
||
|
||
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
|
||
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
|
||
|
||
//相机驱动集合
|
||
MyCamera.MV_CC_DEVICE_INFO_LIST m_stDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
|
||
/// <summary>
|
||
/// 相机对象
|
||
/// </summary>
|
||
private MyCamera m_MyCamera = null;
|
||
/// <summary>
|
||
/// 相机对象驱动
|
||
/// </summary>
|
||
private MyCamera.MV_CC_DEVICE_INFO Mydevice = new MyCamera.MV_CC_DEVICE_INFO();
|
||
/// <summary>
|
||
/// 连续取图线程
|
||
/// </summary>
|
||
Thread m_hReceiveThread = null;
|
||
|
||
// IntPtr m_BufForDriver = IntPtr.Zero;// 图像格式转换后的首地址,用于pylon转halcon,visionpro等图像变量
|
||
// private static Object BufForDriverLock = new Object();
|
||
/// <summary>
|
||
/// 是否取图
|
||
/// </summary>
|
||
bool m_bGrabbing { get; set; }
|
||
|
||
/// <summary>
|
||
/// 相机是否已打开
|
||
/// </summary>
|
||
bool CamIsOpen { get; set; }
|
||
|
||
HObject ho_image;
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 分辨率设置委托事件
|
||
/// </summary>
|
||
public override event delegateResolvingPower resolvingPowerSet;
|
||
/// <summary>
|
||
/// 图像处理委托事件
|
||
/// </summary>
|
||
public override event delegateProcessHImage eventProcessImage;
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
public HikCamera()
|
||
{
|
||
|
||
GetCamNameList(); //获取所有相机列表
|
||
|
||
State = new ShowInfo();
|
||
State.StatuInfo = "";
|
||
State.StatusBackground = ColorStr.Gray;
|
||
State.StatusForeground = ColorStr.White;
|
||
}
|
||
|
||
#region 初始化相机
|
||
/// <summary>
|
||
/// 初始化相机
|
||
/// </summary>
|
||
public override bool InitializeCam()
|
||
{
|
||
try
|
||
{
|
||
if (CamNameList != null && !CamNameList.Contains(CamName))
|
||
{
|
||
ErrorMessage = "未识别到UserID为“" + CamName.ToString() + "”的相机!请重新选择相机";
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
int a = CamNameList.IndexOf(CamName); //获取当前名称在集合中的索引
|
||
// ch:获取选择的设备信息 | en:Get selected device information
|
||
MyCamera.MV_CC_DEVICE_INFO Mydevice = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[a], typeof(MyCamera.MV_CC_DEVICE_INFO));
|
||
m_MyCamera = new MyCamera();
|
||
//创建相机设备对象
|
||
int nRet = m_MyCamera.MV_CC_CreateDevice_NET(ref Mydevice);
|
||
if (MyCamera.MV_OK != nRet)
|
||
{
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
return true;
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取相机名称列表名称集合
|
||
/// <summary>
|
||
/// 获取相机名称列表名称集合
|
||
/// </summary>
|
||
public override void GetCamNameList()
|
||
{
|
||
CamNameList = new List<string>();
|
||
try
|
||
{
|
||
|
||
m_stDeviceList.nDeviceNum = 0;
|
||
int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_stDeviceList);
|
||
if (0 != nRet)
|
||
{
|
||
ErrorMessage = "没有找到任何相机";
|
||
return;
|
||
}
|
||
|
||
|
||
for (int i = 0; i < m_stDeviceList.nDeviceNum; i++)
|
||
{
|
||
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
|
||
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||
{
|
||
MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
|
||
|
||
if (gigeInfo.chUserDefinedName != "")
|
||
{
|
||
|
||
CamNameList.Add(gigeInfo.chUserDefinedName);
|
||
}
|
||
else
|
||
{
|
||
CamNameList.Add(gigeInfo.chManufacturerName + " " + gigeInfo.chModelName);
|
||
}
|
||
}
|
||
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
|
||
{
|
||
MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO));
|
||
if (usbInfo.chUserDefinedName != "")
|
||
{
|
||
CamNameList.Add("U3V: " + usbInfo.chUserDefinedName + " (" + usbInfo.chSerialNumber + ")");
|
||
}
|
||
else
|
||
{
|
||
CamNameList.Add("U3V: " + usbInfo.chManufacturerName + " " + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")");
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowException(ex);
|
||
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 打开相机
|
||
/// <summary>
|
||
/// 打开相机
|
||
/// </summary>
|
||
public override bool OpenCam()
|
||
{
|
||
if (m_MyCamera == null)
|
||
{
|
||
if (!InitializeCam())
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
//相机已打开
|
||
if (CamIsOpen)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
|
||
|
||
try
|
||
{
|
||
int nRet = m_MyCamera.MV_CC_OpenDevice_NET();
|
||
if (MyCamera.MV_OK != nRet)
|
||
{
|
||
m_MyCamera.MV_CC_DestroyDevice_NET();
|
||
ErrorMessage = "相机打开失败";
|
||
return false;
|
||
}
|
||
|
||
// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
|
||
if (Mydevice.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||
{
|
||
int nPacketSize = m_MyCamera.MV_CC_GetOptimalPacketSize_NET();
|
||
if (nPacketSize > 0)
|
||
{
|
||
nRet = m_MyCamera.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
|
||
if (nRet != MyCamera.MV_OK)
|
||
{
|
||
ErrorMessage = "设置数据大小失败";
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ErrorMessage = "设置数据大小失败";
|
||
}
|
||
}
|
||
MyCamera.MVCC_INTVALUE_EX a = new MyCamera.MVCC_INTVALUE_EX();
|
||
// 获取图像宽
|
||
m_MyCamera.MV_CC_GetIntValueEx_NET("Width", ref a);
|
||
Img_Width = (int)a.nCurValue;
|
||
// 获取图像高
|
||
m_MyCamera.MV_CC_GetIntValueEx_NET("Height", ref a);
|
||
Img_Height = (int)a.nCurValue;
|
||
|
||
GetMinMaxExposureTime();
|
||
GetMinMaxGain();
|
||
SetFPS(FPS);
|
||
SetExposureTime(ExposureTime);
|
||
SetGain(Gain);
|
||
|
||
// ch:设置采集连续模式 | en:Set Continues Aquisition Mode
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", (uint)MyCamera.MV_CAM_ACQUISITION_MODE.MV_ACQ_MODE_CONTINUOUS);
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_OFF);
|
||
|
||
CamIsOpen = true;
|
||
return true;
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 关闭相机,释放相关资源
|
||
/// <summary>
|
||
/// 关闭相机,释放相关资源
|
||
/// </summary>
|
||
public override void CloseCam()
|
||
{
|
||
try
|
||
{
|
||
// ch:停止采集 | en:Stop Grabbing
|
||
int nRet = m_MyCamera.MV_CC_StopGrabbing_NET();
|
||
|
||
// ch:取流标志位清零 | en:Reset flow flag bit
|
||
if (m_bGrabbing == true)
|
||
{
|
||
m_bGrabbing = false;
|
||
m_hReceiveThread.Join();
|
||
}
|
||
|
||
//if (m_BufForDriver != IntPtr.Zero)
|
||
//{
|
||
// Marshal.Release(m_BufForDriver);
|
||
//}
|
||
|
||
// ch:关闭设备 | en:Close Device
|
||
m_MyCamera.MV_CC_CloseDevice_NET();
|
||
m_MyCamera.MV_CC_DestroyDevice_NET();
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 单张采集
|
||
bool First = true;
|
||
/// <summary>
|
||
/// 单张采集
|
||
/// </summary>
|
||
public override HObject GrabOne()
|
||
{
|
||
try
|
||
{
|
||
//打开相机
|
||
if (!OpenCam())
|
||
{
|
||
return null;
|
||
}
|
||
|
||
//开启取图模式
|
||
if (!OpenReceiveImageMode())
|
||
{
|
||
return null;
|
||
}
|
||
|
||
ContinuousAcquisition = false;
|
||
resolvingPowerSet(new System.Windows.Rect(0, 0, Img_Width, Img_Height));//抛出分辨率设置事件
|
||
|
||
|
||
//打开触发模式
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON);
|
||
|
||
// ch:触发源选择:0 - Line0; | en:Trigger source select:0 - Line0;
|
||
// 1 - Line1;
|
||
// 2 - Line2;
|
||
// 3 - Line3;
|
||
// 4 - Counter;
|
||
// 7 - Software;
|
||
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE);
|
||
|
||
|
||
ErrorMessage = "";
|
||
ho_image = null;
|
||
// ch:触发命令 | en:Trigger command
|
||
int nRet = m_MyCamera.MV_CC_SetCommandValue_NET("TriggerSoftware");
|
||
if (MyCamera.MV_OK != nRet)
|
||
{
|
||
ErrorMessage = "取图失败";
|
||
}
|
||
|
||
DateTime temptime = DateTime.Now;
|
||
while (ho_image == null)
|
||
{
|
||
if (temptime.AddMilliseconds(5000) < DateTime.Now)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
resolvingPowerSet(new System.Windows.Rect(0, 0, Img_Width, Img_Height));//抛出分辨率设置事件
|
||
//如果是第一次取图 则先存储再读取 因为这里是一个BUG 必须第一次先存一下 否则各种错误
|
||
if (First)
|
||
{
|
||
|
||
//创建文件夹
|
||
if (!Directory.Exists(@"Image/"))
|
||
{
|
||
Directory.CreateDirectory(@"Image/");
|
||
}
|
||
|
||
string filePath = @"Image/TEST.bmp"; //模板图片路径
|
||
HOperatorSet.WriteImage(ho_image, "bmp", 0, filePath);
|
||
|
||
if (File.Exists(filePath)) //如果指定模板图片存在
|
||
{
|
||
HOperatorSet.GenEmptyObj(out ho_image);
|
||
//从文件获取图片
|
||
HOperatorSet.ReadImage(out ho_image, filePath);
|
||
First = false;
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
return ho_image;
|
||
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
return null;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 开始连续采集
|
||
|
||
/// <summary>
|
||
/// 开始连续采集
|
||
/// </summary>
|
||
public override bool StartGrabbing()
|
||
{
|
||
try
|
||
{
|
||
|
||
if (!OpenCam())
|
||
{
|
||
return false;
|
||
}
|
||
|
||
|
||
resolvingPowerSet(new System.Windows.Rect(0, 0, Img_Width, Img_Height));//抛出分辨率设置事件
|
||
|
||
//设置连续采集模式
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_OFF);
|
||
|
||
|
||
//开启取图模式
|
||
if (!OpenReceiveImageMode())
|
||
{
|
||
ErrorMessage = "连续采集开启失败";
|
||
return false;
|
||
|
||
}
|
||
|
||
ContinuousAcquisition = true;
|
||
return true;
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ContinuousAcquisition = false;
|
||
m_bGrabbing = false;
|
||
m_hReceiveThread.Join();
|
||
ShowException(e);
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 停止连续采集
|
||
/// <summary>
|
||
/// 停止连续采集
|
||
/// </summary>
|
||
public override void StopGrabbing()
|
||
{
|
||
try
|
||
{
|
||
|
||
// ch:停止采集 | en:Stop Grabbing
|
||
int nRet = m_MyCamera.MV_CC_StopGrabbing_NET();
|
||
if (nRet != MyCamera.MV_OK)
|
||
{
|
||
ErrorMessage = "停止采集发生未知错误";
|
||
}
|
||
|
||
// ch:标志位设为false | en:Set flag bit false
|
||
ContinuousAcquisition = false;
|
||
m_bGrabbing = false;
|
||
// m_hReceiveThread.Join();
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置Gige相机心跳时间
|
||
/// <summary>
|
||
/// 设置Gige相机心跳时间
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
public void SetHeartBeatTime(long value)
|
||
{
|
||
try
|
||
{
|
||
// 判断是否是网口相机,网口相机才有心跳时间
|
||
if (camera.GetSfncVersion() < Sfnc2_0_0)
|
||
{
|
||
camera.Parameters[PLGigECamera.GevHeartbeatTimeout].SetValue(value);
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置相机帧率
|
||
/// <summary>
|
||
/// 设置相机帧率
|
||
/// </summary>
|
||
/// <param name="FPS"></param>
|
||
public override void SetFPS(int value)
|
||
{
|
||
try
|
||
{
|
||
if (m_MyCamera == null||!CamIsOpen)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (m_MyCamera.MV_CC_SetFloatValue_NET("AcquisitionFrameRate", value) != 0)
|
||
{
|
||
ErrorMessage = "帧率设置失败";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
ShowException(ex);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置相机曝光时间
|
||
/// <summary>
|
||
/// 设置相机曝光时间
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
public override void SetExposureTime(long value)
|
||
{
|
||
try
|
||
{
|
||
if (m_MyCamera == null || !CamIsOpen)
|
||
{
|
||
return;
|
||
}
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("ExposureAuto", 0);
|
||
int nRet = m_MyCamera.MV_CC_SetFloatValue_NET("ExposureTime", value);
|
||
if (nRet != MyCamera.MV_OK)
|
||
{
|
||
ErrorMessage = "曝光设置失败";
|
||
}
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取最小最大曝光时间
|
||
/// <summary>
|
||
/// 获取最小最大曝光时间
|
||
/// </summary>
|
||
public void GetMinMaxExposureTime()
|
||
{
|
||
try
|
||
{
|
||
if (m_MyCamera == null)
|
||
{
|
||
|
||
}
|
||
|
||
MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
|
||
m_MyCamera.MV_CC_GetAutoExposureTimeLower_NET(ref stParam);
|
||
MinExposureTime = stParam.nCurValue;
|
||
|
||
m_MyCamera.MV_CC_GetAutoExposureTimeUpper_NET(ref stParam);
|
||
MaxExposureTime = stParam.nCurValue;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置增益
|
||
/// <summary>
|
||
/// 设置增益
|
||
/// </summary>
|
||
/// <param name="value"></param>
|
||
public override void SetGain(long value)
|
||
{
|
||
try
|
||
{
|
||
if (m_MyCamera == null || !CamIsOpen)
|
||
{
|
||
return;
|
||
}
|
||
m_MyCamera.MV_CC_SetEnumValue_NET("GainAuto", 0);
|
||
if (m_MyCamera.MV_CC_SetFloatValue_NET("Gain", value) != 0)
|
||
{
|
||
ErrorMessage = "增益设置失败";
|
||
}
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取最小最大增益
|
||
/// <summary>
|
||
/// 获取最小最大增益
|
||
/// </summary>
|
||
public void GetMinMaxGain()
|
||
{
|
||
try
|
||
{
|
||
MyCamera.MVCC_FLOATVALUE stParam = new MyCamera.MVCC_FLOATVALUE();
|
||
int nRet = m_MyCamera.MV_CC_GetFloatValue_NET("AutoGainLowerLimit", ref stParam);
|
||
if (MyCamera.MV_OK == nRet)
|
||
{
|
||
MinGain = (long)stParam.fCurValue;
|
||
|
||
}
|
||
|
||
nRet = m_MyCamera.MV_CC_GetFloatValue_NET("AutoGainUpperLimit", ref stParam);
|
||
if (MyCamera.MV_OK == nRet)
|
||
{
|
||
MaxGain = (long)stParam.fCurValue;
|
||
|
||
}
|
||
|
||
//MinGain = 0;
|
||
//MaxGain = 500;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置相机Freerun模式
|
||
/// <summary>
|
||
/// 设置相机Freerun模式
|
||
/// </summary>
|
||
public void SetFreerun()
|
||
{
|
||
try
|
||
{
|
||
// Set an enum parameter.
|
||
if (camera.GetSfncVersion() < Sfnc2_0_0)
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart))
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart))
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
}
|
||
else
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
}
|
||
}
|
||
}
|
||
else // For SFNC 2.0 cameras, e.g. USB3 Vision cameras
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart))
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart))
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
}
|
||
else
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
}
|
||
}
|
||
}
|
||
stopWatch.Restart(); // **** 重启采集时间计时器 ****
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置相机软触发模式
|
||
/// <summary>
|
||
/// 设置相机软触发模式
|
||
/// </summary>
|
||
public void SetSoftwareTrigger()
|
||
{
|
||
try
|
||
{
|
||
// Set an enum parameter.
|
||
if (camera.GetSfncVersion() < Sfnc2_0_0)
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart))
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart))
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software);
|
||
}
|
||
else
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software);
|
||
}
|
||
}
|
||
}
|
||
else // For SFNC 2.0 cameras, e.g. USB3 Vision cameras
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart))
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart))
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software);
|
||
}
|
||
else
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Software);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 发送软触发命令
|
||
/// <summary>
|
||
/// 发送软触发命令
|
||
/// </summary>
|
||
public void SendSoftwareExecute()
|
||
{
|
||
try
|
||
{
|
||
if (camera.WaitForFrameTriggerReady(1000, TimeoutHandling.ThrowException))
|
||
{
|
||
camera.ExecuteSoftwareTrigger();
|
||
}
|
||
}
|
||
catch (Exception exception)
|
||
{
|
||
ShowException(exception);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置相机外触发模式
|
||
/// <summary>
|
||
/// 设置相机外触发模式
|
||
/// </summary>
|
||
public void SetExternTrigger()
|
||
{
|
||
try
|
||
{
|
||
if (camera.GetSfncVersion() < Sfnc2_0_0)
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart))
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart))
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Line1);
|
||
}
|
||
else
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.AcquisitionStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Line1);
|
||
}
|
||
}
|
||
|
||
//Sets the trigger delay time in microseconds.
|
||
camera.Parameters[PLCamera.TriggerDelayAbs].SetValue(0); // 设置触发延时
|
||
|
||
//Sets the absolute value of the selected line debouncer time in microseconds
|
||
camera.Parameters[PLCamera.LineSelector].TrySetValue(PLCamera.LineSelector.Line1);
|
||
camera.Parameters[PLCamera.LineMode].TrySetValue(PLCamera.LineMode.Input);
|
||
camera.Parameters[PLCamera.LineDebouncerTimeAbs].SetValue(0); // 设置去抖延时,过滤触发信号干扰
|
||
|
||
}
|
||
else // For SFNC 2.0 cameras, e.g. USB3 Vision cameras
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart))
|
||
{
|
||
if (camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart))
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.Off);
|
||
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Line1);
|
||
}
|
||
else
|
||
{
|
||
camera.Parameters[PLCamera.TriggerSelector].TrySetValue(PLCamera.TriggerSelector.FrameBurstStart);
|
||
camera.Parameters[PLCamera.TriggerMode].TrySetValue(PLCamera.TriggerMode.On);
|
||
camera.Parameters[PLCamera.TriggerSource].TrySetValue(PLCamera.TriggerSource.Line1);
|
||
}
|
||
}
|
||
|
||
//Sets the trigger delay time in microseconds.//float
|
||
camera.Parameters[PLCamera.TriggerDelay].SetValue(0); // 设置触发延时
|
||
|
||
//Sets the absolute value of the selected line debouncer time in microseconds
|
||
camera.Parameters[PLCamera.LineSelector].TrySetValue(PLCamera.LineSelector.Line1);
|
||
camera.Parameters[PLCamera.LineMode].TrySetValue(PLCamera.LineMode.Input);
|
||
camera.Parameters[PLCamera.LineDebouncerTime].SetValue(0); // 设置去抖延时,过滤触发信号干扰
|
||
|
||
}
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
ShowException(e);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 掉线重连回调函数
|
||
/// <summary>
|
||
/// 掉线重连回调函数
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnConnectionLost(Object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
const int cTimeOutMs = 2000;
|
||
|
||
camera.Close();
|
||
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
ErrorMessage = "";
|
||
try
|
||
{
|
||
camera.Open(cTimeOutMs, TimeoutHandling.ThrowException);
|
||
if (camera.IsOpen)
|
||
{
|
||
State.StatusBackground = ColorStr.Green;
|
||
ErrorMessage = "已重新连接上UserID为“" + CamName + "”的相机!";
|
||
break;
|
||
}
|
||
Thread.Sleep(200);
|
||
}
|
||
catch
|
||
{
|
||
State.StatusBackground = ColorStr.Red;
|
||
ErrorMessage = "请重新连接UserID为“" + CamName + "”的相机!";
|
||
}
|
||
}
|
||
|
||
if (camera == null)
|
||
{
|
||
State.StatusBackground = ColorStr.Red;
|
||
ErrorMessage = "重连超时20s:未识别到UserID为“" + CamName + "”的相机!";
|
||
return;
|
||
}
|
||
|
||
SetHeartBeatTime(5000);
|
||
//camera.Parameters[PLCamera.AcquisitionFrameRateEnable].SetValue(true); // 限制相机帧率
|
||
//camera.Parameters[PLCamera.AcquisitionFrameRateAbs].SetValue(90);
|
||
//camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(10); // 设置内存中接收图像缓冲区大小
|
||
|
||
//Img_Width = (int)camera.Parameters[PLCamera.Width].GetValue(); // 获取图像宽
|
||
//Img_Height = (int)camera.Parameters[PLCamera.Height].GetValue(); // 获取图像高
|
||
//GetMinMaxExposureTime();
|
||
//GetMinMaxGain();
|
||
//camera.StreamGrabber.ImageGrabbed += OnImageGrabbed; // 注册采集回调函数
|
||
//camera.ConnectionLost += OnConnectionLost;
|
||
|
||
|
||
Img_Width = (int)camera.Parameters[PLCamera.Width].GetValue(); // 获取图像宽
|
||
Img_Height = (int)camera.Parameters[PLCamera.Height].GetValue(); // 获取图像高
|
||
|
||
GetMinMaxExposureTime();
|
||
GetMinMaxGain();
|
||
SetFPS(FPS);
|
||
SetExposureTime(ExposureTime);
|
||
SetGain(Gain);
|
||
|
||
|
||
Thread.Sleep(10);
|
||
}
|
||
catch (Exception exception)
|
||
{
|
||
ShowException(exception);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 报错信息显示
|
||
/// <summary>
|
||
/// 报错信息显示
|
||
/// </summary>
|
||
/// <param name="exception"></param>
|
||
private void ShowException(Exception exception)
|
||
{
|
||
ErrorMessage = exception.Message;
|
||
}
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 开启取图模式
|
||
/// </summary>
|
||
private bool OpenReceiveImageMode()
|
||
{
|
||
if (!m_bGrabbing)
|
||
{
|
||
m_bGrabbing = true;
|
||
if (m_hReceiveThread == null || !m_hReceiveThread.IsAlive)
|
||
{
|
||
m_hReceiveThread = new Thread(ReceiveImageWorkThread);
|
||
m_hReceiveThread.Start(m_MyCamera);
|
||
}
|
||
|
||
// ch:开始采集 | en:Start Grabbing
|
||
int nRet = m_MyCamera.MV_CC_StartGrabbing_NET();
|
||
if (MyCamera.MV_OK != nRet)
|
||
{
|
||
m_bGrabbing = false;
|
||
//m_hReceiveThread.Join();
|
||
ErrorMessage = "连续采集开启失败";
|
||
}
|
||
return m_bGrabbing;
|
||
|
||
}
|
||
else
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取图像
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void ReceiveImageWorkThread(object obj)
|
||
{
|
||
int nRet = MyCamera.MV_OK;
|
||
MyCamera device = obj as MyCamera;
|
||
MyCamera.MV_FRAME_OUT stFrameOut = new MyCamera.MV_FRAME_OUT();
|
||
|
||
IntPtr pImageBuf = IntPtr.Zero;
|
||
int nImageBufSize = 0;
|
||
|
||
ho_image = new HObject();
|
||
IntPtr pTemp = IntPtr.Zero;
|
||
|
||
while (m_bGrabbing)
|
||
{
|
||
nRet = device.MV_CC_GetImageBuffer_NET(ref stFrameOut, 1000);
|
||
if (MyCamera.MV_OK == nRet)
|
||
{
|
||
if (IsColorPixelFormat(stFrameOut.stFrameInfo.enPixelType))
|
||
{
|
||
if (stFrameOut.stFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
|
||
{
|
||
pTemp = stFrameOut.pBufAddr;
|
||
}
|
||
else
|
||
{
|
||
if (IntPtr.Zero == pImageBuf || nImageBufSize < (stFrameOut.stFrameInfo.nWidth * stFrameOut.stFrameInfo.nHeight * 3))
|
||
{
|
||
if (pImageBuf != IntPtr.Zero)
|
||
{
|
||
Marshal.FreeHGlobal(pImageBuf);
|
||
pImageBuf = IntPtr.Zero;
|
||
}
|
||
|
||
pImageBuf = Marshal.AllocHGlobal((int)stFrameOut.stFrameInfo.nWidth * stFrameOut.stFrameInfo.nHeight * 3);
|
||
if (IntPtr.Zero == pImageBuf)
|
||
{
|
||
break;
|
||
}
|
||
nImageBufSize = stFrameOut.stFrameInfo.nWidth * stFrameOut.stFrameInfo.nHeight * 3;
|
||
}
|
||
|
||
MyCamera.MV_PIXEL_CONVERT_PARAM stPixelConvertParam = new MyCamera.MV_PIXEL_CONVERT_PARAM();
|
||
|
||
stPixelConvertParam.pSrcData = stFrameOut.pBufAddr;//源数据
|
||
stPixelConvertParam.nWidth = stFrameOut.stFrameInfo.nWidth;//图像宽度
|
||
stPixelConvertParam.nHeight = stFrameOut.stFrameInfo.nHeight;//图像高度
|
||
stPixelConvertParam.enSrcPixelType = stFrameOut.stFrameInfo.enPixelType;//源数据的格式
|
||
stPixelConvertParam.nSrcDataLen = stFrameOut.stFrameInfo.nFrameLen;
|
||
|
||
stPixelConvertParam.nDstBufferSize = (uint)nImageBufSize;
|
||
stPixelConvertParam.pDstBuffer = pImageBuf;//转换后的数据
|
||
stPixelConvertParam.enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed;
|
||
nRet = device.MV_CC_ConvertPixelType_NET(ref stPixelConvertParam);//格式转换
|
||
if (MyCamera.MV_OK != nRet)
|
||
{
|
||
break;
|
||
}
|
||
pTemp = pImageBuf;
|
||
}
|
||
|
||
try
|
||
{
|
||
HOperatorSet.GenImageInterleaved(out ho_image, (HTuple)pTemp, (HTuple)"rgb", (HTuple)stFrameOut.stFrameInfo.nWidth, (HTuple)stFrameOut.stFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
MessageBox.Show(ex.ToString());
|
||
break;
|
||
}
|
||
}
|
||
else if (IsMonoPixelFormat(stFrameOut.stFrameInfo.enPixelType))
|
||
{
|
||
if (stFrameOut.stFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
|
||
{
|
||
pTemp = stFrameOut.pBufAddr;
|
||
}
|
||
else
|
||
{
|
||
if (IntPtr.Zero == pImageBuf || nImageBufSize < (stFrameOut.stFrameInfo.nWidth * stFrameOut.stFrameInfo.nHeight))
|
||
{
|
||
if (pImageBuf != IntPtr.Zero)
|
||
{
|
||
Marshal.FreeHGlobal(pImageBuf);
|
||
pImageBuf = IntPtr.Zero;
|
||
}
|
||
|
||
pImageBuf = Marshal.AllocHGlobal((int)stFrameOut.stFrameInfo.nWidth * stFrameOut.stFrameInfo.nHeight);
|
||
if (IntPtr.Zero == pImageBuf)
|
||
{
|
||
break;
|
||
}
|
||
nImageBufSize = stFrameOut.stFrameInfo.nWidth * stFrameOut.stFrameInfo.nHeight;
|
||
}
|
||
|
||
MyCamera.MV_PIXEL_CONVERT_PARAM stPixelConvertParam = new MyCamera.MV_PIXEL_CONVERT_PARAM();
|
||
|
||
stPixelConvertParam.pSrcData = stFrameOut.pBufAddr;//源数据
|
||
stPixelConvertParam.nWidth = stFrameOut.stFrameInfo.nWidth;//图像宽度
|
||
stPixelConvertParam.nHeight = stFrameOut.stFrameInfo.nHeight;//图像高度
|
||
stPixelConvertParam.enSrcPixelType = stFrameOut.stFrameInfo.enPixelType;//源数据的格式
|
||
stPixelConvertParam.nSrcDataLen = stFrameOut.stFrameInfo.nFrameLen;
|
||
|
||
stPixelConvertParam.nDstBufferSize = (uint)nImageBufSize;
|
||
stPixelConvertParam.pDstBuffer = pImageBuf;//转换后的数据
|
||
stPixelConvertParam.enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8;
|
||
nRet = device.MV_CC_ConvertPixelType_NET(ref stPixelConvertParam);//格式转换
|
||
if (MyCamera.MV_OK != nRet)
|
||
{
|
||
break;
|
||
}
|
||
pTemp = pImageBuf;
|
||
}
|
||
try
|
||
{
|
||
HOperatorSet.GenImage1Extern(out ho_image, "byte", stFrameOut.stFrameInfo.nWidth, stFrameOut.stFrameInfo.nHeight, pTemp, IntPtr.Zero);
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
MessageBox.Show(ex.ToString());
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
device.MV_CC_FreeImageBuffer_NET(ref stFrameOut);
|
||
continue;
|
||
}
|
||
|
||
// 抛出图像处理事件
|
||
if (ContinuousAcquisition)
|
||
{
|
||
eventProcessImage(this.ho_image);
|
||
}
|
||
|
||
if (SaveImageOri)
|
||
{
|
||
//创建文件夹
|
||
if (!Directory.Exists(@"D:/OriginalGraph/" + this.CamName + "/"))
|
||
{
|
||
Directory.CreateDirectory(@"D:/OriginalGraph/" + this.CamName + "/");
|
||
}
|
||
|
||
string filePath = @"D:/OriginalGraph/" + this.CamName + "/" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".bmp"; //模板图片路径 //保存模板图片
|
||
HOperatorSet.WriteImage(this.ho_image, "bmp", 0, filePath);
|
||
}
|
||
|
||
device.MV_CC_FreeImageBuffer_NET(ref stFrameOut);
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if (pImageBuf != IntPtr.Zero)
|
||
{
|
||
Marshal.FreeHGlobal(pImageBuf);
|
||
pImageBuf = IntPtr.Zero;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是否是彩色
|
||
/// </summary>
|
||
/// <param name="enType"></param>
|
||
/// <returns></returns>
|
||
private bool IsColorPixelFormat(MyCamera.MvGvspPixelType enType)
|
||
{
|
||
switch (enType)
|
||
{
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BGR8_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_RGBA8_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BGRA8_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_YUV422_YUYV_Packed:
|
||
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_BayerGB10:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB10_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG10_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG10_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR10_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB12_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG12_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG12_Packed:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12:
|
||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR12_Packed:
|
||
return true;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 判断像素格式
|
||
/// </summary>
|
||
/// <param name="enType"></param>
|
||
/// <returns></returns>
|
||
private bool IsMonoPixelFormat(MyCamera.MvGvspPixelType enType)
|
||
{
|
||
switch (enType)
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|