コード例 #1
0
        /// <summary>
        /// Performs cap inspection and draws results
        /// </summary>
        /// <param name="inputImage">Image with bottle. Inspection results will be drawn on it.</param>
        public void DoInspection(Image inputImage)
        {
            var localSystem = GetBottleCoordinateSystem(inputImage);

            var defects = new List <Edge1D>();

            foreach (var scanSegment in scanSegments)
            {
                using (var currentMap = new ScanMap())
                {
                    Edge1D?edge = null;

                    AVL.CreateScanMap(format,
                                      new Path(scanSegment),
                                      localSystem,
                                      70,
                                      InterpolationMethod.Bilinear,
                                      currentMap);

                    AVL.ScanSingleEdge(inputImage,
                                       currentMap,
                                       scanParams,
                                       Selection.Best,
                                       null,
                                       out edge);

                    if (edge.HasValue)
                    {
                        defects.Add(edge.Value);
                    }
                }
            }

            DrawResults(inputImage, defects);

            //void avl::DrawCoordinateSystem
            //(
            //    avl::Image & ioImage,

            //    const avl::CoordinateSystem2D&inCoordinateSystem,
            // atl::Optional <const avl::CoordinateSystem2D&> inCoordinateSystemAlignment,
            // const avl::Pixel&inColor,
            // const avl::DrawingStyle &inDrawingStyle,
            // const float inArrowSize,

            //    const float inPixelScale
            //)

            foreach (var scanSegment in scanSegments)
            {
                //mr:: local坐标系 变成 image 坐标系
                AVL.AlignSegment(scanSegment, localSystem, false, out Segment2D alignedSegment);

                AVL.DrawSegment(inputImage, alignedSegment, Pixel.White, defaultStyle, MarkerType.None, 5);
            }
            //mr:: 画出寻找local坐标系原点的scanPath
            AVL.DrawPath(inputImage, scanningPath, Pixel.Yellow, defaultStyle);
            //mr:: 画出local坐标系.
            AVL.DrawCoordinateSystem(inputImage, localSystem, Pixel.Green, defaultStyle, 10, 50);
        }
コード例 #2
0
        /// <summary>
        /// Default and sole constructor.
        /// </summary>
        /// <param name="imageFormat">Format of image on which inspection will be performed</param>
        /// <param name="scanPath">Path on which scanning for bottle will be performed</param>
        public CapInspection(ImageFormat imageFormat, Path scanPath)
        {
            format       = imageFormat;
            scanningPath = scanPath;
            //mr:: ScanMap需要Dispose(), scanMap作为字段, 在CapInspection管理字段的Dispose.
            scanMap = new ScanMap();

            /*
             * public static void CreateScanMap
             * (
             *      AvlNet.ImageFormat inImageFormat,
             *      AvlNet.Path inScanPath,
             *      AvlNet.CoordinateSystem2D? inScanPathAlignment,
             *      int inScanWidth,
             *      AvlNet.InterpolationMethod inImageInterpolation,
             *      AvlNet.ScanMap outScanMap,
             *      AvlNet.Path outAlignedScanPath,
             *      IList<AvlNet.Path> diagSamplingPoints,
             *      out float diagSamplingStep
             * )
             */

            //mr:: ScanMap依据ScanPath而生成.
            AVL.CreateScanMap(format, scanPath, null, 5, InterpolationMethod.Bilinear, scanMap);
        }
コード例 #3
0
        /// <summary>
        /// Finds the stripe on the image.
        /// </summary>
        /// <param name="image">Image to find the stripe on.</param>
        /// <param name="scanningSegment">Scanning segment chosen by user.</param>
        /// <param name="selectedPolarity">Polarity of the stripe - dark, bright or any.</param>
        /// <param name="measuredSegment">Segment representing the stripe that has been found.</param>
        /// <param name="measuredSegmentLength">Length of the segment.</param>
        /// <returns></returns>
        public static bool DoMeasurement(Image image, Segment scanningSegment, Polarity selectedPolarity,
                                         out Segment measuredSegment, out float measuredSegmentLength)
        {
            // Create disposable scanning parameters
            //mr:: 生成扫描线段. 注意Segment2D, Segment,是不同类型.Segment是程序自定义类型.
            Segment2D avlScanningSegment = new Segment2D(
                scanningSegment.StartPoint.X,
                scanningSegment.StartPoint.Y,
                scanningSegment.EndPoint.X,
                scanningSegment.EndPoint.Y);

            //mr:: 生成Stripe扫描参数
            StripeScanParams scanParams = new StripeScanParams()
            {
                StripePolarity = selectedPolarity
            };

            //mr:: Nullable.Create<Stripe1D>()
            var stripe = Nullable.Create <Stripe1D>();

            // Create the ScanMap object
            //mr:: ScanMap需要Dispose
            using (var scanMap = new ScanMap())
            {
                //mr:: 生成Image格式.
                ImageFormat imageFormat = new ImageFormat(image);
                //mr:: 生成扫描Map

                /*
                 * public static void CreateScanMap
                 * (
                 *  AvlNet.ImageFormat inImageFormat,
                 *  AvlNet.Path inScanPath,
                 *  AvlNet.CoordinateSystem2D? inScanPathAlignment,
                 *  int inScanWidth,
                 *  AvlNet.InterpolationMethod inImageInterpolation,
                 *  AvlNet.ScanMap outScanMap,
                 *  AvlNet.Path outAlignedScanPath,
                 *  IList<AvlNet.Path> diagSamplingPoints,
                 *  out float diagSamplingStep
                 * )
                 */
                AVL.CreateScanMap(imageFormat,
                                  new Path(avlScanningSegment),
                                  null,
                                  5,
                                  InterpolationMethod.Bilinear,
                                  scanMap);

                // Do the scanning
                //mr:: Stripe1D is a class, declared without out keyword in parameters of AVL.ScanSingleStripe

                /*
                 * public static void ScanSingleStripe
                 * (
                 *  AvlNet.Image inImage,
                 *  AvlNet.ScanMap inScanMap,
                 *  AvlNet.StripeScanParams inStripeScanParams,
                 *  AvlNet.Selection inStripeSelection,
                 *  AvlNet.LocalBlindness? inLocalBlindness,
                 *  INullable<AvlNet.Stripe1D> outStripe,
                 *  AvlNet.Profile diagBrightnessProfile,
                 *  AvlNet.Profile diagResponseProfile
                 * )
                 */
                AVL.ScanSingleStripe(image, scanMap, scanParams, Selection.Best, null, stripe);
            }

            if (stripe.HasValue) // Stripe has been found
            {
                //mr:: Segment is a class; measuredSegment is declared with out keyword ;
                //mr:: Segment的ctor输入参数是System.Drawing.Point类型.
                measuredSegment = new Segment(
                    new System.Drawing.Point((int)stripe.Value.Point1.X, (int)stripe.Value.Point1.Y),
                    new System.Drawing.Point((int)stripe.Value.Point2.X, (int)stripe.Value.Point2.Y));

                measuredSegmentLength = stripe.Value.Width;

                return(true);
            }
            else // Stripe not found
            {
                // Set values of output parameters
                measuredSegment       = null;
                measuredSegmentLength = 0.0f;
                return(false);
            }
        }