Example #1
0
 public void UpdateCurrImage(HObject img)
 {
     if (img == null)
     {
         return;
     }
     if (CurrentImage != null)
     {
         CurrentImage.Dispose();
     }
     if (TemplateParam.Scale > 0.09 && TemplateParam.Scale < 2.1)
     {
         HOperatorSet.CopyImage(img, out CurrentImage);
     }
     else
     {
         MessageBox.Show("图像的缩放系数设置错误,请修改Scale参数");
         HOperatorSet.CopyImage(img, out CurrentImage);
         TemplateParam       = new St_TemplateParam(true);
         TemplateParam.Scale = 1.0;
     }
     if (CurrentImage == null || !CurrentImage.IsInitialized())
     {
         MessageBox.Show("请先加载一张图片");
         return;
     }
     InitUI();
 }
Example #2
0
        public bool Read(string Path)
        {
            bool IsOk = true;
            // BasePath = System.IO.Directory.GetCurrentDirectory();
            string path = Path + ConfigName + @"\";

            this.localSetting = XML <LocalSettingPara> .Read(path + "LocalSetting.xml");

            this.Template = XML <St_TemplateParam> .Read(path + "Template.xml");

            this.Lines = XML <St_LinesParam> .Read(path + "Lines.xml");

            this.Circles = XML <St_CirclesParam> .Read(path + "Circles.xml");

            this.Blobs = XML <St_BlobLocalParam> .Read(path + "Blobs.xml");

            this.LineCirRectInspParam = XML <St_InspectImageSetting> .Read(path + "LineCirRectInspParam.xml");

            if (localSetting == null)
            {
                return(true);
            }
            if (localSetting.localModel.ToString().Contains("Temp"))
            {
                Template.Load(path);
            }
            return(IsOk);
        }
Example #3
0
File: TempLocal.cs Project: Gz1d/Gz
        public override bool doLocal()
        {
            NowResult = new LocalResult();
            //1.0模板匹配
            St_TemplateParam TemplateParam = NowVisionPara.Template;
            RectangleF       roi           = new RectangleF();
            LocalSettingPara Setting       = NowVisionPara.localSetting;

            roi.X      = Setting.SearchAreaX;
            roi.Y      = Setting.SearchAreaY;
            roi.Width  = Setting.SearchWidth;
            roi.Height = Setting.SearchHeight;
            MatchingResult result;

            try{
                NowResult.IsLocalOk = TemplateParam.FindSharpTemplate(NowImg, roi, TemplateParam, out result);
                NowResult.row       = result.mRow;
                NowResult.col       = result.mCol;
                NowResult.angle     = result.mAngle;
                //NowResult.ShowContour = result.mContour;
                NowResult.ShowContour = result.getDetectionResults();
                return(true);
            }
            catch
            { return(false); }
        }
Example #4
0
 public LocalPara()
 {
     localSetting = new LocalSettingPara();
     Template     = new St_TemplateParam(true);
     Lines        = new St_LinesParam(4);
     Circles      = new St_CirclesParam(2);
     Blobs        = new St_BlobLocalParam(2);
 }
Example #5
0
 public SubFrmTemplate(St_TemplateParam param, LocalSettingPara setting, ViewControl viewIn, HObject srcImage, Action <bool> drawRoiInHWindow)
 {
     InitializeComponent();
     TemplateParam = param;
     Setting       = setting;
     view1         = viewIn;
     //ShowWindow.HMouseMove += HMouseMove;
     if (CurrentImage != null)
     {
         CurrentImage.Dispose();
     }
     ActionIsDrawingRoi = drawRoiInHWindow;
 }
Example #6
0
        public bool FindSharpTemplate(HObject srcImg, RectangleF searchArea, St_TemplateParam currParm, out MatchingResult result)
        {
            result = new MatchingResult();

            // if (!IsLoadOK) return false;

            Matching.InitMatchingParam(currParm);

            if (!Matching.FindShapeModel(srcImg, searchArea, out result))
            {
                Logger.PopError("查找模板失败!");
                return(false);
            }
            return(true);
        }
Example #7
0
        private void FindLineBtn_Click(object sender, EventArgs e)
        {
            txtFindTime.Clear();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            if (GrabedImg == null)
            {
                Logger.PopError("请先采集图片!", true);
                return;
            }

            //1.0模板匹配
            St_TemplateParam TemplateParam = VisionPara0.localPara.Template;
            RectangleF       roi           = new RectangleF();
            LocalSettingPara Setting       = VisionPara0.localPara.localSetting;

            roi.X      = Setting.SearchAreaX;
            roi.Y      = Setting.SearchAreaY;
            roi.Width  = Setting.SearchWidth;
            roi.Height = Setting.SearchHeight;
            MatchingResult result;

            TemplateParam.FindSharpTemplate(GrabedImg, roi, TemplateParam, out result);
            //2.0调整图像位置
            St_VectorAngle VectorAngle0 = new St_VectorAngle(VisionPara0.localPara.Template.CenterY,
                                                             VisionPara0.localPara.Template.CenterX, VisionPara0.localPara.Template.TemplateAngle);
            St_VectorAngle TempFindVectorAngle = new St_VectorAngle(result.mRow, result.mCol, result.mAngle);//找到的模板坐标
            HTuple         HomMat = new HTuple();

            HOperatorSet.VectorAngleToRigid(result.mRow, result.mCol, result.mAngle, VisionPara0.localPara.Template.CenterY,
                                            VisionPara0.localPara.Template.CenterX, VisionPara0.localPara.Template.TemplateAngle, out HomMat);
            HObject AffineImg = new HObject();

            HOperatorSet.AffineTransImage(GrabedImg, out AffineImg, HomMat, "constant", "false");

            HOperatorSet.ClearWindow(ShowWindow);
            MyVisionBase.hDispObj(ShowWindow, GrabedImg);

            //3.0找出Pin针坐标
            HObject RoiContour = new HObject();

            MyVisionBase.hDispObj(ShowWindow, AffineImg);
            HTuple PinRows = new HTuple(), PinCols = new HTuple();

            PinInsepct.FindPinPos(TeachInspectPinParam, AffineImg, out PinRows, out PinCols);
            HObject ShowContour = new HObject();

            HOperatorSet.GenCrossContourXld(out ShowContour, PinRows, PinCols, 50, 0);
            MyVisionBase.hSetColor(ShowWindow, "red");
            MyVisionBase.hDispObj(ShowWindow, ShowContour);
            //4.0 计算出Pin针偏移量
            HTuple OffSetRows = new HTuple(), OffSetCols = new HTuple(), OffSetDists = new HTuple();;

            PinInsepct.CalculatePinOffset(TeachInspectPinParam, PinRows, PinCols, out OffSetRows, out OffSetCols, out OffSetDists);
            HTuple Max      = OffSetDists.TupleMax();
            HTuple MaxIndex = OffSetDists.TupleFind(Max);

            HOperatorSet.GenCircleContourXld(out ShowContour, PinRows[MaxIndex[0].I], PinCols[MaxIndex[0].I], 50, 0,
                                             Math.PI * 2, "positive", 1.0);
            MyVisionBase.hSetColor(ShowWindow, "red");
            MyVisionBase.hDispObj(ShowWindow, ShowContour);
            txtFindTime.Text = sw.ElapsedMilliseconds.ToString();
        }