Example #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("读取失败");
     }
 }
Example #2
0
 private void bGetImage_Click(object sender, EventArgs e)
 {
     try
     {
         VisionImage img = GetImage?.Invoke();
         //VisionImage img = new VisionImage();
         //img.ReadFile(@"C:\Users\lichen\Desktop\黑到白\1.bmp");
         if (img != null)
         {
             m_hoModedImage?.Dispose();
             m_hoModedImage = HalconHelper.NI2HImage(img);
             HTuple htWidth  = new HTuple();
             HTuple htHeight = new HTuple();
             HOperatorSet.GetImageSize(m_hoModedImage, out htWidth, out htHeight);
             HOperatorSet.SetPart(m_htWindowHandle, 0, 0, htHeight, htWidth);
             HOperatorSet.DispObj(m_hoModedImage, m_htWindowHandle);
             zoom_beginRow = 0;
             zoom_beginCol = 0;
             zoom_endCol   = htWidth;
             zoom_endRow   = htHeight;
             isLoadImage   = true;
         }
     }
     catch { }
 }
        private void EnableButtons()
        {
            if (CloseForm.InvokeRequired)
            {
                CloseForm.Invoke(new MethodInvoker(delegate { CloseForm.Enabled = true; }));
            }
            else
            {
                CloseForm.Enabled = true;
            }

            if (GetImage.InvokeRequired)
            {
                GetImage.Invoke(new MethodInvoker(delegate { GetImage.Text = pictureDialog.GetButtonText(RetryCounter); }));
                GetImage.Invoke(new MethodInvoker(delegate { GetImage.Enabled = true; }));
            }
            else
            {
                GetImage.Enabled = true;
                GetImage.Text    = pictureDialog.GetButtonText(RetryCounter);
            }
        }
        private void bAutoCliab1_Click(object sender, EventArgs e)
        {
            if (fm_SoftwareCliab.FindTemp == null || fm_SoftwareCliab.FindTemp.GetInvocationList().Length <= 0)
            {
                MessageBox.Show("请打开相机轴控界面!!");
                return;
            }

            #region 九点标定
            Task.Factory.StartNew(() =>
            {
                float.TryParse(this.tXSpace.Text, out this.xspace);
                float.TryParse(this.tYSpace.Text, out this.yspace);

                List <PointF> WorldPt = new List <PointF>();
                PointF start          = new PointF(orgPt.X - xspace, orgPt.Y - yspace);
                for (int i = 0; i < 3; ++i)
                {
                    for (int j = 0; j < 3; ++j)
                    {
                        WorldPt.Add(new PointF(start.X + i * xspace, start.Y + j * yspace));
                    }
                }

                // 拍照 标定 记录图像坐标
                List <PointContour> ImagePt = new List <PointContour>();
                var camera = CameraDefine.Instance.CameraList[this.module.Module][this.calibRatio1.SelectCam];
                var entiy  = SystemEntiy.Instance[this.module.Module];
                for (int I = 0; I < WorldPt.Count; ++I)
                {
                    entiy.XYGoPosTillStop(WorldPt[I]);
                    // Grab Image and Calc
                    var result = fm_SoftwareCliab.FindTemp.Invoke(this.module.Module, this.calibRatio1.SelectCam);
                    if (result.State == VisionResultState.OK)
                    {
                        ImagePt.Add(result.Point);
                    }
                    else
                    {
                        MessageBox.Show("侦测失败!!");
                        return;
                    }
                }

                short rtn = 0;

                var image = GetImage?.Invoke();
                if (image == null)
                {
                    MessageBox.Show("获取图片失败!!!");
                    return;
                }

                if (this.calibRatio1.SelectCam == Camera.Top || this.calibRatio1.SelectCam == Camera.Label)
                {
                    this.AddCliab(this.module.Module, this.calibRatio1.SelectCam, 0, image, WorldPt, ImagePt);
                }
                else
                {
                    if (this.calibRatio1.SelectNz == Nozzle.Nz1 || this.calibRatio1.SelectNz == Nozzle.Nz3)
                    {
                        this.AddCliab(this.module.Module, this.calibRatio1.SelectCam, 0, image, WorldPt, ImagePt);
                    }
                    else
                    {
                        this.AddCliab(this.module.Module, this.calibRatio1.SelectCam, 1, image, WorldPt, ImagePt);
                    }
                }

                if (rtn == 0)
                {
                    CameraDefine.Save();
                    MessageBox.Show("相机标定成功!!");
                }
                else
                {
                    MessageBox.Show("相机标定成功!!");
                }
            });
            #endregion
        }
Example #5
0
        private void toolInputCamrea_Click(object sender, EventArgs e)
        {
            var img = GetImage?.Invoke();

            Algorithms.Copy(img, this.imageSet.Image);
        }