コード例 #1
0
 private void btnFindTemp2_Click(object sender, EventArgs e)
 {
     Variable.CamReturn cam = new Variable.CamReturn();
     if (VisionHelper.FindNccTemplate(Form_Main.Instance.imageSet.Image, Form_Main.Instance.imageSet.Roi, ModelID, 1, 0.6, 0, 0, 1, 1, ref cam))
     {
         VisionHelper.ShowResult(Form_Main.Instance.imageSet, cam);
         btnFindTemp2.BackColor = Color.Transparent;
     }
     else
     {
         btnFindTemp2.BackColor = Color.Red;
     }
 }
コード例 #2
0
        private void bStartChkCailb_Jig_Click(object sender, EventArgs e)
        {
            if (!bRun)
            {
                this.bStartChkCailb_Jig.Text = "正在测量...";
                ChkPoint_Jig_Act             = new List <PointF>();
                bRun = true;
                double col    = double.Parse(this.textCol_Jig.Text);
                double row    = double.Parse(this.textRow_Jig.Text);
                double rMin   = double.Parse(this.tMinR.Text);
                double rMax   = double.Parse(this.tMaxR.Text);
                double gian   = double.Parse(this.tGainValue.Text);
                double offset = double.Parse(this.tOffsetValue.Text);


                if (!Directory.Exists(Variable.sPath_SYS_Jig))
                {
                    Directory.CreateDirectory(Variable.sPath_SYS_Jig);
                }

                if (File.Exists(Variable.sPath_SYS_Jig + "Pt_Act.txt"))
                {
                    File.Delete(Variable.sPath_SYS_Jig + "Pt_Act.txt");
                }
                if (File.Exists(Variable.sPath_SYS_Jig + "Pt_Machine.txt"))
                {
                    File.Delete(Variable.sPath_SYS_Jig + "Pt_Machine.txt");
                }
                if (Thd_Cailb == null || !Thd_Cailb.IsAlive)
                {
                    Thd_Cailb = new Thread(() =>
                    {
                        Variable.CamReturn cam = new Variable.CamReturn();
                        Form_Main.Instance.StartGrabImage();

                        for (int i = 0; i < chkPoint_Jig.Count; i++)
                        {
                            #region 开始测量
                            try
                            {
                                if (!bRun)
                                {
                                    MessageBox.Show("停止侦测", "提示");
                                    return;
                                }

                                PointF Pt_Act = new PointF();
                                Pt_Act.X      = (float)Math.Floor(i / col);
                                Pt_Act.Y      = (float)(i - col * Pt_Act.X);
                                ChkPoint_Jig_Act.Add(Pt_Act);
                                PointF Pt_Machine = new PointF();
                                Form_Main.Instance.XYGoPosTillStop(20 * 1000, this.chkPoint_Jig[i], variable);
                                // 获得上相机图像
                                VisionImage image = Form_Main.Instance.GrabImage2View(Camera.CAM.Top);
                                image             = Form_Main.Instance.GainOffset(image, gian, offset);
                                Algorithms.Copy(image, Form_Main.Instance.imageSet.Image);
                                PointContour centr = new PointContour();
                                double rad         = 0;
                                if (VisionHelper.DetectCircle(Form_Main.Instance.imageSet.Image, Form_Main.Instance.imageSet.Roi, rMin, rMax, out centr, out rad))
                                {
                                    cam.X    = centr.X;
                                    cam.Y    = centr.Y;
                                    cam.IsOK = true;
                                    VisionHelper.ShowResult(Form_Main.Instance.imageSet, cam);
                                    Pt_Machine = Form_Main.Instance.Point2CCDCenter(this.chkPoint_Jig[i], new PointContour(cam.X, cam.Y), 0, 0);
                                }
                                else
                                {
                                    throw new Exception("寻找模板失败");
                                }
                                //if (VisionHelper.FindNccTemplate(Form_Main.Instance.imageSet.Image, Form_Main.Instance.imageSet.Roi, ModelID, 1, 0.5, 0, 0, 1, 1, ref cam))
                                //{
                                //    VisionHelper.ShowResult(Form_Main.Instance.imageSet, cam);
                                //    Pt_Machine = Form_Main.Instance.Point2CCDCenter(this.chkPoint_Jig[i], new PointContour(cam.X, cam.Y), 0);
                                //}
                                //else
                                //{
                                //    throw new Exception("寻找模板失败");
                                //}

                                ChkPoint_Jig_Act.Add(Pt_Machine);

                                StreamWriter sw = File.AppendText(Variable.sPath_SYS_Jig + "Pt_Act.txt");
                                sw.Write(Pt_Act.X.ToString("F3") + "," + Pt_Act.Y.ToString("F3") + "\r\n");
                                sw.Close();
                                StreamWriter sw1 = File.AppendText(Variable.sPath_SYS_Jig + "Pt_Machine.txt");
                                sw1.Write(Pt_Machine.X.ToString("F3") + "," + Pt_Machine.Y.ToString("F3") + "\r\n");
                                sw1.Close();
                            }
                            catch (Exception ex)
                            {
                                if (MessageBox.Show($"侦测失败:{ex.Message} 是否重新识别 Y/N ", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    i--;
                                    continue;
                                }
                                else
                                {
                                    MessageBox.Show("玻璃杯校验停止!!!");
                                    bRun = false;
                                    return;
                                }
                            }
                            #endregion
                        }
                    });

                    Thd_Cailb.Start();
                }
            }
            else
            {
                if (MessageBox.Show("是否停止测量", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    this.bStartChkCailb_Jig.Text = "开始测量";
                    bRun = false;
                }
            }
        }