コード例 #1
0
        public ICModelParameter DrawRectangle1()
        {
            double hv_Row1, hv_Column1, hv_Row2, hv_Column2;

            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("margin");
            windowHandle.SetColor("red");
            windowHandle.DrawRectangle1(out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);

            HObject ho_Rectangle;

            HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2, hv_Column2);

            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("margin");
            windowHandle.SetColor("blue");
            windowHandle.DispObj(ho_Rectangle);


            var icmodel = new ICModelParameter()
            {
                Row1  = hv_Row1, Column1 = hv_Column1, Row2 = hv_Row2, Column2 = hv_Column2,
                Label = string.Format("IC_{0}", CountOfICs++),
            };

            this.ModelICs.Add(icmodel);
            return(icmodel);
        }
コード例 #2
0
        private bool CompareICs(ICModelParameter detectedIc, ICModelParameter icmodel)
        {
            if (icmodel.InvalidIC)
            {
                bool result = false;
                if (detectedIc.InvalidIC)
                {
                    if (Math.Abs(icmodel.CenterRowIC - detectedIc.CenterRowIC) < 20)
                    {
                        if (Math.Abs(icmodel.CenterColIC - detectedIc.CenterColIC) < 20)
                        {
                            if (icmodel.AreaIC * 0.7 <= detectedIc.AreaIC && icmodel.AreaIC * 1.3 >= detectedIc.AreaIC)
                            {
                                result = true;
                            }
                        }
                    }
                }
                else
                {
                    result = false;
                }

                windowHandle.SetColor(result ? "green" : "red");

                windowHandle.DispRectangle1(icmodel.Row1, icmodel.Column1, icmodel.Row2, icmodel.Column2);

                windowHandle.SetTposition((int)icmodel.CenterRowIC, (int)icmodel.CenterColIC);

                windowHandle.WriteString(result ? "OK" : "NG");

                return(result);
            }
            return(true);
        }
コード例 #3
0
        public bool CopyProcessParam(ref ICModelParameter detectedIC)
        {
            detectedIC.Row1    = this.Row1;
            detectedIC.Column1 = this.Column1;
            detectedIC.Row2    = this.Row2;
            detectedIC.Column2 = this.Column2;

            detectedIC.MinGray = this.MinGray;
            detectedIC.MaxGray = this.MaxGray;

            detectedIC.MinArea = this.MinArea;
            detectedIC.MaxArea = this.MaxArea;

            return(true);
        }
コード例 #4
0
        public bool ThresholdOneIC(ICModelParameter icModel)
        {
            windowHandle.ClearWindow();
            windowHandle.DispObj(ho_Image);

            HObject ho_Rectangle, ho_ImageRegion;
            HObject ho_Regions, ho_ConnectedRegions, ho_RegionFillUp;
            HObject ho_SelectedRegions;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageRegion);
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);

            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle1(out ho_Rectangle, icModel.Row1, icModel.Column1, icModel.Row2, icModel.Column2);
            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("margin");
            windowHandle.SetColor("blue");
            windowHandle.DispObj(ho_Rectangle);

            ho_ImageRegion.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageRegion);

            ho_Regions.Dispose();
            HOperatorSet.Threshold(ho_ImageRegion, out ho_Regions, icModel.MinGray, icModel.MaxGray);

            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("fill");
            windowHandle.SetColor("red");
            windowHandle.DispObj(ho_Regions);

            ho_Rectangle.Dispose();
            ho_ImageRegion.Dispose();
            ho_Regions.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_RegionFillUp.Dispose();
            ho_SelectedRegions.Dispose();

            return(true);
        }
コード例 #5
0
 public bool LoadICModels()
 {
     try
     {
         XDocument doc = XDocument.Load(this.ICModelsFilePath);
         if (doc.Root != null && doc.Root.Elements("ICModel") != null && doc.Root.Elements("ICModel").Count() > 0)
         {
             this.ModelICs.Clear();
             foreach (var icmodelElement in doc.Root.Elements("ICModel"))
             {
                 var icmodel = new ICModelParameter();
                 icmodel.FromXElement(icmodelElement);
                 this.ModelICs.Add(icmodel);
             }
             this.CountOfICs = this.ModelICs.Count();
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
コード例 #6
0
        public bool Detect()
        {
            bool result = true;
            //if (this.LoadICModels())
            //{
            int icCount     = this.ModelICs.Count;
            var detectedICs = new List <ICModelParameter>();

            for (int i = 0; i < icCount; i++)
            {
                var icmodel = this.ModelICs[i];

                var detectedIc = new ICModelParameter();
                icmodel.CopyProcessParam(ref detectedIc);

                this.ProcessOneIC(detectedIc);

                detectedICs.Add(detectedIc);

                result = this.CompareICs(detectedIc, icmodel) ? result : false;
            }

            windowHandle.ClearWindow();
            windowHandle.SetDraw("margin");
            windowHandle.DispObj(ho_Image);

            for (int i = 0; i < icCount; i++)
            {
                var icmodel = this.ModelICs[i];

                var detectedIc = detectedICs[i];

                result = this.CompareICs(detectedIc, icmodel) ? result : false;
            }
            //}
            return(result);
        }
コード例 #7
0
        public bool ProcessConnectionROI(ICModelParameter icModel, out string regionInfo)
        {
            regionInfo = string.Empty;

            windowHandle.ClearWindow();
            windowHandle.DispObj(ho_Image);

            HObject ho_Rectangle, ho_ImageRegion;
            HObject ho_Regions, ho_ConnectedRegions, ho_RegionFillUp;
            HObject ho_SelectedRegions;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageRegion);
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);

            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle1(out ho_Rectangle, icModel.Row1, icModel.Column1, icModel.Row2, icModel.Column2);
            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("margin");
            windowHandle.SetColor("blue");
            windowHandle.DispObj(ho_Rectangle);

            ho_ImageRegion.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageRegion);

            ho_Regions.Dispose();
            HOperatorSet.Threshold(ho_ImageRegion, out ho_Regions, icModel.MinGray, icModel.MaxGray);

            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);

            ho_RegionFillUp.Dispose();
            HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp);

            HTuple areas, rows, cols;

            HOperatorSet.AreaCenter(ho_RegionFillUp, out areas, out rows, out cols);

            double maxAres     = 0;
            int    regionCount = (int)((new HTuple(areas.TupleLength())));

            for (int index = 0; index < regionCount - 1; index++)
            {
                double area = areas.TupleSelect(index);
                if (maxAres < area)
                {
                    maxAres = area;
                }
            }

            regionInfo = string.Format("最大区域面积为{0}", maxAres);

            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("fill");
            windowHandle.SetColor("red");
            windowHandle.DispObj(ho_RegionFillUp);

            ho_Rectangle.Dispose();
            ho_ImageRegion.Dispose();
            ho_Regions.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_RegionFillUp.Dispose();
            ho_SelectedRegions.Dispose();

            return(true);
        }
コード例 #8
0
        public bool ProcessOneIC(ICModelParameter icModel)
        {
            windowHandle.ClearWindow();
            windowHandle.DispObj(ho_Image);

            HObject ho_Rectangle, ho_ImageRegion;
            HObject ho_Regions, ho_ConnectedRegions, ho_RegionFillUp;
            HObject ho_SelectedRegions;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageRegion);
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);

            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle1(out ho_Rectangle, icModel.Row1, icModel.Column1, icModel.Row2, icModel.Column2);
            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("margin");
            windowHandle.SetColor("blue");
            windowHandle.DispObj(ho_Rectangle);

            ho_ImageRegion.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageRegion);

            ho_Regions.Dispose();
            HOperatorSet.Threshold(ho_ImageRegion, out ho_Regions, icModel.MinGray, icModel.MaxGray);


            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);

            ho_RegionFillUp.Dispose();
            HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp);

            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions, "area", "and", icModel.MinArea, icModel.MaxArea);

            HTuple regionCount;

            HOperatorSet.CountObj(ho_SelectedRegions, out regionCount);


            if (regionCount.I == 1)
            {
                HTuple icArea;
                HTuple icCentRow;
                HTuple icCentCol;
                HOperatorSet.AreaCenter(ho_SelectedRegions, out icArea, out icCentRow, out icCentCol);

                icModel.AreaIC      = icArea.D;
                icModel.CenterRowIC = icCentRow.D;
                icModel.CenterColIC = icCentCol.D;
                icModel.InvalidIC   = true;
            }
            else
            {
                icModel.InvalidIC = false;
            }

            windowHandle.SetLineWidth(3);
            windowHandle.SetDraw("fill");
            windowHandle.SetColor("red");
            windowHandle.DispObj(ho_SelectedRegions);

            ho_Rectangle.Dispose();
            ho_ImageRegion.Dispose();
            ho_Regions.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_RegionFillUp.Dispose();
            ho_SelectedRegions.Dispose();

            return(true);
        }