//触发极化 public void TriggerPolary(TIS.Imaging.ICImagingControl icImagingControl1) { //极化初始化 TriPolarity = (TIS.Imaging.VCDSwitchProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_TriggerMode + ":" + TIS.Imaging.VCDIDs.VCDElement_TriggerPolarity + ":" + TIS.Imaging.VCDIDs.VCDInterface_Switch); TriPolarity.Switch = false; }
//软触发 public void Strigger(TIS.Imaging.ICImagingControl icImagingControl1) { Softtrigger = (TIS.Imaging.VCDButtonProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_TriggerMode + ":" + TIS.Imaging.VCDIDs.VCDElement_SoftwareTrigger + ":" + TIS.Imaging.VCDIDs.VCDInterface_Button); Softtrigger.Push();//软触发 }
//退出时关闭相机 public void CamClose(TIS.Imaging.ICImagingControl icImagingControl1) { if (icImagingControl1.DeviceValid) { icImagingControl1.LiveStop(); } }
//保存图片 public void SaveImage(TIS.Imaging.ICImagingControl icImagingControl1, string filename) { icImagingControl1.LiveStop(); icImagingControl1.LiveStart(); icImagingControl1.ImageActiveBuffer.SaveImage(filename + ".bmp"); }
//设置曝光 public void SetExposure(TIS.Imaging.ICImagingControl icImagingControl1, float ExposureTime) { ExposureSwitch = (TIS.Imaging.VCDSwitchProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Exposure + ":" + TIS.Imaging.VCDIDs.VCDElement_Auto + ":" + TIS.Imaging.VCDIDs.VCDInterface_Switch); if (ExposureSwitch != null) { ExposureSwitch.Switch = false; //取消自动曝光 ExposureAbsoluteValue = (TIS.Imaging.VCDAbsoluteValueProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Exposure + ":" + TIS.Imaging.VCDIDs.VCDElement_Value + ":" + TIS.Imaging.VCDIDs.VCDInterface_AbsoluteValue); if (ExposureAbsoluteValue != null) { if (ExposureTime <= ExposureAbsoluteValue.RangeMin) { ExposureAbsoluteValue.Value = ExposureAbsoluteValue.RangeMin; } else if (ExposureTime >= ExposureAbsoluteValue.RangeMax) { ExposureAbsoluteValue.Value = ExposureAbsoluteValue.RangeMax; } else { ExposureAbsoluteValue.Value = ExposureTime; } } } }
//相机初始化 public void CameraInitialize(TIS.Imaging.ICImagingControl icImagingControl1) { try { icImagingControl1.LoadDeviceStateFromFile("device1.xml", true); //从文件加载相机文件,默认保存在当前工程中,也可以保存到绝对路径中 } catch (Exception) //捕捉加载文件错误信息 { icImagingControl1.ShowDeviceSettingsDialog(); //相机选择窗口 if (!icImagingControl1.DeviceValid) { MessageBox.Show("没有找到设备"); Application.Exit(); } else { icImagingControl1.SaveDeviceStateToFile("device1.xml");//保存相机参数到xml文件 } } //SN号打开相机 //OpenBySN(icImagingControl1, "37814466"); //初始化控件 icImagingControl1.LiveCaptureContinuous = true; //设置回调模式 icImagingControl1.LiveDisplayDefault = false; //取消窗口默认大小显示 //初始化设置 icImagingControl1.LiveDisplayHeight = icImagingControl1.Height; icImagingControl1.LiveDisplayWidth = icImagingControl1.Width; icImagingControl1.MemoryCurrentGrabberColorformat = TIS.Imaging.ICImagingControlColorformats.ICRGB32;//黑白格式为:ICY8;彩色格式为:ICRGB32 }
//SN号打开相机 public void OpenBySN(TIS.Imaging.ICImagingControl icImagingControl1, string Ctemp) { string temp = ""; if (icImagingControl1.Devices.Length > 0) { foreach (Device Dev in icImagingControl1.Devices) { if (Dev.GetSerialNumber(out temp)) { if (temp == Ctemp)//判断是否等于指定相机序号 { icImagingControl1.Device = Dev.Name; break; } } } if (!icImagingControl1.DeviceValid) { MessageBox.Show("没有找到相机,是否SN号有误!"); Application.Exit(); } } else { MessageBox.Show("没有找到设备,请确认相机是否连接好"); Application.Exit(); } }
/// <summary> /// 打开相机 /// </summary> /// <param name="strSN">相机ID号</param> /// <returns>成功返回true,失败返回false</returns> /// public bool Open(string strSN) { try { string tempSN = string.Empty; m_ImageControl = new ICImagingControl(); foreach (Device dev in m_ImageControl.Devices) { if (dev.GetSerialNumber(out tempSN)) { if (strSN == tempSN)//判断是否等于指定相机序号 { m_ImageControl.Device = dev.Name; break; } } } if (!m_ImageControl.DeviceValid) { throw new Exception("没有找到相机,是否SN号有误!"); } if (m_ImageControl.LiveVideoRunning) { m_ImageControl.LiveStop(); } m_ImageControl.MemoryCurrentGrabberColorformat = TIS.Imaging.ICImagingControlColorformats.ICY8; float[] Frame = m_ImageControl.DeviceFrameRates; m_ImageControl.DeviceFrameRate = Frame[0]; VCDProp = TIS.Imaging.VCDHelpers.VCDSimpleModule.GetSimplePropertyContainer(m_ImageControl.VCDPropertyItems); //m_ImageControl.DeviceListChangedExecutionMode = TIS.Imaging.EventExecutionMode.Invoke; //m_ImageControl.DeviceLostExecutionMode = TIS.Imaging.EventExecutionMode.AsyncInvoke; //m_ImageControl.ImageAvailableExecutionMode = TIS.Imaging.EventExecutionMode.Invoke; m_ImageControl.LiveCaptureContinuous = true; m_ImageControl.LiveDisplayDefault = false; m_ImageControl.ImageAvailable += ImageCallBack; m_byMonoBuffer = new byte[m_nWidth * m_nHeight]; m_ImageControl.LiveStart(); TrigEnableSwitch = (TIS.Imaging.VCDSwitchProperty)m_ImageControl.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_TriggerMode + ":" + TIS.Imaging.VCDIDs.VCDElement_Value + ":" + TIS.Imaging.VCDIDs.VCDInterface_Switch); TrigEnableSwitch.Switch = true; m_ImageControl.LiveStop(); //TrigEnableSwitch.Switch = false; // m_ImageControl.DeviceTrigger = false; Imagecamera cannot set trigger while openning bIsConnected = true; //IsConnected = true; return(true); } catch (Exception ex) { Trace.WriteLine("YMJ Init fail " + ex.Message); return(false); } }
//获取频闪极性属性 public void StrobePolarityFun(TIS.Imaging.ICImagingControl icImagingControl1) { StrobePolaritySwitch = (TIS.Imaging.VCDSwitchProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Strobe + ":" + TIS.Imaging.VCDIDs.VCDElement_StrobePolarity + ":" + TIS.Imaging.VCDIDs.VCDInterface_Switch); if (StrobePolaritySwitch != null) { StrobePolaritySwitch.Switch = true; } }
//频闪使能 public void StrobeEnable(TIS.Imaging.ICImagingControl icImagingControl1) { StrobeSwitch = (TIS.Imaging.VCDSwitchProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Strobe + ":" + TIS.Imaging.VCDIDs.VCDElement_Value + ":" + TIS.Imaging.VCDIDs.VCDInterface_Switch); if (StrobeSwitch != null) { StrobeSwitch.Switch = true;//频闪使能 } }
//触发使能 public void TriEnable(TIS.Imaging.ICImagingControl icImagingControl1) { TrigEnableSwitch = (TIS.Imaging.VCDSwitchProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_TriggerMode + ":" + TIS.Imaging.VCDIDs.VCDElement_Value + ":" + TIS.Imaging.VCDIDs.VCDInterface_Switch); if (TrigEnableSwitch != null) { TrigEnableSwitch.Switch = true;//触发使能 } }
public AviDialog(TIS.Imaging.ICImagingControl ic) : base() { //This call is required by the Windows Form Designer. InitializeComponent(); //Add any initialization after the InitializeComponent() call _ImagingControl = ic; }
//设置亮度 public void SetBrightness(TIS.Imaging.ICImagingControl icImagingControl1, int Brightness) { BrightnessRange = (TIS.Imaging.VCDRangeProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Brightness + ":" + TIS.Imaging.VCDIDs.VCDElement_Value + ":" + TIS.Imaging.VCDIDs.VCDInterface_Range); if (BrightnessRange != null) { //BrightnessRange.RangeMax //BrightnessRange.RangeMin //BrightnessRange.Value BrightnessRange.Value = Brightness; } }
//Debounce 防反跳() public void TriDebounce(TIS.Imaging.ICImagingControl icImagingControl1, double DeTime) { Trigger_Debounce_Time = (TIS.Imaging.VCDAbsoluteValueProperty)icImagingControl1.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_TriggerMode + ":" + TIS.Imaging.VCDIDs.VCDElement_TriggerDebounceTime + ":" + TIS.Imaging.VCDIDs.VCDInterface_AbsoluteValue); if (DeTime <= Trigger_Debounce_Time.RangeMin) { Trigger_Debounce_Time.Value = Trigger_Debounce_Time.RangeMin; } else if (DeTime >= Trigger_Debounce_Time.RangeMax) { Trigger_Debounce_Time.Value = Trigger_Debounce_Time.RangeMax; } else { Trigger_Debounce_Time.Value = DeTime; } }
public void CameraPara(TIS.Imaging.ICImagingControl icImagingControl1) { //文件打开相机 try { icImagingControl1.LoadDeviceStateFromFile("device1.xml", true); } catch (Exception) { // icImagingControl1.ShowDeviceSettingsDialog(); if (!icImagingControl1.DeviceValid) { MessageBox.Show("没有找到设备"); } else { icImagingControl1.SaveDeviceStateToFile("device1.xml"); } } }
//相机属性 public void Camproperty(TIS.Imaging.ICImagingControl icImagingControl1) { icImagingControl1.ShowPropertyDialog(); }
//关闭相机 public void StopLiveVideo(TIS.Imaging.ICImagingControl icImagingControl1) { icImagingControl1.LiveStop(); }