Beispiel #1
0
        public static void UpdateRelativeCoordinate(this PartSearchingDefinition def,
                                                    IRelativeCoordinate relativeCoordinate)
        {
            var p1 = def.RoiRelativeLine.GetPoint1();
            var p2 = def.RoiRelativeLine.GetPoint2();

            var actualP1 = relativeCoordinate.GetOriginalPoint(p1);
            var actualP2 = relativeCoordinate.GetOriginalPoint(p2);

            var roiLine = new Line {
                X1 = actualP1.X, Y1 = actualP1.Y, X2 = actualP2.X, Y2 = actualP2.Y
            };

            def.RoiLine = roiLine;

            //
            var p1a = def.AreaRelativeLine.GetPoint1();
            var p2b = def.AreaRelativeLine.GetPoint2();

            var actualP1a = relativeCoordinate.GetOriginalPoint(p1a);
            var actualP2b = relativeCoordinate.GetOriginalPoint(p2b);

            var areaLine = new Line {
                X1 = actualP1a.X, Y1 = actualP1a.Y, X2 = actualP2b.X, Y2 = actualP2b.Y
            };

            def.AreaLine = areaLine;
        }
Beispiel #2
0
//        public IList<PartSearchingResult> SearchParts(HImage image, IList<PartSearchingDefinition> definitions)
        public PartSearchingResult SearchPart(HImage image, PartSearchingDefinition definition)
        {
            var swSearchPart = new NotifyStopwatch("SearchPart: " + definition.Name);

            int     offsetX = 0;
            int     offsetY = 0;
            HRegion domain;

            var result = new PartSearchingResult()
            {
                Definition = definition.DeepClone(),
            };

            var reducedImage = HDevelopExport.Singletone.ChangeDomainForRectangle(
                image,
                line: definition.RoiLine,
                halfWidth: definition.RoiHalfWidth,
                margin: 0.5);

            if (definition.Domain_SaveCacheImageEnabled)
            {
                reducedImage.CropDomain()
                .ToBitmapSource()
                .SaveToTiff(_cacheImageDir + "\\PartInspector_" + definition.Name + "_1_Domain.tif");
            }

            domain = reducedImage.GetDomain();

            offsetX = domain.GetColumn1();
            offsetY = domain.GetRow1();
            var croppedImage = reducedImage.CropDomain();


            var region = definition.PartExtractor.Extract(croppedImage);

            var countObj = region.CountObj();

            if (countObj == 0)
            {
            }
            else
            {
                var movedRegion = region.MoveRegion(offsetY, offsetX);

                var rect2 = movedRegion.GetSmallestHRectangle2();
                var line  = rect2.GetRoiLineFromRectangle2Phi();
                result.PartLine      = line;
                result.PartHalfWidth = rect2.Length2;
                result.PartRegion    = movedRegion;
            }
            swSearchPart.Dispose();
            return(result);
        }