Exemplo n.º 1
0
        /// <summary>
        /// Finds gasket on image and computes its local coordinate system
        /// </summary>
        /// <param name="gasketImage">Image with gasket</param>
        /// <returns>Gasket local coordinate system</returns>
        private static CoordinateSystem2D GetGasketLocalCoordinateSystem(Image gasketImage)
        {
            var localSystem = CoordinateSystem2D.Default;

            using (var searchRegion = new Region())
            {
                AVL.CreateBoxRegion(new Box(17, 145, 126, 213), 656, 492, searchRegion);

                var gasket = AvlNet.Nullable.Create <Object2D>();

                if (edgeModel.HasValue)
                {
                    AVL.LocateSingleObject_Edges(gasketImage,
                                                 searchRegion,
                                                 edgeModel.Value,
                                                 0, 3, 40.0f,
                                                 EdgePolarityMode.MatchStrictly, EdgeNoiseLevel.High,
                                                 false, 0.8f,
                                                 gasket);
                }

                if (gasket.HasValue)
                {
                    localSystem = gasket.Value.Alignment; //mr:: 模板匹配之后,提取匹配项的坐标系
                }
                return(localSystem);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the GasketInspector
        /// </summary>
        /// <param name="templateImage">Image with template gasket</param>
        public static void Init(Image templateImage)
        {
            Box modelBoundingBox;

            AVL.CreateBox(new Location(30, 185), Anchor2D.TopLeft, 100, 125, out modelBoundingBox);

            using (var modelRegion = new Region())
            {
                AVL.CreateBoxRegion(modelBoundingBox, templateImage.Width, templateImage.Height, modelRegion);

                AVL.CreateEdgeModel(templateImage, modelRegion, null, 0, null, 0.0f, 35.0f, 15.0f, 0.0f, 360.0f, 1.0f, 1.0f,
                                    1.0f, 1.0f, 1.0f, edgeModel);
            }

            isInitialized = true;
        }
Exemplo n.º 3
0
        private void GenerateEdgeModel()
        {
            using (var modelRegion = new Region())
                using (var templateImage = new Image())
                {
                    AVL.LoadImage(TemplateImagePath, false, templateImage);

                    Box templateboundingBox;

                    //public static void CreateBox
                    //(
                    //    AvlNet.Location inLocation,
                    //    AvlNet.Anchor2D inLocationAnchor,
                    //    int inWidth,
                    //    int inHeight,
                    //    out AvlNet.Box outBox
                    //)

                    AVL.CreateBox(new Location(360, 330), Anchor2D.TopLeft, 250, 250, out templateboundingBox);

                    //mr:: RegionOfInterest的定义
                    //public class RegionOfInterest : AvlComparableType<avl::RegionOfInterest>
                    //mr:: Region的定义
                    //public class Region : AvlComparableType<avl::Region>

                    //public static void CreateBoxRegion
                    //(
                    //    AvlNet.Box inBox,
                    //    int inFrameWidth,
                    //    int inFrameHeight,
                    //    AvlNet.Region outRegion
                    //)
                    AVL.CreateBoxRegion(templateboundingBox, templateImage.Width, templateImage.Height, modelRegion);


                    //public static void CreateEdgeModel
                    //(
                    //    AvlNet.Image inImage,
                    //    NullableRef<AvlNet.Region> inTemplateRegion,
                    //    AvlNet.Rectangle2D? inReferenceFrame,
                    //    int inMinPyramidLevel,
                    //    int? inMaxPyramidLevel,
                    //    float inSmoothingStdDev,
                    //    float inEdgeThreshold,
                    //    float inEdgeHysteresis,
                    //    float inMinAngle,
                    //    float inMaxAngle,
                    //    float inAnglePrecision,
                    //    float inMinScale,
                    //    float inMaxScale,
                    //    float inScalePrecision,
                    //    float inEdgeCompleteness,
                    //    INullable<AvlNet.EdgeModel> outEdgeModel,
                    //    out AvlNet.Point2D? outEdgeModelPoint,
                    //    INullable<SafeList<AvlNet.Path>> diagEdges,  //mr:: 注意这个类型定义
                    //    INullable<SafeList<AvlNet.Image>> diagEdgePyramid  //mr:: 注意这个类型定义
                    //)

                    //mr:: inTemplateRegion可以是 null, 类型是AvlNet.Region,并不是RegionOfInterest类型
                    AVL.CreateEdgeModel(templateImage,
                                        modelRegion,
                                        null,
                                        0,
                                        null,
                                        0.0f,
                                        60.0f,
                                        40.0f,
                                        -45.0f, 45.0f, 1.0f, 1.0f,
                                        1.0f, 1.0f, 1.0f,
                                        edgeModel); //mr!! 在CreateEdgeModel中这个参数声明中是 INullable<AvlNet.EdgeModel>类型
                    //mr:: 参下面定义
                    //     接口定义这里无需要对T做出限定, 因为接口无法单独生成实例.
                    //public interface INullable<T>
                    //{
                    //    T Value { get; }
                    //    bool HasValue { get; }

                    //    void Reset();
                    //    void Reset(T newValue);
                    //}
                }
        }