コード例 #1
0
        /// <summary>
        /// Look at the input image and find a suitable blob.
        /// </summary>
        /// <param name="filter">HSL filter to use for image segmentation.</param>
        /// <param name="image">Input image to segment.</param>
        /// <param name="minRect">Minimum size of output blob.</param>
        /// <param name="colourBitmap">Bitmap to write binary image to.</param>
        /// <param name="maxSize">Maximum size of output blob (default value will allow any size).</param>
        /// <returns>A rectangle array of all suitable blobs, or an empty array if no suitable blobs are found.</returns>
        protected System.Drawing.Rectangle[] DetectObstacle(AForge.Imaging.Filters.HSLFiltering filter, Bitmap image, System.Drawing.Point minRect, out Bitmap colourBitmap, System.Drawing.Point maxSize = default(System.Drawing.Point))
        {
            Bitmap filtered;

            filtered = filter.Apply(image);

            //short[,] structuringElement = new short[,] { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 1, 0 } };

            filtered = BinaryImage(filtered);
            //AForge.Imaging.Filters.Opening openingFilter = new AForge.Imaging.Filters.Opening(structuringElement);
            //filtered = openingFilter.Apply(filtered);
            colourBitmap = filtered;

            AForge.Imaging.BlobCounter blobs = new AForge.Imaging.BlobCounter();
            blobs.MinWidth  = (int)minRect.X;
            blobs.MinHeight = (int)minRect.Y;
            if (!maxSize.IsEmpty)
            {
                blobs.MaxWidth  = maxSize.X;
                blobs.MaxHeight = maxSize.Y;
            }
            blobs.FilterBlobs  = true;
            blobs.ObjectsOrder = AForge.Imaging.ObjectsOrder.Size;
            blobs.ProcessImage(filtered);

            System.Drawing.Rectangle[] rectangles = blobs.GetObjectsRectangles();

            return(rectangles);
        }
コード例 #2
0
        public static void TestColorFiltering()
        {
            var bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(colorImgName);

            var            image = bmp.ToImage <Bgr, byte>();
            UnmanagedImage uIm   = UnmanagedImage.FromManagedImage(bmp);

            measure(() =>
            {
                var hsvIm = image.Convert <Hsv, byte>();
                var mask  = hsvIm.InRange(new Hsv(335 / 2, 0, 0), new Hsv(180, 0, 0), 0 /*just first channel*/);

                var maskedIm = image.CopyBlank();
                image.CopyTo(maskedIm, mask);
            },
                    () =>
            {
                AForge.Imaging.Filters.HSLFiltering f = new AForge.Imaging.Filters.HSLFiltering();
                f.Hue = new AForge.IntRange(335, 0);
                f.Apply(uIm);
            },
                    100,
                    "Image<,> HSV filtering",
                    "AForge HSL filtering");
        }
コード例 #3
0
        public static void TestColorFiltering()
        {
            var bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(colorImgName);

            var image = bmp.ToImage<Bgr, byte>();
            UnmanagedImage uIm = UnmanagedImage.FromManagedImage(bmp);

            measure(() =>
            {
                var hsvIm = image.Convert<Hsv, byte>();
                var mask = hsvIm.InRange(new Hsv(335 / 2, 0, 0), new Hsv(180, 0, 0), 0 /*just first channel*/);

                var maskedIm = image.CopyBlank();
                image.CopyTo(maskedIm , mask);
            },
            () =>
            {

                AForge.Imaging.Filters.HSLFiltering f = new AForge.Imaging.Filters.HSLFiltering();
                f.Hue = new AForge.IntRange(335, 0);
                f.Apply(uIm);
            },
            100,
            "Image<,> HSV filtering",
            "AForge HSL filtering");
        }