Beispiel #1
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);
        }
Beispiel #2
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);
 }
Beispiel #3
0
 public SubFrmBlobLocal(St_BlobLocalParam BlobParaIn, ViewControl viewIn, HObject ImgIn, Action <bool> drawRoiInHWindow)
 {
     InitializeComponent();
     TeachBlobLocaltPara = BlobParaIn;
     view1 = viewIn;
     ActionIsDrawingRoi = drawRoiInHWindow;
     if (ImgIn != null && ImgIn.IsInitialized())
     {
         HOperatorSet.CopyImage(ImgIn, out GrabedImg);
     }
     PixelSizeNumUpDn.Value = (decimal)TeachBlobLocaltPara.PixelSize;
 }
Beispiel #4
0
 public override bool  doLocal()
 {
     try
     {
         BlobLocalRlt      NowResult0  = new BlobLocalRlt();
         St_BlobLocalParam Blobs       = NowVisionPara.Blobs;
         HObject           RoiCont     = new HObject();
         HObject           MinRectCont = new HObject();
         HObject           RegionCont  = new HObject();
         HOperatorSet.GenEmptyObj(out RoiCont);
         HOperatorSet.GenEmptyObj(out MinRectCont);
         HOperatorSet.GenEmptyObj(out RegionCont);
         BlobLocal1(NowImg, Blobs, out ListRow, out ListCol, out ListWid, out ListHei, out ListArea, out RoiCont, out MinRectCont, out RegionCont);
         HOperatorSet.ConcatObj(RoiCont, MinRectCont, out RoiCont);
         HOperatorSet.ConcatObj(RoiCont, RegionCont, out RoiCont);
         HOperatorSet.CopyObj(RoiCont, out NowResult0.ShowContour, 1, -1);
         if (RoiCont != null)
         {
             RoiCont.Dispose();
         }
         if (RegionCont != null)
         {
             RegionCont.Dispose();
         }
         if (MinRectCont != null)
         {
             MinRectCont.Dispose();
         }
         NowResult0.row      = ListRow[0];
         NowResult0.col      = ListCol[0];
         NowResult0.angle    = 0;
         NowResult0.ListRow  = ListRow;
         NowResult0.ListCol  = ListCol;
         NowResult0.ListWid  = ListWid;
         NowResult0.ListHei  = ListHei;
         NowResult0.ListArea = ListArea;
         NowResult           = NowResult0;
         return(true);
     }
     catch { return(false); }
 }
Beispiel #5
0
        public static bool BlobLocal(HObject ImgIn, St_BlobLocalParam BlobParaIn, out List <double> Rows, out List <double> Cols,
                                     out List <double> RectWs, out List <double> RectHs, out List <double> Areas, out HObject RoiContour,
                                     out HObject MinRectContour, out HObject RegionContour)
        {
            Rows           = new List <double>();
            Cols           = new List <double>();
            RectWs         = new List <double>();
            RectHs         = new List <double>();
            Areas          = new List <double>();
            RoiContour     = new HObject();
            MinRectContour = new HObject();
            RegionContour  = new HObject();

            HObject    Roi = new HObject();
            RectangleF NewRectF = new RectangleF(0, 0, 100, 100);
            HObject    ReduceImg = new HObject();
            HObject    ThresholdRegion = new HObject();
            HObject    ConnectRegion = new HObject();
            HObject    SelectRegion = new HObject();
            HTuple     Area = new HTuple(), Row = new HTuple(), Col = new HTuple();
            HTuple     RectRow1 = new HTuple(), RectCol1 = new HTuple(), RectRow2 = new HTuple(), RectCol2 = new HTuple();
            HObject    RectContourI   = new HObject();
            HObject    RegionContourI = new HObject();

            HOperatorSet.GenEmptyObj(out RoiContour);
            HOperatorSet.GenEmptyObj(out RegionContour);
            HOperatorSet.GenEmptyObj(out MinRectContour);


            for (int i = 0; i < BlobParaIn.Count; i++)
            {
                try
                {
                    NewRectF = BlobParaIn.InspectRois[i];
                    HOperatorSet.GenRectangle1(out Roi, NewRectF.Y, NewRectF.X, NewRectF.Y + NewRectF.Height, NewRectF.X + NewRectF.Width);//生成检测区域
                    HOperatorSet.GenContourRegionXld(Roi, out RectContourI, "border");
                    HOperatorSet.ConcatObj(RectContourI, RoiContour, out RoiContour);
                    RectContourI.Dispose();
                    HOperatorSet.ReduceDomain(ImgIn, Roi, out ReduceImg);                                                   //裁剪图像
                    Roi.Dispose();
                    HOperatorSet.Threshold(ReduceImg, out ThresholdRegion, BlobParaIn.MinGrays[i], BlobParaIn.MaxGrays[i]); //阈值分割
                    ReduceImg.Dispose();
                    HOperatorSet.Connection(ThresholdRegion, out ConnectRegion);                                            //区域连接
                    ThresholdRegion.Dispose();
                    HOperatorSet.SelectShape(ConnectRegion, out SelectRegion, "area", "and", BlobParaIn.AreaMins[i], BlobParaIn.AreaMaxs[i]);
                    ConnectRegion.Dispose();
                    HOperatorSet.AreaCenter(SelectRegion, out Area, out Row, out Col);
                    HOperatorSet.GenContourRegionXld(SelectRegion, out RegionContourI, "border");
                    HOperatorSet.ConcatObj(RegionContour, RegionContourI, out RegionContour);
                    RegionContourI.Dispose();
                }
                catch
                { }

                if (Row.Length > 0)
                {
                    Rows.Add(Row.D);
                    Cols.Add(Col.D);
                }
                else
                {
                    Rows.Add(0);
                    Cols.Add(0);
                }
                if (RectCol2.Length > 0)
                {
                    RectWs.Add(RectCol2.D - RectCol1.D);
                    RectHs.Add(RectRow2.D - RectRow1.D);
                }
                else
                {
                    RectWs.Add(0);
                    RectHs.Add(0);
                }
                // HOperatorSet.SmallestRectangle2(SelectRegion,out Row ,out Col,out P)
                HOperatorSet.SmallestRectangle1(SelectRegion, out RectRow1, out RectCol1, out RectRow2, out RectCol2);
                HOperatorSet.GenContourRegionXld(SelectRegion, out RectContourI, "border");
                HOperatorSet.ConcatObj(MinRectContour, RectContourI, out MinRectContour);
                RectContourI.Dispose();
            }
            return(true);
        }
Beispiel #6
0
        private void InitCombox()
        {
            if (TeachBlobLocaltPara.Count == 0)
            {
                TeachBlobLocaltPara = new St_BlobLocalParam(2, true);
            }
            int count = TeachBlobLocaltPara.Count;

            LineSelectComBox.Items.Clear();
            if (count == 1)
            {
                LineSelectComBox.Items.Add("第1个定位区域");
            }
            else if (count == 2)
            {
                LineSelectComBox.Items.Add("第1个定位区域");
                LineSelectComBox.Items.Add("第2个定位区域");
            }
            else if (count == 3)
            {
                LineSelectComBox.Items.Add("第1个定位区域");
                LineSelectComBox.Items.Add("第2个定位区域");
                LineSelectComBox.Items.Add("第3个定位区域");
            }
            else if (count == 4)
            {
                LineSelectComBox.Items.Add("第1个定位区域");
                LineSelectComBox.Items.Add("第2个定位区域");
                LineSelectComBox.Items.Add("第3个定位区域");
                LineSelectComBox.Items.Add("第4个定位区域");
            }
            else if (count == 5)
            {
                LineSelectComBox.Items.Add("第1个定位区域");
                LineSelectComBox.Items.Add("第2个定位区域");
                LineSelectComBox.Items.Add("第3个定位区域");
                LineSelectComBox.Items.Add("第4个定位区域");
                LineSelectComBox.Items.Add("第5个定位区域");
            }
            else if (count == 6)
            {
                LineSelectComBox.Items.Add("第1个检测区域");
                LineSelectComBox.Items.Add("第2个检测区域");
                LineSelectComBox.Items.Add("第3个检测区域");
                LineSelectComBox.Items.Add("第4个检测区域");
                LineSelectComBox.Items.Add("第5个检测区域");
                LineSelectComBox.Items.Add("第6个检测区域");
            }
            else if (count == 7)
            {
                LineSelectComBox.Items.Add("第1个检测区域");
                LineSelectComBox.Items.Add("第2个检测区域");
                LineSelectComBox.Items.Add("第3个检测区域");
                LineSelectComBox.Items.Add("第4个检测区域");
                LineSelectComBox.Items.Add("第5个检测区域");
                LineSelectComBox.Items.Add("第6个检测区域");
                LineSelectComBox.Items.Add("第7个检测区域");
            }
            else if (count == 8)
            {
                LineSelectComBox.Items.Add("第1个检测区域");
                LineSelectComBox.Items.Add("第2个检测区域");
                LineSelectComBox.Items.Add("第3个检测区域");
                LineSelectComBox.Items.Add("第4个检测区域");
                LineSelectComBox.Items.Add("第5个检测区域");
                LineSelectComBox.Items.Add("第6个检测区域");
                LineSelectComBox.Items.Add("第7个检测区域");
                LineSelectComBox.Items.Add("第8个检测区域");
            }
            else
            {
                return;
            }
            LineSelectComBox.SelectedIndex = 0;
        }
Beispiel #7
0
        private void ClearParaBtn_Click(object sender, EventArgs e)
        {
            DialogResult rlt = MessageBox.Show("真的要清除参数?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (rlt != DialogResult.Yes)
            {
                return;
            }
            int initLineCount = 1;

            rlt = MessageBox.Show("即将示教3个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (rlt == DialogResult.Yes)
            {
                initLineCount = 3;
            }
            if (initLineCount != 3)
            {
                rlt = MessageBox.Show("即将示教2个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (rlt == DialogResult.Yes)
                {
                    initLineCount = 2;
                }
                else
                {
                    rlt = MessageBox.Show("即将示教1个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (rlt == DialogResult.Yes)
                    {
                        initLineCount = 1;
                    }
                    else
                    {
                        rlt = MessageBox.Show("即将示教4个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (rlt == DialogResult.Yes)
                        {
                            initLineCount = 4;
                        }
                        else
                        {
                            rlt = MessageBox.Show("即将示教5个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (rlt == DialogResult.Yes)
                            {
                                initLineCount = 5;
                            }
                            else
                            {
                                rlt = MessageBox.Show("即将示教6个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (rlt == DialogResult.Yes)
                                {
                                    initLineCount = 6;
                                }
                                else
                                {
                                    rlt = MessageBox.Show("即将示教7个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                    if (rlt == DialogResult.Yes)
                                    {
                                        initLineCount = 7;
                                    }
                                    else
                                    {
                                        rlt = MessageBox.Show("即将示教8个定位区域?", "区域数量确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                        if (rlt == DialogResult.Yes)
                                        {
                                            initLineCount = 8;
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            TeachBlobLocaltPara = new St_BlobLocalParam(initLineCount);
            InitCombox();
        }