当前位置: 首页>>代码示例>>C#>>正文


C# BlobCounter.ExtractBlobsImage方法代码示例

本文整理汇总了C#中AForge.Imaging.BlobCounter.ExtractBlobsImage方法的典型用法代码示例。如果您正苦于以下问题:C# BlobCounter.ExtractBlobsImage方法的具体用法?C# BlobCounter.ExtractBlobsImage怎么用?C# BlobCounter.ExtractBlobsImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AForge.Imaging.BlobCounter的用法示例。


在下文中一共展示了BlobCounter.ExtractBlobsImage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

        public IEnumerable<Bitmap> Apply(Bitmap bitmap)
        {
            // assuming scanned background is white we need to invert for the algo to work
            var copy = new Invert().Apply(bitmap);

            copy = EnsureGrayscale(copy);
            new Threshold { ThresholdValue = 25 }.ApplyInPlace(copy);
            new FillHoles().ApplyInPlace(copy);

            var blobCounter = new BlobCounter
            {
                // set filtering options
                FilterBlobs = true,
                MinWidth = 50,
                MinHeight = 50,
            };

            blobCounter.ProcessImage(copy);
            var blobs = blobCounter.GetObjectsInformation();

            if (blobs.Any())
            {
                var invertedOriginal = new Invert().Apply(bitmap);
                foreach (var blob in blobs)
                {
                    // use inverted source to ensure correct edge colors
                    blobCounter.ExtractBlobsImage(invertedOriginal, blob, false);
                    var blobImage = blob.Image.ToManagedImage();

                    // straighten
                    var angle = new DocumentSkewChecker().GetSkewAngle(EnsureGrayscale(blobImage));
                    var rotationFilter = new RotateBilinear(-angle) { FillColor = Color.Black };
                    blobImage = rotationFilter.Apply(blobImage);

                    // crop
                    blobImage = new ExtractBiggestBlob().Apply(blobImage);

                    new Invert().ApplyInPlace(blobImage);
                    yield return blobImage;
                }
            }
            else
            {
                yield return bitmap;
            }
        }
开发者ID:x-skywalker,项目名称:Enhance,代码行数:46,代码来源:CropAndStraighten.cs

示例2: ExtractBlob

        public List<Blob> ExtractBlob()
        {
            // create instance of blob counter
            BlobCounter blobCounter = new BlobCounter();
            // process input image
            blobCounter.ProcessImage(ImageBitmap);
            
            // get information about detected objects   
            
            Blob[] blobArray = blobCounter.GetObjectsInformation();

            foreach(Blob blobdata in blobArray)
            {
                blobCounter.ExtractBlobsImage(ImageBitmap, blobdata, true);
            }
            
            return blobArray.ToList();
        }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:18,代码来源:ImageProcessor.cs

示例3: Index

        public ActionResult Index(string Data, int Smallest = 3, int Largest = 6, HttpPostedFileBase file = null)
        {
            string base64Image = null;
            if (file != null)
            {
                //try to determine data from posted file
                var bitmap = new Bitmap(file.InputStream);

                // lock image
                BitmapData bitmapData = bitmap.LockBits(
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                // step 1 - turn background to black
                var filter = new Invert();
                filter.ApplyInPlace(bitmapData);

                ColorFiltering colorFilter = new ColorFiltering();

                colorFilter.Red = new IntRange(0, 64);
                colorFilter.Green = new IntRange(0, 64);
                colorFilter.Blue = new IntRange(0, 64);
                colorFilter.FillOutsideRange = false;

                colorFilter.ApplyInPlace(bitmapData);

                // step 2 - locating objects
                BlobCounter blobCounter = new BlobCounter();

                blobCounter.FilterBlobs = true;
                blobCounter.MinHeight = 5;
                blobCounter.MinWidth = 5;

                blobCounter.ProcessImage(bitmapData);
                var blobs = blobCounter.GetObjectsInformation();
                bitmap.UnlockBits(bitmapData);
                base64Image = bitmap.ToBase64();
                // get information about detected objects
                var shapeChecker = new SimpleShapeChecker();

                var letters = new List<Letter>();

                int circleCount = 0;
                foreach (
                    var blob in
                        blobs.ToArray()
                            .OrderBy(b => b.Rectangle.Top)
                            .ThenBy(b => b.Rectangle.Left)
                            .ThenByDescending(b => b.Area))
                {

                    List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);

                    AForge.Point center;
                    float radius;

                    if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                    {

                        //Todo: filter on the largest radius * 90% to deal with resolutions
                        if (radius < 40)
                            continue;

                        blobCounter.ExtractBlobsImage(bitmap, blob, false);
                        var letter = blob.Image.ToManagedImage(true);
                        var resizeFilter = new ResizeBilinear(150, 150);
                        letter = resizeFilter.Apply(letter);

                        var bwBitmap = new Bitmap(75, 75, PixelFormat.Format32bppArgb);

                        for (int y = 40; y < 115; y++)
                        {
                            for (int x = 40; x < 115; x++)
                            {
                                var color = letter.GetPixel(x, y);
                                if (color.Name == "ff000000")
                                {
                                    bwBitmap.SetPixel(x - 40, y - 40, Color.Black);
                                }
                                else
                                {
                                    bwBitmap.SetPixel(x - 40, y - 40, Color.White);
                                }
                            }
                        }

                       letters.Add(new Letter
                       {
                           L = TrainingData.GetBestGuess(bwBitmap),
                           X = center.X,
                           Y = center.Y,
                           Radius = radius
                       });
                    }
                }

                var minX = letters.Min(c => c.X);
                var maxX = letters.Max(c => c.X);

                var minY = letters.Min(c => c.Y);
//.........这里部分代码省略.........
开发者ID:bootleg224,项目名称:WordBubblesSolver,代码行数:101,代码来源:HomeController.cs

示例4: Process

        public ActionResult Process(HttpPostedFileBase file)
        {
            var model = new List<TrainingDataItem>();

            var bitmap = new Bitmap(file.InputStream);

            // lock image
            BitmapData bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            // step 1 - turn background to black
            var filter = new Invert();
            filter.ApplyInPlace(bitmapData);

            ColorFiltering colorFilter = new ColorFiltering();

            colorFilter.Red = new IntRange(0, 64);
            colorFilter.Green = new IntRange(0, 64);
            colorFilter.Blue = new IntRange(0, 64);
            colorFilter.FillOutsideRange = false;

            colorFilter.ApplyInPlace(bitmapData);

            // step 2 - locating objects
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = 5;
            blobCounter.MinWidth = 5;

            blobCounter.ProcessImage(bitmapData);
            var blobs = blobCounter.GetObjectsInformation();
            bitmap.UnlockBits(bitmapData);

            // get information about detected objects
            var shapeChecker = new SimpleShapeChecker();

            int circleCount = 0;
            foreach (
                var blob in
                    blobs.ToArray()
                        .OrderBy(b => b.Rectangle.Top)
                        .ThenBy(b => b.Rectangle.Left)
                        .ThenByDescending(b => b.Area))
            {

                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);

                AForge.Point center;
                float radius;

                if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                {

                    //Todo: filter on the largest radius * 90% to deal with resolutions
                    if (radius < 40)
                        continue;

                    blobCounter.ExtractBlobsImage(bitmap, blob, false);
                    var letter = blob.Image.ToManagedImage(true);
                    var resizeFilter = new ResizeBilinear(150, 150);
                    letter = resizeFilter.Apply(letter);
                    var base64 = (letter.ToBase64());
                    var sb = new StringBuilder();

                    var bwBitmap = new Bitmap(75, 75, PixelFormat.Format32bppArgb);

                    for (int y = 40; y < 115; y++)
                    {
                        for (int x = 40; x < 115; x++)
                        {
                            var color = letter.GetPixel(x, y);
                            if (color.Name == "ff000000")
                            {
                                sb.Append("0");
                                bwBitmap.SetPixel(x - 40, y - 40, Color.Black);
                            }
                            else
                            {
                                sb.Append("1");
                                bwBitmap.SetPixel(x - 40, y - 40, Color.White);
                            }
                        }

                        sb.AppendLine();
                    }

                    model.Add(new TrainingDataItem
                    {
                        Base64Image = (bwBitmap.ToBase64()),
                        Letter = TrainingData.GetBestGuess(bwBitmap)
                    });
                }
            }

            return View(model.ToArray());
        }
开发者ID:bootleg224,项目名称:WordBubblesSolver,代码行数:98,代码来源:TrainingController.cs


注:本文中的AForge.Imaging.BlobCounter.ExtractBlobsImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。