Exemplo n.º 1
0
 private void bRead_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.cbCodeList.Text != string.Empty)
         {
             if (GetImage == null || GetRoi == null)
             {
                 MessageBox.Show("请先打开相机界面!!!");
                 return;
             }
             using (VisionFlow flow = VisionFlow.Load(VisionToolCtrl.sPathVision + this.cbCodeList.Text))
             {
                 var image = GetImage?.Invoke();
                 var roi   = GetRoi?.Invoke();
                 if (roi == null || roi.Count == 0 || !(roi[0].Shape is RectangleContour))
                 {
                     MessageBox.Show("请在相机界面中绘制读取框!!!");
                     return;
                 }
                 var rtn = flow.Detect(image, roi[0].Shape);
                 this.tbBarcode.Text = rtn.BarCode;
             }
         }
     }
     catch
     {
         MessageBox.Show("读取失败");
     }
 }
        private void bSetViewROI_Click(object sender, EventArgs e)
        {
            var roi = GetRoi?.Invoke();

            if (roi != null && roi.Count > 0 && roi[0].Shape.GetType() == typeof(RectangleContour))
            {
                SystemConfig.Instance.Machines[this.module.Module].NozzleMap[this.selectNz2.SelectNz].ViewRoi = roi[0].Shape.Clone() as RectangleContour;
                SystemConfig.Save();
            }
            else
            {
                MessageBox.Show("请正确绘制ROI");
            }
        }
        private void bStart_Click(object sender, EventArgs e)
        {
            if (Array == null)
            {
                MessageBox.Show("请先生成量测参数!!!");
                return;
            }

            if (this.cbVisionList.Text == string.Empty)
            {
                MessageBox.Show("请选择量测算法!!!");
                return;
            }

            Roi roi = GetRoi?.Invoke();

            if (roi.Count == 0 || roi[0].Shape.GetType() != typeof(RectangleContour))
            {
                MessageBox.Show("请正确绘制ROI!!!");
                return;
            }

            rx = new double[Array.Length];
            x  = new double[Array.Length];

            double angle = 0;
            double space = (double)this.numSpace.Value;
            string func  = this.cbVisionList.Text;

            if (Aixs == GeneralAxis.X)
            {
                angle = MathHelper.GetAngle(Array[0], Array.Last()
                                            , Array[0], new PointF(Array[0].X + 10, Array[0].Y));
            }
            else
            {
                angle = MathHelper.GetAngle(Array[0], Array.Last()
                                            , Array[0], new PointF(Array[0].X, Array[0].Y - 10));
            }

            if (angle > 90)
            {
                angle = 180 - angle;
            }

            double rate = Math.Cos(angle * 180 / Math.PI);

            for (int i = 0; i < Array.Length; ++i)
            {
                SystemEntiy.Instance[this.module].XYGoPosTillStop(Array[i]);
                GoAndCheck(func, roi);
                GoAndCheck(func, roi);
                PointF xy = SystemEntiy.Instance[this.module].XYPos;

                double val = this.Aixs == GeneralAxis.X ? xy.X : xy.Y;

                // 再计算
                if (i == 0)
                {
                    x[0] = val;
                }
                else
                {
                    x[i]  = x[0] + (val - x[0]) * rate;
                    rx[i] = x[i] - (x[0] + space * i * rate);
                    this.dAxis.Rows[i].Cells[1].Value = (rx[i]).ToString("f3");
                }
            }
        }