示例#1
0
        public bool Save(string Path)
        {
            bool   Isok = true;
            string path = Path + ConfigName + @"\";

            if (!FileLib.DirectoryEx.Exist(Path + ConfigName))
            {
                FileLib.DirectoryEx.Create(Path + ConfigName);
            }
            if (localSetting == null)
            {
                localSetting = new LocalSettingPara();
            }
            if (localSetting.localModel.ToString().Contains("Temp"))
            {
                Isok = Isok && Template.Save(path);
            }
            Isok = Isok && XML <LocalSettingPara> .Write(this.localSetting, path + "LocalSetting.xml");

            Isok = Isok && XML <St_TemplateParam> .Write(this.Template, path + "Template.xml");

            Isok = Isok && XML <St_LinesParam> .Write(this.Lines, path + "Lines.xml");

            Isok = Isok && XML <St_CirclesParam> .Write(this.Circles, path + "Circles.xml");

            Isok = Isok && XML <St_BlobLocalParam> .Write(this.Blobs, path + "Blobs.xml");

            Isok = Isok && XML <St_InspectImageSetting> .Write(this.LineCirRectInspParam, path + "LineCirRectInspParam.xml");

            return(Isok);
        }
示例#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);
        }
示例#3
0
文件: TempLocal.cs 项目: 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); }
        }
示例#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);
 }
示例#5
0
        public bool ClearNullObj()
        {
            if (localSetting == null)
            {
                localSetting = new LocalSettingPara();
            }

            return(true);
        }
示例#6
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;
 }
示例#7
0
 public void UpdateSetting(LocalSettingPara setting)
 {
     Setting = setting;
 }
示例#8
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();
        }