Exemplo n.º 1
0
        public override HalconDotNet.HObject GetModelRegion()
        {
            HalconDotNet.HObject rg  = new HalconDotNet.HObject();
            HalconDotNet.HObject crs = new HalconDotNet.HObject();

            crs.Dispose();
            HalconDotNet.HOperatorSet.GenCrossContourXld(out crs, _locateRow, _locateCol, 9999, 0);
            rg.Dispose();
            HalconDotNet.HOperatorSet.GenRegionContourXld(crs, out rg, new HalconDotNet.HTuple("filled"));

            crs.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out crs, _locateRow, _locateCol, 0, 5, 5);
            HalconDotNet.HOperatorSet.ConcatObj(rg, crs, out rg);
            return(rg);
        }
Exemplo n.º 2
0
 private void ContinueGrabBtn_Click(object sender, EventArgs e) //连续采集
 {
     ContinueGrabBtn.Enabled = false;
     IsContinnueGrab         = true;
     System.Threading.Tasks.Task.Factory.StartNew(new Action(() => {
         int i = 0;
         while (IsContinnueGrab)
         {
             i++;
             if (GrabedImg != null)
             {
                 GrabedImg.Dispose();
             }
             if (CameraCtrl.Instance.GrabImg(TeachCamLightPara.CamName, out GrabedImg))
             {
                 view1.Refresh();
                 view1.AddViewImage(GrabedImg);
                 view1.Repaint();
             }
             System.Threading.Thread.Sleep(100);
             if (i > 500)
             {
                 break;
             }
         }
     }));
 }
Exemplo n.º 3
0
        public override void Draw(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject rgCircle = new HalconDotNet.HObject();
            rgCircle.Dispose();
            HalconDotNet.HOperatorSet.GenCircle(out rgCircle, new HalconDotNet.HTuple(_locateRow), new HalconDotNet.HTuple(_locateCol), new HalconDotNet.HTuple(_radius));
            HalconDotNet.HOperatorSet.DispObj(rgCircle, hwndHandle);

            HalconDotNet.HObject rec1 = new HalconDotNet.HObject(), rec2 = new HalconDotNet.HObject();
            rec1.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec1,
                                                    new HalconDotNet.HTuple(_locateRow),
                                                    new HalconDotNet.HTuple(_locateCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec1, hwndHandle);

            rec2.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec2,
                                                    new HalconDotNet.HTuple(_sizeRow),
                                                    new HalconDotNet.HTuple(_sizeCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec2, hwndHandle);
        }
Exemplo n.º 4
0
        public override void DisplayActiveHandle(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject rec = new HalconDotNet.HObject();
            rec.Dispose();
            switch (ActiveHandleIdx)
            {
            case 0:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_locateRow),
                                                        new HalconDotNet.HTuple(_locateCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            case 1:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_sizeRow),
                                                        new HalconDotNet.HTuple(_sizeCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override HalconDotNet.HObject GetModelRegion()
        {
            HalconDotNet.HObject rgInternal = new HalconDotNet.HObject();
            rgInternal.Dispose();
            HalconDotNet.HOperatorSet.GenCircle(out rgInternal, new HalconDotNet.HTuple(_locateRow), new HalconDotNet.HTuple(_locateCol), new HalconDotNet.HTuple(_radiusInternal));

            HalconDotNet.HObject rgExternal = new HalconDotNet.HObject();
            rgExternal.Dispose();
            HalconDotNet.HOperatorSet.GenCircle(out rgExternal, new HalconDotNet.HTuple(_locateRow), new HalconDotNet.HTuple(_locateCol), new HalconDotNet.HTuple(_radiusExternal));

            HalconDotNet.HObject rg = new HalconDotNet.HObject();
            rg.Dispose();

            //计算圆环区域:半径大的圆与半径小的圆之间的差集
            if (_radiusExternal > _radiusInternal)
            {
                HalconDotNet.HOperatorSet.Difference(rgExternal, rgInternal, out rg);
            }
            else
            {
                HalconDotNet.HOperatorSet.Difference(rgInternal, rgExternal, out rg);
            }

            return(rg);
        }
Exemplo n.º 6
0
        public override void Draw(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject line = new HalconDotNet.HObject(), rec1 = new HalconDotNet.HObject(), rec2 = new HalconDotNet.HObject();
            line.Dispose();
            HalconDotNet.HOperatorSet.GenRegionLine(out line,
                                                    new HalconDotNet.HTuple(_startRow),
                                                    new HalconDotNet.HTuple(_startCol),
                                                    new HalconDotNet.HTuple(_extentRow),
                                                    new HalconDotNet.HTuple(_extentCol));
            HalconDotNet.HOperatorSet.DispObj(line, hwndHandle);

            rec1.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec1,
                                                    new HalconDotNet.HTuple(_startRow),
                                                    new HalconDotNet.HTuple(_startCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec1, hwndHandle);

            rec2.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec2,
                                                    new HalconDotNet.HTuple(_locateRow),
                                                    new HalconDotNet.HTuple(_locateCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec2, hwndHandle);
            if (_arrowHandle != null &&
                _arrowHandle.IsInitialized())
            {
                HalconDotNet.HOperatorSet.DispObj(_arrowHandle, hwndHandle);
            }
        }
Exemplo n.º 7
0
        public override void DisplayActiveHandle(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject rec = new HalconDotNet.HObject();
            rec.Dispose();
            switch (ActiveHandleIdx)
            {
            //定位圆心
            case 0:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_locateRow),
                                                        new HalconDotNet.HTuple(_locateCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //缩放边点
            case 1:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_sizeRow),
                                                        new HalconDotNet.HTuple(_sizeCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //弧段起始角点
            case 2:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_startRow),
                                                        new HalconDotNet.HTuple(_startCol),
                                                        new HalconDotNet.HTuple(_startPhi),
                                                        new HalconDotNet.HTuple(10),
                                                        new HalconDotNet.HTuple(2));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //弧段终止角点(箭头)
            case 3:
                if (_arrowHandle != null &&
                    _arrowHandle.IsInitialized())
                {
                    HalconDotNet.HOperatorSet.DispObj(_arrowHandle, hwndHandle);
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 窗口1显示的内容
        /// [可以自定义显示的内容]
        /// </summary>
        /// <param name="appProData"></param>
        private void Camera0UpdateIconic(ProVisionEbd.Data.AppProcessData appProData)
        {
            try
            {
                if (_hwndCtrller0 != null)
                {
                    if (appProData != null)
                    {
                        this.Invoke(new System.Windows.Forms.MethodInvoker(() => {
                            _hwndCtrller0.ClearEntities();
                            _hwndCtrller0.ClearMessageLineList();

                            if (_hoImage0 != null &&
                                _hoImage0.IsInitialized())
                            {
                                _hoImage0.Dispose();
                            }

                            _hoImage0 = appProData.RawImage.Clone();
                            _hwndCtrller0.AddHobjEntity(_hoImage0);

                            _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "yellow");
                            _hwndCtrller0.AddHobjEntity(appProData.InspetcRegion);
                            ProVision.Communal.MessageLine msl = new ProVision.Communal.MessageLine();

                            if (appProData.ImgProcessOK)
                            {
                                if (appProData.ImgResultOK)
                                {
                                    msl.Context  = "处理结果满足要求";
                                    msl.CtxColor = "green";
                                    _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "green");
                                }
                                else
                                {
                                    msl.Context  = "处理结果不满足要求";
                                    msl.CtxColor = "red";
                                    _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "red");
                                }
                            }
                            else
                            {
                                msl.Context  = "图像处理异常";
                                msl.CtxColor = "red";
                                _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "red");
                            }

                            _hwndCtrller0.AddMessageLine(msl);
                            _hwndCtrller0.AddHobjEntity(appProData.ResultRegion);
                            _hwndCtrller0.Repaint();
                            appProData.Dispose();
                        }));
                    }
                }
            }
            catch (HalconDotNet.HalconException hex) { }
            catch (System.Exception ex) { }
        }
Exemplo n.º 9
0
        public override void Draw(HalconDotNet.HTuple hwndHandle)
        {
            _circularArc.Dispose();
            HalconDotNet.HOperatorSet.GenCircleContourXld(out _circularArc,
                                                          new HalconDotNet.HTuple(_locateRow),
                                                          new HalconDotNet.HTuple(_locateCol),
                                                          new HalconDotNet.HTuple(_radius),
                                                          new HalconDotNet.HTuple(_startPhi),
                                                          new HalconDotNet.HTuple(_startPhi + _extentPhi),
                                                          new HalconDotNet.HTuple(_circularArcDir),
                                                          new HalconDotNet.HTuple(1.0));
            HalconDotNet.HOperatorSet.DispObj(_circularArc, hwndHandle);

            HalconDotNet.HObject rec1, rec2, rec3;

            HalconDotNet.HOperatorSet.GenRectangle2(out rec1,
                                                    new HalconDotNet.HTuple(_sizeRow),
                                                    new HalconDotNet.HTuple(_sizeCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec1, hwndHandle);

            HalconDotNet.HOperatorSet.GenRectangle2(out rec2,
                                                    new HalconDotNet.HTuple(_locateRow),
                                                    new HalconDotNet.HTuple(_locateCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec2, hwndHandle);

            HalconDotNet.HOperatorSet.GenRectangle2(out rec3,
                                                    new HalconDotNet.HTuple(_startRow),
                                                    new HalconDotNet.HTuple(_startCol),
                                                    new HalconDotNet.HTuple(_startPhi),
                                                    new HalconDotNet.HTuple(10),
                                                    new HalconDotNet.HTuple(2));
            HalconDotNet.HOperatorSet.DispObj(rec3, hwndHandle);

            if (_arrowHandle != null &&
                _arrowHandle.IsInitialized())
            {
                HalconDotNet.HOperatorSet.DispObj(_arrowHandle, hwndHandle);
            }
        }
Exemplo n.º 10
0
        public override void CreateROI(HalconDotNet.HWindow window, double row, double col)
        {
            HalconDotNet.HObject polygonXLD = new HalconDotNet.HObject();
            HalconDotNet.HTuple  tmpRows    = new HalconDotNet.HTuple();
            HalconDotNet.HTuple  tmpCols    = new HalconDotNet.HTuple();
            HalconDotNet.HTuple  tmpWights  = new HalconDotNet.HTuple();

            HalconDotNet.HTuple area    = new HalconDotNet.HTuple();
            HalconDotNet.HTuple r       = new HalconDotNet.HTuple();
            HalconDotNet.HTuple c       = new HalconDotNet.HTuple();
            HalconDotNet.HTuple pointer = new HalconDotNet.HTuple();

            try
            {
                polygonXLD.Dispose();
                HalconDotNet.HOperatorSet.DrawNurbs(out polygonXLD, window, "true", "true", "true", "true", 3,
                                                    out tmpRows, out tmpCols, out tmpWights);
                if (tmpRows.TupleLength() > 0)
                {
                    polygonXLD.Dispose();
                    HalconDotNet.HOperatorSet.GenContourPolygonXld(out polygonXLD, tmpRows, tmpCols);
                    HalconDotNet.HOperatorSet.AreaCenterXld(polygonXLD, out area, out r, out c, out pointer);

                    _locateRow = r[0].D;
                    _locateCol = c[0].D;

                    window.DispPolygon(tmpRows, tmpCols);
                    window.DispRectangle2(_locateRow, _locateCol, 0, 5, 5); //几何中心
                    this._numHandles = tmpRows.TupleLength() + 1;           //几何中心+边点

                    for (int i = 0; i < tmpRows.TupleLength(); i++)
                    {
                        _sizeRows.Add(tmpRows[i].D);
                        _sizeCols.Add(tmpCols[i].D);
                        window.DispRectangle2(tmpRows[i].D, tmpCols[i].D, 0, 2, 2);
                    }
                }
            }
            catch (HalconDotNet.HalconException hex)
            {
            }
        }
Exemplo n.º 11
0
 public override HalconDotNet.HObject GetModelRegion()
 {
     HalconDotNet.HObject rg = new HalconDotNet.HObject();
     rg.Dispose();
     HalconDotNet.HOperatorSet.GenRegionLine(out rg,
                                             new HalconDotNet.HTuple(_startRow),
                                             new HalconDotNet.HTuple(_startCol),
                                             new HalconDotNet.HTuple(_extentRow),
                                             new HalconDotNet.HTuple(_extentCol));
     return(rg);
 }
Exemplo n.º 12
0
        protected CameraDriver(ProCommon.Communal.CameraProperty camProperty)
        {
            if (HoImage != null &&
                HoImage.IsInitialized())
            {
                HoImage.Dispose();
            }
            HalconDotNet.HOperatorSet.GenEmptyObj(out HoImage);

            DriverExceptionDel  = new DriverExceptionOccuredDel(OnDriverExceptionOccured);
            this.CameraProperty = camProperty;
        }
Exemplo n.º 13
0
        private void CamParaDgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try{
                if (e.RowIndex >= 0)
                {
                    //当前行对应的相机参数
                    CameraPara CurCamPara = (CameraPara)this.CamParaDgv.CurrentRow.DataBoundItem;
                    if (CurCamPara == null)
                    {
                        return;
                    }
                    switch (CamParaDgv.Columns[e.ColumnIndex].Name)
                    {
                    case "DeleteBtnDgvCol":
                        if (MessageBox.Show("是否删除该项设备?    ", "删除提示", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) != DialogResult.Yes)
                        {
                            return;
                        }
                        CameraParaManager.Instance.CameraParaList.Remove(CurCamPara);
                        break;

                    case "OpenCamBtnDgvCol":
                        CameraPara camParaI;
                        for (int i = 0; i < CameraParaManager.Instance.CameraParaList.Count() - 1; i++)
                        {
                            camParaI = CameraParaManager.Instance.CameraParaList[i];
                            if (CurCamPara.CameraName == camParaI.CameraName)
                            {
                                MessageBox.Show("相机已经示教,请重新选择相机");
                                break;
                            }
                        }
                        CameraCtrl.Instance.Init();
                        break;

                    case "GrabImgDgvCol":
                        ImgOut.Dispose();
                        CameraCtrl.Instance.GrabImg(CurCamPara.CameraName, out ImgOut);
                        view.ResetView();
                        view.AddViewImage(ImgOut);
                        //view.Refresh();
                        view.Repaint();
                        break;
                    }
                    this.CamParaDgv.Refresh();
                }
            }
            catch
            { }
        }
Exemplo n.º 14
0
        private void LoadImage()
        {
            bool isChs = (LanguageVersion == ProCommon.Communal.Language.Chinese);

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            string txt     = isChs ? "图像文件" : "Image File";
            string caption = isChs ? "错误信息" : "Error Message";

            ofd.Filter      = txt + "(*.BMP,*.JPG,*.JPEG,*.TIF)|*.bmp;*.jpg;*.jpeg;*.tif";
            ofd.FilterIndex = 0;
            txt             = isChs ? "请选择一张图像文件" : "Select an image file";
            ofd.Title       = txt;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    _hoImage.Dispose();
                }

                try
                {
                    if (_HwndCtrller != null)
                    {
                        _HwndCtrller.ClearEntities();
                        if (_ROIManager != null)
                        {
                            _ROIManager.ROIList.Clear();
                        }

                        HalconDotNet.HOperatorSet.ReadImage(out _hoImage, new HalconDotNet.HTuple(ofd.FileName));

                        HalconDotNet.HOperatorSet.GetImageSize(_hoImage, out _imgWidth, out _imgHeight);
                        HalconDotNet.HOperatorSet.SetSystem("tsp_height", _imgHeight);
                        HalconDotNet.HOperatorSet.SetSystem("tsp_width", _imgWidth);

                        _HwndCtrller.AddHobjEntity(_hoImage);
                        _HwndCtrller.Repaint();
                    }
                }
                catch (HalconDotNet.HalconException hex)
                {
                    txt = isChs ? "加载图像失败!\r\n" : "Load image failed!\r\n";
                    ProCommon.DerivedForm.FrmMsgBox.Show(txt + hex.Message, caption,
                                                         ProCommon.DerivedForm.MyButtons.OK, ProCommon.DerivedForm.MyIcon.Error, isChs);
                }
            }
        }
Exemplo n.º 15
0
        protected override bool LoadAlgorithmFile()
        {
            bool rt = false;

            try
            {
                if (!string.IsNullOrEmpty(Parameter.PathForSaveLocPara))
                {
                    if (_matchModelAssistant != null)
                    {
                        if (_matchModelAssistant.LoadShapeModel(Parameter.PathForSaveLocPara))
                        {
                            rt = true;
                        }
                        else
                        {
                            ErrorMessage = IsChinese ? "定位参数文件加载失败!" : "Load parameter file for location failed!";
                        }

                        //更新搜索区域
                        if (rt)
                        {
                            if (InspectArea != null &&
                                InspectArea.IsInitialized())
                            {
                                InspectArea.Dispose();
                            }
                            InspectArea = _matchModelAssistant.ModelSearchRegion;

                            ModelRow = _matchModelAssistant.ModelPose[0];
                            ModelCol = _matchModelAssistant.ModelPose[1];
                            ModelAgl = _matchModelAssistant.ModelPose[2];
                        }
                    }
                    else
                    {
                        ErrorMessage = IsChinese ? "模板匹配助手为空!" : "Match model assistant is null !";
                    }
                }
                else
                {
                    ErrorMessage = IsChinese ? "定位参数文件路径异常!" : "No file path for location is valid !";
                }
            }
            catch (HalconDotNet.HalconException hex) { ErrorMessage = hex.Message; }
            catch (System.Exception ex) { ErrorMessage = ex.Message; }
            finally { }
            return(rt);
        }
Exemplo n.º 16
0
 private void OnCameraImageGrabbed(ProCommon.Communal.Camera cam, HalconDotNet.HObject hoImage)
 {
     if (hoImage != null &&
         hoImage.IsInitialized())
     {
         if (HoImage != null &&
             HoImage.IsInitialized())
         {
             HoImage.Dispose();
         }
         HoImage = hoImage;
         if (ImageGrabbedEvt != null)
         {
             ImageGrabbedEvt(cam, HoImage);
         }
     }
 }
Exemplo n.º 17
0
        public override void Draw(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject xldCross = new HalconDotNet.HObject();
            xldCross.Dispose();
            HalconDotNet.HOperatorSet.GenCrossContourXld(out xldCross, new HalconDotNet.HTuple(_locateRow), new HalconDotNet.HTuple(_locateCol), 9999, 0);
            HalconDotNet.HOperatorSet.DispObj(xldCross, hwndHandle);

            HalconDotNet.HObject rec1 = new HalconDotNet.HObject();
            rec1.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec1,
                                                    new HalconDotNet.HTuple(_locateRow),
                                                    new HalconDotNet.HTuple(_locateCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec1, hwndHandle);
        }
Exemplo n.º 18
0
        private void DetermineArrowHandle()
        {
            double lth, dr, dc, halfHW;
            double rrow, ccol, rowP1, colP1, rowP2, colP2;
            double headlth = 15, headwth = 15;

            //取线段向量的比例值构成的向量
            rrow = _locateRow + (_extentRow - _locateRow) * 0.8;
            ccol = _locateCol + (_extentCol - _locateCol) * 0.8;

            lth = HalconDotNet.HMisc.DistancePp(rrow, ccol, _extentRow, _extentCol);
            if (lth == 0)
            {
                lth = -1;
            }
            dr     = (_extentRow - rrow) / lth;
            dc     = (_extentCol - ccol) / lth;
            halfHW = headwth / 2.0;

            rowP1 = rrow + (lth - headlth) * dr + halfHW * dc;
            colP1 = ccol + (lth - headlth) * dc - halfHW * dr;

            rowP2 = rrow + (lth - headlth) * dr - halfHW * dc;
            colP2 = ccol + (lth - headlth) * dc + halfHW * dr;

            if (_arrowHandle != null &&
                _arrowHandle.IsInitialized())
            {
                _arrowHandle.Dispose();
            }

            if (lth == -1)
            {
                //产生点
                HalconDotNet.HOperatorSet.GenContourPolygonXld(out _arrowHandle, new HalconDotNet.HTuple(rrow), new HalconDotNet.HTuple(ccol));
            }
            else
            {
                //产生箭头
                HalconDotNet.HOperatorSet.GenContourPolygonXld(out _arrowHandle,
                                                               new HalconDotNet.HTuple(new double[] { rrow, _extentRow, rowP1, _extentRow, rowP2 }),
                                                               new HalconDotNet.HTuple(new double[] { ccol, _extentCol, colP1, _extentCol, colP2 }));
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Clears all variables managing ROI objects
        /// 删除ROI列表
        /// </summary>
        public void Reset()
        {
            ROIList.Clear();
            ResetInstantROI();
            if (_syntheticalRegion != null &&
                _syntheticalRegion.IsInitialized())
            {
                _syntheticalRegion.Dispose();
            }
            _syntheticalRegion = null;

            if (_nonUnionPositiveRegion != null &&
                _nonUnionPositiveRegion.IsInitialized())
            {
                _nonUnionPositiveRegion.Dispose();
            }
            _nonUnionPositiveRegion = null;

            IconicUpdatedDel(EVENT_DELETED_ALL_ROIS);
        }
Exemplo n.º 20
0
        public override HalconDotNet.HObject GetModelRegion()
        {
            if (_circularArc != null &&
                _circularArc.IsInitialized())
            {
                _circularArc.Dispose();
            }

            HalconDotNet.HOperatorSet.GenCircleContourXld(out _circularArc,
                                                          new HalconDotNet.HTuple(_locateRow),
                                                          new HalconDotNet.HTuple(_locateCol),
                                                          new HalconDotNet.HTuple(_radius),
                                                          new HalconDotNet.HTuple(_startPhi),
                                                          new HalconDotNet.HTuple(_startPhi + _extentPhi),
                                                          new HalconDotNet.HTuple(_circularArcDir),
                                                          new HalconDotNet.HTuple(1.0));
            HalconDotNet.HObject rg = new HalconDotNet.HObject();
            rg.Dispose();
            HalconDotNet.HOperatorSet.GenRegionContourXld(_circularArc, out rg, "margin");
            return(rg);
        }
Exemplo n.º 21
0
        public override void Draw(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject rgInternal = new HalconDotNet.HObject();
            rgInternal.Dispose();
            HalconDotNet.HOperatorSet.GenCircle(out rgInternal, new HalconDotNet.HTuple(_locateRow), new HalconDotNet.HTuple(_locateCol), new HalconDotNet.HTuple(_radiusInternal));
            HalconDotNet.HOperatorSet.DispObj(rgInternal, hwndHandle);

            HalconDotNet.HObject rgExternal = new HalconDotNet.HObject();
            rgExternal.Dispose();
            HalconDotNet.HOperatorSet.GenCircle(out rgExternal, new HalconDotNet.HTuple(_locateRow), new HalconDotNet.HTuple(_locateCol), new HalconDotNet.HTuple(_radiusExternal));
            HalconDotNet.HOperatorSet.DispObj(rgExternal, hwndHandle);

            HalconDotNet.HObject rec1 = new HalconDotNet.HObject(), rec2 = new HalconDotNet.HObject(), rec3 = new HalconDotNet.HObject();
            rec1.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec1,
                                                    new HalconDotNet.HTuple(_locateRow),
                                                    new HalconDotNet.HTuple(_locateCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec1, hwndHandle);

            rec2.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec2,
                                                    new HalconDotNet.HTuple(_sizeRowInternal),
                                                    new HalconDotNet.HTuple(_sizeColInternal),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec2, hwndHandle);

            rec3.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec3,
                                                    new HalconDotNet.HTuple(_sizeRowExternal),
                                                    new HalconDotNet.HTuple(_sizeColExternal),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec3, hwndHandle);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Releases the memory for all iconic HALCON objects contained in
        /// this instance.
        /// 释放包含在该类中的图形对象
        /// </summary>
        public void Clear()
        {
            _hImage.Dispose();
            _caltabRegion.Dispose();

            if (_caltabRegion != null &&
                _caltabRegion.IsInitialized())
            {
                _caltabRegion.Dispose();
            }

            if (_markCenterXLD != null &&
                _markCenterXLD.IsInitialized())
            {
                _markCenterXLD.Dispose();
            }

            if (_estimatedWorldCoordinateSystem != null &&
                _estimatedWorldCoordinateSystem.IsInitialized())
            {
                _estimatedWorldCoordinateSystem.Dispose();
            }
        }
Exemplo n.º 23
0
        protected void LoadImage()
        {
            bool isChs = LanguageVersion == ProVision.Communal.Language.Chinese;

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            string filter = isChs ? "图像文件" : "Image Files";

            ofd.Filter = filter + "(*.BMP,*.JPG,*.JPEG,*.TIF)|*.bmp;*.jpg;*.jpeg;*.tif";
            string title = isChs ? "请选择一张图像文件" : "Select an image file";

            ofd.FilterIndex = 0;
            ofd.Title       = title;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (_hoImage != null &&
                        _hoImage.IsInitialized())
                    {
                        _hoImage.Dispose();
                    }

                    HalconDotNet.HOperatorSet.ReadImage(out _hoImage, ofd.FileName);
                    _HwndCtrller.AddHobjEntity(_hoImage);
                    _HwndCtrller.Repaint();//ROI--加载图像,重新渲染图形
                }
                catch (HalconDotNet.HalconException hex)
                {
                    string txt     = isChs ? "加载图像失败!\r\n" : "Load image failed !\r\n";
                    string caption = isChs ? "错误信息" : "Error message";
                    ProVision.Communal.FrmMsgBox.Show(txt + hex.GetErrorMessage(), caption, isChs);
                }
            }
        }
Exemplo n.º 24
0
        protected override bool DoSoftTriggerOnce()
        {
            bool rt = false;

            try
            {
                if (!AcqHandle.TupleEqual(new HalconDotNet.HTuple()))
                {
                    if (!_imgData.IsInitialized())
                    {
                        _imgData = new HalconDotNet.HObject();
                    }

                    _imgData.Dispose();
                    HalconDotNet.HOperatorSet.GrabImageAsync(out _imgData, AcqHandle, GrabTimeOut);

                    if (_imgData != null)
                    {
                        //触发图像采集完成事件
                        OnImgDataOut();
                        rt = true;
                    }
                }
            }
            catch (HalconDotNet.HalconException hex)
            {
                if (DriverExceptionDel != null)
                {
                    DriverExceptionDel(string.Format("错误:Halcon模拟相机异步抓取失败!\n错误代码:{0}", hex.GetErrorCode()));
                }
            }
            finally
            {
            }
            return(rt);
        }
Exemplo n.º 25
0
        private void ModifyRegion()
        {
            bool   isChs   = LanguageVersion == ProCommon.Communal.Language.Chinese;
            string txt     = isChs ? "修改区域异常!" : "Error occured when modify region!";
            string caption = isChs ? "警告信息" : "Warning Message";

            HalconDotNet.HTuple  mr, mc, mbtntype;
            HalconDotNet.HObject tmpModify = null;
            HalconDotNet.HObject tmpKeep = null, tmpSelect = null;

            HalconDotNet.HOperatorSet.GenEmptyObj(out tmpKeep);
            HalconDotNet.HOperatorSet.GenEmptyObj(out tmpSelect);

            int cnt = 0;

            this.hwndcDisplay.Focus();
            UpdateRegionForDisplay();

            while (_isModifying)
            {
                try
                {
                    HalconDotNet.HOperatorSet.GetMposition(this.hwndcDisplay.HalconWindow, out mr, out mc, out mbtntype);

                    if (_hoBrushRegion != null &&
                        _hoBrushRegion.IsInitialized())
                    {
                        _hoBrushRegion.Dispose();
                    }

                    HalconDotNet.HOperatorSet.GenRectangle1(out _hoBrushRegion, mr - _zoomFactorForBrush, mc - _zoomFactorForBrush, mr + _zoomFactorForBrush, mc + _zoomFactorForBrush);

                    UpdateRegionForDisplay();
                    if (mbtntype.TupleEqual(new HalconDotNet.HTuple(1))) //按下鼠标左键
                    {
                        HalconDotNet.HOperatorSet.Difference(_hoSelectedRegion, _hoBrushRegion, out tmpModify);

                        _hoSelectedRegion.Dispose();
                        _hoSelectedRegion = tmpModify;

                        //若初始区域为数组型
                        cnt = _hoModifiedRegion.CountObj();

                        for (int i = 0; i < cnt; i++)
                        {
                            tmpSelect.Dispose();

                            //未选择的区域,不修改,需要保留
                            if (i != this.lstbRegion.SelectedIndex)
                            {
                                HalconDotNet.HOperatorSet.SelectObj(_hoModifiedRegion, out tmpSelect, i + 1);
                            }
                            //选择的区域,更新为上述修改后的区域
                            else
                            {
                                HalconDotNet.HOperatorSet.CopyObj(_hoSelectedRegion, out tmpSelect, 1, 1);
                            }

                            HalconDotNet.HOperatorSet.ConcatObj(tmpKeep, tmpSelect, out tmpKeep);
                        }

                        tmpSelect.Dispose();

                        _hoModifiedRegion.Dispose();
                        _hoModifiedRegion = tmpKeep;

                        HalconDotNet.HOperatorSet.WaitSeconds(0.001);
                    }
                    else if (mbtntype.TupleEqual(new HalconDotNet.HTuple(4))) //按下鼠标右键
                    {
                        _isModifying = false;

                        if (_hoBrushRegion != null &&
                            _hoBrushRegion.IsInitialized())
                        {
                            _hoBrushRegion.Dispose();
                        }

                        //UpdateRegionForDisplay();

                        _isModified = true;
                    }
                }
                catch (HalconDotNet.HalconException hex)
                {
                    //_isModifying = false;
                    //ProCommon.DerivedForm.FrmMsgBox.Show(txt + "\r\n" + hex.Message, caption,
                    //    ProCommon.DerivedForm.MyButtons.OK,
                    //    ProCommon.DerivedForm.MyIcon.Error, isChs);
                }

                //System.Threading.Thread.Sleep(1);
                Application.DoEvents();
            }
        }
Exemplo n.º 26
0
        public override void DisplayActiveHandle(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject rec = new HalconDotNet.HObject();
            rec.Dispose();
            switch (ActiveHandleIdx)
            {
            //齐轴矩形定位中心
            case 0:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_locateRow),
                                                        new HalconDotNet.HTuple(_locateCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //齐轴矩形右上角点
            case 1:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_upLeftRow),
                                                        new HalconDotNet.HTuple(_botRightCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //齐轴矩形左上角点
            case 2:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_upLeftRow),
                                                        new HalconDotNet.HTuple(_upLeftCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //齐轴矩形左下角点
            case 3:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_botRightRow),
                                                        new HalconDotNet.HTuple(_upLeftCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            //齐轴矩形右下角点
            case 4:
            {
                HalconDotNet.HOperatorSet.GenRectangle2(out rec,
                                                        new HalconDotNet.HTuple(_botRightRow),
                                                        new HalconDotNet.HTuple(_botRightCol),
                                                        new HalconDotNet.HTuple(0),
                                                        new HalconDotNet.HTuple(5),
                                                        new HalconDotNet.HTuple(5));
                HalconDotNet.HOperatorSet.DispObj(rec, hwndHandle);
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Determines(or updates) the basic information for this
        /// calibration image, which are the values for the region
        /// plate, the center marks, and the estimated pose.
        /// The flag <c>mPlateStatus</c> describes the evaluation
        /// of the computation process.
        /// If desired the quality assessment can be recalculated
        /// as well.
        /// 计算或更新标定图像的基本信息,包括标定板区域,特征点中心坐标
        /// 以及标定板的评估位置(相机外参).
        /// "标定板状态"标记描述标定计算过程的评估值,若希望获取品质也可以
        /// 重新计算
        /// </summary>
        /// <param name="isUpdateQuality">
        /// Triggers the recalculation of the quality assessment for
        /// this calibration image
        /// 触发重计算标定图像品质任务
        /// </param>
        public void UpdateCaltab(bool isUpdateQuality)
        {
            HalconDotNet.HTuple worldX, worldY;
            HalconDotNet.HTuple unit = new HalconDotNet.HTuple("m");
            bool failed = false;

            ProVision.Calibration.QualityProcedures proc =
                new ProVision.Calibration.QualityProcedures();
            string descriptionFile;

            HalconDotNet.HTuple startCamPara;
            ErrorMessage = "";

            _caltabRegion.Dispose();
            _markCenterXLD.Dispose();
            _estimatedWorldCoordinateSystem.Dispose();

            _markCenterRows = new HalconDotNet.HTuple();
            _markCenterCols = new HalconDotNet.HTuple();

            _plateStatus    = ProVision.Calibration.CalibOnPlateAssistant.PS_NOT_FOUND;
            descriptionFile = _assistant.DescrpFile;
            try
            {
                //注意:FindCaltab算子的控制参数2(从1开始计数),数据类型为整型,非整型则异常(非整型用HTuple封装亦异常)
                HalconDotNet.HOperatorSet.FindCaltab(_hImage, out _caltabRegion,
                                                     descriptionFile,
                                                     _assistant.FilterSize,
                                                     _assistant.MarkThresh,
                                                     _assistant.MarkMinDiameter);

                _plateStatus = ProVision.Calibration.CalibOnPlateAssistant.PS_MARKS_FAILED;

                //--Quality issue measurements,标定图像品质计算
                if (isUpdateQuality)
                {
                    _qualityIssueList.Clear();
                    failed = _assistant.TestQualityIssues(this);
                }

                startCamPara = _assistant.GetCameraParams(this);

                HalconDotNet.HOperatorSet.FindMarksAndPose(_hImage, _caltabRegion, descriptionFile, startCamPara,
                                                           _assistant.StartThresh, _assistant.DeltaThresh, _assistant.MinThresh, _assistant.Alpha,
                                                           _assistant.MinContLength, _assistant.MarkMaxDiameter, out _markCenterRows,
                                                           out _markCenterCols, out _plateEstimatedPose);

                HalconDotNet.HOperatorSet.GenCrossContourXld(out _markCenterXLD, _markCenterRows, _markCenterCols,
                                                             new HalconDotNet.HTuple(10), new HalconDotNet.HTuple(0));

                //品质异常:可能无法提取到标定板区域或标志点
                if (failed)
                {
                    _assistant.AddQualityIssue(this, ProVision.Calibration.CalibOnPlateAssistant.QUALITY_ISSUE_FAILURE, 0.0);
                }

                //标定板上特征点的中心像素坐标转换为对应的世界坐标系坐标
                HalconDotNet.HOperatorSet.ImagePointsToWorldPlane(startCamPara, _plateEstimatedPose, _markCenterRows, _markCenterCols, unit,
                                                                  out worldX, out worldY);

                //标定板相邻世界坐标点的点间距(米)
                HalconDotNet.HTuple distance;
                HalconDotNet.HOperatorSet.DistancePp(worldX[0].D, worldY[0].D, worldX[1].D, worldY[1].D, out distance);
                _estimatedPlateSize  = distance.D;
                _estimatedPlateSize *= 10.0;

                proc.Get_3D_Coord_System(_hImage, out _estimatedWorldCoordinateSystem,
                                         startCamPara, _plateEstimatedPose, new HalconDotNet.HTuple(_estimatedPlateSize / 2.0));

                _plateStatus = _qualityIssueList.Count > 0 ? ProVision.Calibration.CalibOnPlateAssistant.PS_QUALITY_ISSUES :
                               ProVision.Calibration.CalibOnPlateAssistant.PS_OK;
                CanCalib = 0; //准备好标定标记:允许当前标定图像加入标定过程
            }
            catch (HalconDotNet.HalconException hex)
            {
                ErrorMessage = hex.Message;
                string str = hex.GetErrorMessage();

                /* if exception was raised due to lack of memory,
                 * forward the error to the calling method
                 * 若由于内存不足抛出异常,则将异常传递给调用者 */
                if (hex.Message.IndexOf("not enough") != -1)
                {
                    throw (hex);
                }
            }
        }
Exemplo n.º 28
0
        public virtual void Do()
        {
            //1.打开光源
            FileLib.Logger.Pop("  打开光源:", false, "运行日志");
            foreach (LightPara item in MyVisionPara.camLightPara.lightPara)
            {
                LightCtrlManager.Instance.SetLightValue(item);
            }
            //2.采图
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
            FileLib.Logger.Pop("  开始采图:", false, "运行日志");
            CameraCtrl.Instance.SetExpos(MyVisionPara.camLightPara.CamName, MyVisionPara.camLightPara.Exposure);
            //10.获取当前的机械坐标
            double X = 0, Y = 0, Z = 0, Theta = 0;

            if (CaliParaManager.Instance.GetCaliMode(MyVisionPara.localPara.localSetting.CoordiCam) == CaliModelEnum.HandEyeCali)
            {
                MotionManager.Instance.SetCoordi(MyVisionPara.localPara.localSetting.TeachCoordi);
                FileLib.Logger.Pop("当前的坐标系为:" + MyVisionPara.localPara.localSetting.TeachCoordi.ToString(), false, "运行日志");
                MotionManager.Instance.GetCoordiPos(out X, out Y, out Z, out Theta);
                FileLib.Logger.Pop("当前的机械坐标", false, "运行日志");
                FileLib.Logger.Pop("X:" + X.ToString("f4") + "  Y:" + Y.ToString("f4") +
                                   "  Z:" + Z.ToString("f4") + "  Theta:" + Theta.ToString("f4"), false, "运行日志");
            }

            if (CameraCtrl.Instance.GrabImg(MyVisionPara.camLightPara.CamName, out GrabImg))
            {
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCameraGrabed, 1); //拍照OK
                FileLib.Logger.Pop("  采图OK:", false, "运行日志");
            }
            else
            {
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCameraGrabed, 2); //拍照NG
                FileLib.Logger.Pop("  采图NG:", false, "运行日志");
            }
            ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);

            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam0)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);
            }
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam1)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
            }
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam3);
            }
            view1.ResetView();
            view1.Refresh();
            view1.AddViewImage(GrabImg);
            view1.Repaint();
            MyVisionBase.SaveImg(GrabImg, "扎针对位图片");
            //3.关闭光源
            LightCtrlManager.Instance.SetAllLightTo0();
            FileLib.Logger.Pop("  关闭光源:", false, "运行日志");
            //4.0设置定位模式
            MyLocal.SetLocalModel(MyVisionPara.localPara.localSetting.localModel);
            //5.0设置定位参数
            MyLocal.SetParam(GrabImg, MyVisionPara.localPara);
            //6.执行定位
            try
            {
                MyLocal.doLocal();
                //7.告诉PLC定位结果完成
                if (MyVisionPara.ProjectVisionItem == ProjectVisionEnum.ProjectVision1)
                {
                    FileLib.Logger.Pop(" 扎针右侧视觉定位完成,先不发给PLC信号,等计算出偏移量后,将信号发给PLC:", false, "运行日志");
                }
                else
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCamLocalResult, 1); //告诉PLC定位结果OK
                    FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果OK):", false, "运行日志");
                }
            }
            catch (Exception e0)
            {
                Logger.PopError1(e0, false, "视觉错误日志");
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCamLocalResult, 2); //告诉PLC定位结果NG
                FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果NG):", false, "运行日志");
                MyLocalResult.IsLocalOk = false;
            }


            MyLocalResult = MyLocal.GetResult();
            view1.AddViewObject(MyLocalResult.ShowContour);
            //结合标定坐标计算出产品的实际位置
            //8.获取标定矩阵
            MyHomMat2D HomMat = new MyHomMat2D();

            HomMat = CaliParaManager.Instance.GetHomMAT(MyVisionPara.localPara.localSetting.CoordiCam); //获取示教的标定矩阵
            FileLib.Logger.Pop("  获取示教的标定矩阵:" + MyVisionPara.localPara.localSetting.CoordiCam.ToString(), false, "运行日志");
            FileLib.Logger.Pop(HomMat.ToString(), false, "运行日志");
            HalconDotNet.HTuple HHomMat = new HalconDotNet.HTuple();
            //标定矩阵的转换
            MyVisionBase.MyHomMatToHalcon(HomMat, out HHomMat);
            //9.图像坐标系的原点由左上角变到左下角
            MyVisionBase.AdjImgRow(GrabImg, ref MyLocalResult.row);
            St_VectorAngle PixelVector = new St_VectorAngle(MyLocalResult.row, MyLocalResult.col, MyLocalResult.angle);

            FileLib.Logger.Pop("当前的像素坐标", false, "运行日志");
            FileLib.Logger.Pop("Col:" + MyLocalResult.col.ToString("f4") + "  Row:" + MyLocalResult.row.ToString("f4") +
                               "  Theta:" + MyLocalResult.angle.ToString("f4"), false, "运行日志");

            CaliValue CaliPara = CaliParaManager.Instance.GetCaliValue(MyVisionPara.localPara.localSetting.CoordiCam);

            VectorAngle GrabPos = new VectorAngle(X, Y, Theta);

            //9 计算出当前产品距离旋转中心的坐标
            EyeToHandPos.TransEyeToHandPos(PixelVector, CaliPara, GrabPos, out PosToRot);
            //10计算出示教产品到旋转中心的坐标
            St_VectorAngle TeachPixelPos = new St_VectorAngle(MyLocalResult.TeachRow, MyLocalResult.TeachCol, MyLocalResult.TeachAngle);
            VectorAngle    TeachGrabPos  = new VectorAngle(MyLocalResult.TeachX, MyLocalResult.TeachY, MyLocalResult.TeachTheta);

            MyVisionBase.AdjImgRow(GrabImg, ref TeachPixelPos.Row);
            EyeToHandPos.TransEyeToHandPos(TeachPixelPos, CaliPara, TeachGrabPos, out TeachPosToRot);
            view1.Repaint();
            view1.SetString(100, 100, "red", "PosToRot: " + "   X: " + PosToRot.Col.ToString("f3") + "   Y: " +
                            PosToRot.Row.ToString("f3") + "   Theta: " + PosToRot.Angle.ToString("f3"));
            MyLocalResult.PosToRot      = PosToRot;
            MyLocalResult.TeachPosToRot = TeachPosToRot;
            FileLib.Logger.Pop("示教的产品相对旋转中心的偏移量", false, "运行日志");

            FileLib.Logger.Pop("PosToRot: " + "   X: " + PosToRot.Col.ToString("f3") + "   Y: " +
                               PosToRot.Row.ToString("f3") + "   Theta: " + PosToRot.Angle.ToString("f3"), false, "运行日志");

            FileLib.Logger.Pop("当前的产品相对旋转中心的偏移量", false, "运行日志");
            FileLib.Logger.Pop("PosToRot: " + "   X: " + TeachPosToRot.Col.ToString("f3") + "   Y: " +
                               TeachPosToRot.Row.ToString("f3") + "   Theta: " + TeachPosToRot.Angle.ToString("f3"), false, "运行日志");
            //11.计算出X Y Theta的补偿量,

            ////图像坐标转到机械坐标系
            //MyVisionBase.AffineTransPt(MyLocalResult.col, MyLocalResult.row, HHomMat, out MyLocalResult.x, out MyLocalResult.y);
            ////
            //MyVisionBase.AffineTransPt(MyLocalResult.TeachCol, MyLocalResult.TeachRow, HHomMat, out MyLocalResult.TeachX, out MyLocalResult.TeachY);
        }
Exemplo n.º 29
0
        public override void Do()
        {
            //1.打开光源
            FileLib.Logger.Pop("  打开光源:", false, "FOF运行日志");
            foreach (LightPara item in MyVisionPara.camLightPara.lightPara)
            {
                LightCtrlManager.Instance.SetLightValue(item);
            }
            //2.采图
            FileLib.Logger.Pop("  开始采图:", false, "FOF运行日志");
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
            if (FilterImg != null)
            {
                FilterImg.Dispose();
            }
            CameraCtrl.Instance.SetExpos(MyVisionPara.camLightPara.CamName, MyVisionPara.camLightPara.Exposure);
            if (CameraCtrl.Instance.GrabImg(MyVisionPara.camLightPara.CamName, out GrabImg))
            {
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_ok, 1); //拍照OK
                }
                FileLib.Logger.Pop("  采图OK:", false, "FOF运行日志");
            }
            else
            {
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_ok, 2); //拍照NG
                }
                FileLib.Logger.Pop("  采图NG:", false, "FOF运行日志");
            }
            ViewControl view1 = new ViewControl();

            view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam3);
            }
            view1.ResetView();
            view1.Refresh();

            //3.关闭光源
            //LightCtrlManager.Instance.SetAllLightTo0();
            //FileLib.Logger.Pop("  关闭光源:", false, "FOF运行日志");

            //4.0设置定位模式
            MyLocal.SetLocalModel(MyVisionPara.localPara.localSetting.localModel);
            //5.0设置定位参数
            FileLib.Logger.Pop("  开始偏移检测:", false, "FOF运行日志");
            MyVisionBase.SaveImg(GrabImg, "FOF偏移检测图片");


            if (MyVisionPara.camLightPara.IsFilter)
            {
                FileLib.Logger.Pop("  开始频域滤波,FilterC:" + MyVisionPara.camLightPara.FilterC.ToString(), false, "FOF运行日志");
                MyVisionBase.FilterImg(GrabImg, out FilterImg, MyVisionPara.camLightPara.FilterC);
                view1.AddViewImage(FilterImg);
                MyVisionBase.SaveImg(FilterImg, "FOF偏移检测图片");
                MyLocal.SetParam(FilterImg, MyVisionPara.localPara);
            }
            else
            {
                view1.AddViewImage(GrabImg);
                MyLocal.SetParam(GrabImg, MyVisionPara.localPara);
            }

            view1.Repaint();
            //6.执行定位
            try
            {
                FileLib.Logger.Pop("  开始定位:", false, "FOF运行日志");
                MyLocal.doLocal();
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_result, 1);
                }
                FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果OK):", false, "FOF运行日志");
            }
            catch (Exception e0)
            {
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_result, 2);
                }
                Logger.PopError1(e0, false, "视觉错误日志");
                FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果NG):", false, "FOF运行日志");
            }
            MyLocalResult = MyLocal.GetResult();
            view1.AddViewObject(MyLocalResult.ShowContour);
            view1.Repaint();
            //8.结合标定坐标计算出产品的实际位置
            MyHomMat2D HomMat = new MyHomMat2D();

            HomMat = CaliParaManager.Instance.GetHomMAT(MyVisionPara.localPara.localSetting.CoordiCam); //获取示教的标定矩阵
            FileLib.Logger.Pop("  获取标定矩阵(CoordiEnumItem):" + MyVisionPara.localPara.localSetting.CoordiCam.ToString()
                               , false, "FOF运行日志");
            FileLib.Logger.Pop(HomMat.ToString(), false, "FOF运行日志");
            HalconDotNet.HTuple HHomMat = new HalconDotNet.HTuple();
            //9.标定矩阵的转换
            MyVisionBase.MyHomMatToHalcon(HomMat, out HHomMat);
            //10.图像坐标系的原点由左上角变到左下角
            MyVisionBase.AdjImgRow(GrabImg, ref MyLocalResult.row);
            MyVisionBase.AffineTransPt(MyLocalResult.col, MyLocalResult.row, HHomMat, out MyLocalResult.x, out MyLocalResult.y);
            FileLib.Logger.Pop("col: " + MyLocalResult.col.ToString("f3") + " row: " + MyLocalResult.row.ToString("f3"), false, "FOF运行日志");
            FileLib.Logger.Pop("X: " + MyLocalResult.x.ToString("f3") + " Y:   " + MyLocalResult.y.ToString("f3"), false, "FOF运行日志");
            MyLocalResult.Theta = MyLocalResult.angle;
            if (FilterImg != null)
            {
                FilterImg.Dispose();
            }
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
        }
Exemplo n.º 30
0
        private void Bbi_Click(object sender, ItemClickEventArgs e)
        {
            switch (e.Item.Tag.ToString())
            {
            case "BBI_LOADIMAGE":
                LoadImage();
                break;

            case "BBI_LINE":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROILine());     //定义区域时,矢量线段不响应;主要用在定义测量
                    }
                }
                break;

            case "BBI_RECTANGLE1":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROIRectangle1());
                    }
                }
                break;

            case "BBI_RECTANGLE2":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROIRectangle2());
                    }
                }
                break;

            case "BBI_CIRCULARARC":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROICircularArc());     //定义区域时,有向圆弧不响应;主要用在定义测量
                    }
                }
                break;

            case "BBI_CIRCLE":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROICircle());
                    }
                }
                break;

            case "BBI_ANNULUS":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROIAnnulus());
                    }
                }
                break;

            case "BBI_DELETEACTIVEROI":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.RemoveActiveROI();
                    }
                }
                break;

            case "BBI_DELETEALLROI":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _HwndCtrller.ResetAll();
                        _HwndCtrller.Repaint();
                    }
                }
                break;

            case "BBI_RESETWINDOW":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _HwndCtrller.ResetWindow();
                        _HwndCtrller.Repaint();
                    }
                }
                break;

            case "BBI_CLEARICONIC":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _HwndCtrller.ResetAll();

                        if (_hoModifiedRegion != null &&
                            _hoModifiedRegion.IsInitialized())
                        {
                            _hoModifiedRegion.Dispose();
                        }

                        if (_hoSelectedRegion != null &&
                            _hoSelectedRegion.IsInitialized())
                        {
                            _hoSelectedRegion.Dispose();
                        }

                        this.bchkiModifyRegion.Checked = false;
                        this.lstbRegion.Items.Clear();
                        _isUpdated = false;
                    }
                }
                break;

            case "BBI_UPDATEREGION":

                _isUpdated = false;
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    //若非传入区域
                    if (!_isTransmitted)
                    {
                        if (_ROIManager != null)
                        {
                            if (_hoRawRegion != null &&
                                _hoRawRegion.IsInitialized())
                            {
                                _hoRawRegion.Dispose();
                            }
                            HalconDotNet.HOperatorSet.GenEmptyObj(out _hoRawRegion);

                            _roiList = _ROIManager.ROIList;

                            if (_roiList != null &&
                                _roiList.Count > 0)
                            {
                                this.lstbRegion.Items.Clear();
                                string roiType = "";

                                for (int i = 0; i < _roiList.Count; i++)
                                {
                                    HalconDotNet.HOperatorSet.ConcatObj(_hoRawRegion, ((ProVision.InteractiveROI.ROI)_roiList[i]).GetModelRegion(), out _hoRawRegion);
                                    roiType = ((ProVision.InteractiveROI.ROI)_roiList[i]).ROIShape.ToString();
                                    this.lstbRegion.Items.Add(i.ToString("00") + "[" + roiType + "]");
                                }

                                if (_hoModifiedRegion != null &&
                                    _hoModifiedRegion.IsInitialized())
                                {
                                    _hoModifiedRegion.Dispose();
                                }

                                _hoModifiedRegion             = _hoRawRegion.Clone();
                                this.lstbRegion.SelectedIndex = 0;
                                HalconDotNet.HOperatorSet.SelectObj(_hoModifiedRegion, out _hoSelectedRegion, 1);
                                _isUpdated = true;
                            }
                        }
                    }
                    else
                    {
                        //传入区域--作为单一区域
                        this.lstbRegion.Items.Clear();
                        this.lstbRegion.Items.Add("00" + "[Arbitrary]");
                        if (_hoModifiedRegion != null &&
                            _hoModifiedRegion.IsInitialized())
                        {
                            _hoModifiedRegion.Dispose();
                        }

                        //修改区域与选择区域为同一指向
                        HalconDotNet.HOperatorSet.SelectObj(_hoRawRegion, out _hoModifiedRegion, 1);
                        _hoSelectedRegion = _hoModifiedRegion;
                    }
                }
                break;

            default: break;
            }
        }