Пример #1
0
        /// <summary>
        /// 枚举在线相机
        /// </summary>
        /// <returns></returns>
        public override bool DoEnumerateCameraList()
        {
            try
            {
                if (m_objIGXFactory == null)
                {
                    return(false);
                }
                //

                listGXDeviceInfo = new List <IGXDeviceInfo>();
                //关闭流
                __CloseStream();
                // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开
                __CloseDevice();
                m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo);
                if (listGXDeviceInfo.Count() <= 0)
                {
                    ////ErrorMessage.Clear();
                    ////ErrorMessage.Append("大恒相机枚举设备失败");
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #2
0
        public bool Open()
        {
            if (m_bIsOpen)
            {
                return(m_bIsOpen);
            }
            bool result = false;

            try
            {
                List <IGXDeviceInfo> listGXDeviceInfo = new List <IGXDeviceInfo>();

                //关闭流
                __CloseStream();
                // 如果设备已经打开则关闭,保证相机在初始化出错情况下能再次打开
                __CloseDevice();

                m_objIGXFactory.UpdateDeviceList(200, listGXDeviceInfo);

                // 判断当前连接设备个数
                if (listGXDeviceInfo.Count <= 0)
                {
                    throw new Exception("没有发现设备");
                }

                //打开列表第一个设备

                m_objIGXDevice         = m_objIGXFactory.OpenDeviceBySN(listGXDeviceInfo[0].GetSN(), GX_ACCESS_MODE.GX_ACCESS_EXCLUSIVE);
                m_objIGXFeatureControl = m_objIGXDevice.GetRemoteFeatureControl();


                //打开流
                if (null != m_objIGXDevice)
                {
                    m_objIGXStream = m_objIGXDevice.OpenStream(0);
                }

                __InitDevice();

                m_objGxBitmap = new GxBitmap(m_objIGXDevice);

                // 更新设备打开标识
                m_bIsOpen = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                result = m_bIsOpen;
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 枚举设备
        /// </summary>
        public void EnumDevice()
        {
            //listIGXDeviceInfo.Clear();
            objIGXFactory.UpdateDeviceList(200, listIGXDeviceInfo);
            if (listIGXDeviceInfo.Count == 0)
            {
                throw new Exception();
            }
            for (int i = 0; i < listIGXDeviceInfo.Count; i++)
            {
                Camera objCamera = new Camera();
                objCamera.strDisplayName = listIGXDeviceInfo[i].GetDisplayName();
                objCamera.strSN          = listIGXDeviceInfo[i].GetSN();

                listCamera.Add(objCamera);//添加相机列队
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            List <CameraSummary> summaries = new List <CameraSummary>();
            List <CameraSummary> found     = new List <CameraSummary>();

            List <IGXDeviceInfo> devices = new List <IGXDeviceInfo>();

            igxFactory.UpdateDeviceList(200, devices);

            foreach (IGXDeviceInfo device in devices)
            {
                string identifier = device.GetSN();
                bool   cached     = cache.ContainsKey(identifier);

                if (cached)
                {
                    // We've already seen this camera in the current Kinovea session.
                    //deviceIds[identifier] = device.GetDeviceID();
                    summaries.Add(cache[identifier]);
                    found.Add(cache[identifier]);
                    continue;
                }

                string             alias            = device.GetDisplayName();
                Bitmap             icon             = null;
                SpecificInfo       specific         = new SpecificInfo();
                Rectangle          displayRectangle = Rectangle.Empty;
                CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                ImageRotation      rotation         = ImageRotation.Rotate0;
                //deviceIndices[identifier] = device.GetDeviceID();

                if (blurbs != null)
                {
                    foreach (CameraBlurb blurb in blurbs)
                    {
                        if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                        {
                            continue;
                        }

                        // We know this camera from a previous Kinovea session, restore the user custom values.
                        alias            = blurb.Alias;
                        icon             = blurb.Icon ?? defaultIcon;
                        displayRectangle = blurb.DisplayRectangle;
                        if (!string.IsNullOrEmpty(blurb.AspectRatio))
                        {
                            aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                        }
                        if (!string.IsNullOrEmpty(blurb.Rotation))
                        {
                            rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                        }
                        specific = SpecificInfoDeserialize(blurb.Specific);
                        break;
                    }
                }

                icon = icon ?? defaultIcon;

                CameraSummary summary = new CameraSummary(alias, device.GetDisplayName(), identifier, icon, displayRectangle, aspectRatio, rotation, specific, this);

                summaries.Add(summary);
                found.Add(summary);
                cache.Add(identifier, summary);
            }

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        /// 拍摄单张
        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);
            }
        }