Example #1
0
 /// <summary>
 /// 相机丢失回调
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void OnConnectLoss(object sender, EventArgs e)
 {
     m_dev.ShutdownGrab();
     m_dev.Dispose();
     m_dev = null;
     if (event_OnConnectLoss != null)
     {
         event_OnConnectLoss();
     }
 }
Example #2
0
        // 相机丢失回调
        private void OnConnectLoss(object sender, EventArgs e)
        {
            m_dev.ShutdownGrab();
            m_dev.Dispose();
            m_dev = null;

            this.Invoke(new Action(() =>
            {
                btnOpen.Enabled            = true;
                btnClose.Enabled           = false;
                btnSoftwareTrigger.Enabled = false;
            }));
        }
Example #3
0
        // 窗口关闭
        protected override void OnClosed(EventArgs e)
        {
            if (m_dev != null)
            {
                m_dev.Dispose();
                m_dev = null;
            }

            if (_g != null)
            {
                _g.Dispose();
                _g = null;
            }

            base.OnClosed(e);
        }
Example #4
0
        // 打开相机
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                // 设备搜索
                List <IDeviceInfo> li = Enumerator.EnumerateDevices();
                if (li.Count > 0)
                {
                    // 获取搜索到的第一个设备
                    m_dev = Enumerator.GetDeviceByIndex(0);

                    // 注册链接时间
                    m_dev.CameraOpened   += OnCameraOpen;
                    m_dev.ConnectionLost += OnConnectLoss;
                    m_dev.CameraClosed   += OnCameraClose;

                    // 打开设备
                    if (!m_dev.Open())
                    {
                        MessageBox.Show(@"连接相机失败");
                        return;
                    }

                    // 打开Software Trigger
                    m_dev.TriggerSet.Open(TriggerSourceEnum.Software);

                    // 设置图像格式
                    using (IEnumParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImagePixelFormat])
                    {
                        p.SetValue("BayerRG12Packed");
                    }
                    // 设置图片亮度
                    using (IIntegraParameter p = m_dev.ParameterCollection[ParametrizeNameSet.Brightness])
                    {
                        p.SetValue(100);
                    }
                    //设置曝光时间
                    using (IFloatParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ExposureTime])
                    {
                        p.SetValue(50000);
                    }

                    /*
                     * // 设置图片高度
                     * using (IIntegraParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImageHeight])
                     * {
                     *  p.SetValue(600);
                     * }
                     * // 设置图片宽度
                     * using (IIntegraParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImageWidth])
                     * {
                     *  p.SetValue(600);
                     * }
                     */

                    // 注册码流回调事件
                    m_dev.StreamGrabber.ImageGrabbed += OnImageGrabbed;

                    // 开启码流
                    if (!m_dev.GrabUsingGrabLoopThread())
                    {
                        MessageBox.Show(@"开启码流失败");
                        return;
                    }

                    m_dev.ExecuteSoftwareTrigger();
                }
            }
            catch (Exception exception)
            {
                Catcher.Show(exception);
            }
        }