예제 #1
0
        private void DisplayCalib(HImage image)
        {
            if (ho_Caltab == null)
            {
                ho_Caltab = new HObject();
                ho_Caltab.GenEmptyObj();
            }
            ho_Caltab.Dispose();
            HOperatorSet.GetCalibDataObservContours(out ho_Caltab, CalibDataID, "caltab", 0, 0, index);
            HTuple hv_Row, hv_Column, hv_Index, hv_Pose;

            HOperatorSet.GetCalibDataObservPoints(CalibDataID, 0, 0, index, out hv_Row, out hv_Column, out hv_Index, out hv_Pose);
            if (ho_Cross == null)
            {
                ho_Cross = new HObject();
                ho_Cross.GenEmptyObj();
            }
            ho_Cross.Dispose();
            HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row, hv_Column, 30, 0.785398);

            mView.ClearList();
            if (image != null && image.IsInitialized())
            {
                mView.AddIconicVar(image);
            }
            if (ho_Caltab != null && ho_Caltab.IsInitialized())
            {
                mView.ChangeGraphicSettings(Mode.COLOR, "green");
                mView.ChangeGraphicSettings(Mode.LINEWIDTH, 3);
                mView.AddIconicVar(ho_Caltab);
            }
            if (ho_Cross != null && ho_Cross.IsInitialized())
            {
                mView.ChangeGraphicSettings(Mode.COLOR, "blue");
                mView.ChangeGraphicSettings(Mode.LINEWIDTH, 2);
                mView.AddIconicVar(ho_Cross);
            }
            mView.AddText(index.ToString(), 100, 100, 80, "green");
            mView.Repaint();
        }
        private void Camera_ImageEvent(object sender, ImageEventArgs e)
        {
            if (e.Command == Command.ExtTrigger)
            {
                //硬件触发
                TrigerRun(e, 1000, e.CameraIndex, true);
            }
            else if (e.Command == Command.Grab)
            {  //软触发
                TriggerRun(e, e.SettingIndex, 1000);
            }
            else
            {
                //#if DEBUG
                //  Util.Notify(string.Format("显示图像线程ID:{0}", Thread.CurrentThread.ManagedThreadId));
                //#endif
                //测试模式---如果换了工具组,就将上个正在测试的工具关闭。---很重要。
                if (autoUnit.IsTestMode)
                {
                    if (e.CameraIndex != autoUnit.toolShowUnit1.GetCameraIndex(autoUnit.CurrentSettingIndex))
                    {
                        if (CameraManger.CameraDic.ContainsKey(e.CameraIndex))
                        {
                            if (CameraManger.CameraDic[e.CameraIndex].IsContinuousShot)
                            {
                                CameraManger.CameraDic[e.CameraIndex].ContinuousShotStop();
                            }
                        }
                        return;
                    }
                    TrigerRun(e, 1, autoUnit.CurrentSettingIndex, false);
                }    //在线测试模式
                else ///连续采集图像,直接显示
                {
                    if (ImageRunFinishSignal.WaitOne(1))
                    {
                        autoUnit.Invoke(new Action(() =>
                        {
                            //显示图像
                            HWndCtrl hWndCtrl = cameraShowUnit.HWndUnit.HWndCtrl;
                            HTuple t0;
                            HOperatorSet.CountSeconds(out t0);
                            hWndCtrl.ClearList();
                            hWndCtrl.AddIconicVar(e.CameraImage);
                            hWndCtrl.Repaint();
                            //Application.DoEvents();//不要使用liscence,否则不对就会造成卡顿严重//高帧率下显示会卡顿

                            string cameraInfo = CameraManger.CameraDic[e.CameraIndex].GetCameraAcqInfo();
                            cameraShowUnit.HWndUnit.CameraMessage = string.Format("相机{0} {1}", e.CameraIndex, cameraInfo);

                            ImageRunFinishSignal.Set();

                            e.Dispose();
                        }));
                    }
                    else
                    {
                        e.Dispose();
                        //if (this.InvokeRequired)
                        //{
                        //    Thread.Sleep(10);
                        //}
                    }
                }//连续采集图像,直接显示
            }
        }