/// <summary> /// 打开设备打开流 /// </summary> public void OpenDevice() { // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开 if (null != objIGXDevice) { objIGXDevice.Close(); objIGXDevice = null; } //打开设备 objIGXDevice = IGXFactory.GetInstance().OpenDeviceBySN(strSN, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); objIGXFeatureControl = objIGXDevice.GetRemoteFeatureControl(); //打开流 objIGXStream = objIGXDevice.OpenStream(0); objIGXStreamFeatureControl = objIGXStream.GetFeatureControl(); //初始化相机参数 objIGXFeatureControl.GetEnumFeature("AcquisitionMode").SetValue("Continuous"); //设置采集模式连续采集 objIGXFeatureControl.GetEnumFeature("TriggerSource").SetValue("Software"); //设置触发源软触发 objIGXFeatureControl.GetEnumFeature("TriggerMode").SetValue("Off"); //默认实时 //更新设备打开标识 bIsOpen = true; }
public CDHCam(int i, PictureBox pic_ShowImage) { List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); IGXFactory.GetInstance().UpdateAllDeviceList(200, listGXDeviceInfo); strSN = listGXDeviceInfo[i].GetSN(); m_objIGXDevice = IGXFactory.GetInstance().OpenDeviceBySN(strSN, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); m_objGxBitmap = new GxBitmap(m_objIGXDevice, pic_ShowImage); isOpen = false; }
///<图像显示类对象 /// <summary> /// 关闭流 /// </summary> public DaHengCamera() { try { m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); }catch (Exception e) { } }
/// <summary> /// 加载窗体执行初始化UI和库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GxSingleCam_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; if (withTma) { tma = new CTMA500(); } try { IGXFactory.GetInstance().Init(); List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); IGXFactory.GetInstance().UpdateAllDeviceList(200, listGXDeviceInfo); foreach (IGXDeviceInfo objDeviceInfo in listGXDeviceInfo) { Console.WriteLine("#######################"); Console.WriteLine(objDeviceInfo.GetModelName()); Console.WriteLine(objDeviceInfo.GetVendorName()); Console.WriteLine(objDeviceInfo.GetUserID()); Console.WriteLine(objDeviceInfo.GetIP()); Console.WriteLine(objDeviceInfo.GetSN()); //更多的设备信息详见IGXDeviceInfo接口 } if (listGXDeviceInfo.Count > 1) { caml = new CDHCam(0, m_pic_ShowImage); camr = new CDHCam(1, m_pic2_ShowImage); } else { MessageBox.Show("摄像头数量不足~"); } } catch (CGalaxyException ex) { string strErrorInfo = "错误码为:" + ex.GetErrorCode().ToString() + "错误描述信息为:" + ex.Message; Console.WriteLine(strErrorInfo); } if (withros) { try { ros = new CROS("msi-PC", "http://192.168.1.2:11311"); System.Threading.Thread initthread = new Thread(new ParameterizedThreadStart(Init)); initthread.Start(); } catch (Exception ex) { string strErrorInfo = "错误码为:" + ex.ToString() + "错误描述信息为:" + ex.Message; Console.WriteLine(strErrorInfo); } } }
public static void InitDhSdk() { IGXFactory.GetInstance().Init(); //枚举超时时间假设为200ms listGXDeviceInfo.Clear(); IGXFactory.GetInstance().UpdateAllDeviceList(200, listGXDeviceInfo); foreach (IGXDeviceInfo objDeviceInfo in listGXDeviceInfo) { Console.WriteLine(objDeviceInfo.GetModelName()); Console.WriteLine(objDeviceInfo.GetVendorName()); } }
public static bool DaHeng_Init() { try { DaHeng_Uninit(); m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); return(true); } catch (Exception ex) { m_objIGXFactory = null; return(false); } }
/// <summary> /// 打开设备 /// </summary> public void OpenCamera(PictureBox m_pic_ShowImage) { CloseStream(); CloseCamera(); m_objIGXDevice = IGXFactory.GetInstance().OpenDeviceByUserID(strUserID, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl(); if (null != m_objIGXDevice) { m_objIGXStream = m_objIGXDevice.OpenStream(0); } InitCamera(); m_objCfg = m_objIGXDevice.CreateImageProcessConfig(); AllocImageData(); }
public override bool SanityCheck() { bool result = false; try { igxFactory = IGXFactory.GetInstance(); igxFactory.Init(); result = true; } catch { log.DebugFormat("Daheng Camera subsystem not available."); } return(result); }
private void m_btnOpenCamera_Click(object sender, EventArgs e) { try { List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); m_objIGXFactory.UpdateAllDeviceList(200, listGXDeviceInfo); camera = new GxCamera(); //ImageAlg testalg = new ImageAlg(); //Order order = new Order(); if (listGXDeviceInfo.Count <= 0) { MessageBox.Show("未发现设备!"); //int[,] p = new int[,] { { 4, 2 }, { 1, 1 }, { 2, 5 }, { 6, 7 } }; //Point[] points = new Point[4]; //for (int i = 0; i < 4; i++) //{ // points[i].X = p[i, 0]; // points[i].Y = p[i, 1]; //} //Point[] sorted = ImageAlg.SortPoints(points); return; } String strUserID = listGXDeviceInfo[0].GetUserID(); camera.strUserID = strUserID; //camera = new GxCamera(); ///////////////////////////////// camera.OpenCamera(m_pic_ShowImage); m_btnCloseCamera.Focus(); m_bIsOpen = true; UpdateUI(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public bool Open() { if (listGXDeviceInfo.Count > 0 && objDevice == null) { if (camera_id < listGXDeviceInfo.Count) { camera_sn = listGXDeviceInfo[camera_id].GetSN(); objDevice = IGXFactory.GetInstance().OpenDeviceBySN(camera_sn, GxIAPINET.GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); objIGXStream = objDevice.OpenStream(0); objIGXFeatureControl = objDevice.GetRemoteFeatureControl(); objIGXStream.RegisterCaptureCallback(objDevice, OnFrameCallbackFun); objIGXStream.StartGrab(); } else { Console.WriteLine("相机初始化失败!"); return(false); } return(true); } return(false); }
public bool Init() { m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo); for (int i = 0; i < listGXDeviceInfo.Count; i++) { AqDevice.IAqCamera camera = new AqDaHengCamera(); camera.Id = listGXDeviceInfo[i].GetDeviceID(); camera.Name = listGXDeviceInfo[i].GetUserID(); camera.Ip = listGXDeviceInfo[i].GetIP(); camera.Mac = listGXDeviceInfo[i].GetMAC(); cameras.Add(camera); } AqDaHengCamera.ObjIGXFactory = m_objIGXFactory; return(true); }
public int OpenCamera() { //关闭流 if (null != m_objIGXStream) { m_objIGXStream.Close(); m_objIGXStream = null; } //关闭设备 if (null != m_objIGXDevice) { m_objIGXDevice.Close(); m_objIGXDevice = null; } IGXFactory m_objIGXFactory = null; m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo); foreach (IGXDeviceInfo tempinfo in listGXDeviceInfo) { if (tempinfo.GetUserID() == this.name) { m_objIGXDevice = ObjIGXFactory.OpenDeviceByUserID(this.Name, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl(); m_DeviceOffLine = m_objIGXDevice.RegisterDeviceOfflineCallback(null, CallOffLineFunction); } } TriggerConfiguration(); SetExposureTime(); return(0); }
/// <summary> /// 打开相机 /// </summary> public override void Open() { // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开 if (null != objIGXDevice) { objIGXDevice.Close(); objIGXDevice = null; } //打开设备 objIGXDevice = IGXFactory.GetInstance().OpenDeviceBySN(strName, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); objIGXFeatureControl = objIGXDevice.GetRemoteFeatureControl(); //打开流 objIGXStream = objIGXDevice.OpenStream(0); objIGXStreamFeatureControl = objIGXStream.GetFeatureControl(); // 建议用户在打开网络相机之后,根据当前网络环境设置相机的流通道包长值, // 以提高网络相机的采集性能,设置方法参考以下代码。 GX_DEVICE_CLASS_LIST objDeviceClass = objIGXDevice.GetDeviceInfo().GetDeviceClass(); if (GX_DEVICE_CLASS_LIST.GX_DEVICE_CLASS_GEV == objDeviceClass) { // 判断设备是否支持流通道数据包功能 if (true == objIGXFeatureControl.IsImplemented("GevSCPSPacketSize")) { // 获取当前网络环境的最优包长值 uint nPacketSize = objIGXStream.GetOptimalPacketSize(); // 将最优包长值设置为当前设备的流通道包长值 objIGXFeatureControl.GetIntFeature("GevSCPSPacketSize").SetValue(nPacketSize); } } //初始化相机参数 objIGXFeatureControl.GetEnumFeature("AcquisitionMode").SetValue("Continuous"); //设置采集模式连续采集 objIGXFeatureControl.GetEnumFeature("TriggerSource").SetValue("Software"); //设置触发源软触发 objIGXFeatureControl.GetEnumFeature("TriggerMode").SetValue("On"); //默认单张 }
/// <summary> /// 枚举设备 /// </summary> public bool EnumDevice() { //初始化 objIGXFactory = IGXFactory.GetInstance(); objIGXFactory.Init(); listIGXDeviceInfo.Clear(); objIGXFactory.UpdateDeviceList(200, listIGXDeviceInfo); if (listIGXDeviceInfo.Count == 0) { return(false); } else { for (int i = 0; i < listIGXDeviceInfo.Count; i++) { Daheng objCamera = new Daheng(); objCamera.strName = listIGXDeviceInfo[i].GetSN(); listCamera.Add(objCamera);//添加相机列队 } return(true); } }
private void Snapshot_Click(object sender, EventArgs e) { try { //1.Open Device // Before using any GxIAPINET methods, the GxIAPINET must be initialized. m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); //open device List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); // Close stream __CloseStream(); // If the device is opened then close it to ensure the camera could open again. __CloseDevice(); // Enumerate all camera devices m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo); // Check if found any device if (listGXDeviceInfo.Count <= 0) { MessageBox.Show("No devices found!"); return; } //Open the first found device m_objIGXDevice = m_objIGXFactory.OpenDeviceBySN(listGXDeviceInfo[0].GetSN(), GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl(); // Open stream if (null != m_objIGXDevice) { m_objIGXStream = m_objIGXDevice.OpenStream(0); } // It is recommended that the user set the camera's stream channel packet length value // according to the current network environment after turning on // the network camera to improve the collection performance of the network camera. // For the setting method, refer to the following code. GX_DEVICE_CLASS_LIST objDeviceClass = m_objIGXDevice.GetDeviceInfo().GetDeviceClass(); if (GX_DEVICE_CLASS_LIST.GX_DEVICE_CLASS_GEV == objDeviceClass) { // Determine whether the device supports the stream channel packet function. if (true == m_objIGXFeatureControl.IsImplemented("GevSCPSPacketSize")) { // Get the optimal packet length value of the current network environment uint nPacketSize = m_objIGXStream.GetOptimalPacketSize(); // Set the optimal packet length value to the stream channel packet length of the current device. m_objIGXFeatureControl.GetIntFeature("GevSCPSPacketSize").SetValue(nPacketSize); } } __InitDevice(); m_objGxBitmap = new GxBitmap(m_objIGXDevice, m_pic_ShowImage); //2.Start acquisition // Start stream channel acquisition if (null != m_objIGXStream) { m_objIGXStream.StartGrab(); } // Send AcquisitionStart command if (null != m_objIGXFeatureControl) { m_objIGXFeatureControl.GetCommandFeature("AcquisitionStart").Execute(); } //3.Snapshot IImageData objIImageData = null; double dElapsedtime = 0; uint nTimeout = 500; //Flush image queues to clear out-of-date images if (null != m_objIGXStream) { m_objIGXStream.FlushQueue(); } //Send TriggerSoftware commands if (null != m_objIGXFeatureControl) { m_objIGXFeatureControl.GetCommandFeature("TriggerSoftware").Execute(); } //Get image if (null != m_objIGXStream) { //Start stopwatch m_objStopTime.Start(); objIImageData = m_objIGXStream.GetImage(nTimeout); //Stop stopwatch and get the ElapsedTime dElapsedtime = m_objStopTime.Stop(); } m_objGxBitmap.Show(objIImageData); string strFileName = @"D:\TestImages\SWS.bmp"; m_objGxBitmap.SaveBmp(objIImageData, strFileName); if (null != objIImageData) { // Release resource objIImageData.Destroy(); } //4.Stop acquisition // Send AcquisitionStop command if (null != m_objIGXFeatureControl) { m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute(); } // Stop stream channel acquisition if (null != m_objIGXStream) { m_objIGXStream.StopGrab(); } //5.Close device // Reset statistical time count m_objStatistic.Reset(); // close stream and device __CloseAll(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void UninitDhSdk() { IGXFactory.GetInstance().Uninit(); }
//构造函数 public CameraManager() { //初始化 objIGXFactory = IGXFactory.GetInstance(); objIGXFactory.Init(); }
/// 拍摄单张 public void SingleShot(string save_path) { strSingleShotName = save_path; try { m_objIGXFactory = IGXFactory.GetInstance(); m_objIGXFactory.Init(); List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>(); //关闭流 __CloseStream(); // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开 __CloseDevice(); m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo); // 判断当前连接设备个数 if (listGXDeviceInfo.Count <= 0) { MessageBox.Show("未发现设备!"); return; } str_MySN = listGXDeviceInfo[0].GetSN(); m_objIGXDevice = m_objIGXFactory.OpenDeviceBySN(str_MySN, GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE); if (null == m_objIGXDevice) { MessageBox.Show(string.Format("未能打开相机{0}设备。", str_MySN)); return; } m_objGxBitmap = new GxBitmap(m_objIGXDevice); m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl(); if (null == m_objIGXFeatureControl) { MessageBox.Show(string.Format("未获得相机{0}属性控制。", str_MySN)); return; } m_objIGXStream = m_objIGXDevice.OpenStream(0); if (null == m_objIGXStream) { MessageBox.Show(string.Format("相机{0}获取流失败。", str_MySN)); } //初始化相机参数 m_objIGXFeatureControl.GetEnumFeature("AcquisitionMode").SetValue("Continuous"); m_objIGXFeatureControl.GetEnumFeature("TriggerMode").SetValue("Off"); //打开流,获得单帧图像 m_objIGXStream.StartGrab(); m_objIGXFeatureControl.GetCommandFeature("AcquisitionStart").Execute(); IImageData singleImageData = m_objIGXStream.GetImage(100); m_objIGXFeatureControl.GetCommandFeature("AcquisitionStop").Execute(); m_objIGXFeatureControl = null; m_objIGXStream.StopGrab(); __CloseStream(); __CloseDevice(); m_objIGXFactory.Uninit(); if (!Directory.Exists(m_strFilePath)) { Directory.CreateDirectory(m_strFilePath); } strSingleShotName = m_strFilePath + "\\" + strSingleShotName; m_objGxBitmap.SaveBmp(singleImageData, strSingleShotName); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } }