C# 和 Aforge - 从 blob 中提取图像

发布于 2025-01-07 10:29:43 字数 1379 浏览 1 评论 0原文

以下函数解决了问题,但我不明白如何调用它,特别是“out List ImgLetters”部分。

  public static bool ApplyBlobExtractor (Bitmap SourceImg, int LettersCount, out List<Bitmap> ImgLetters)
    {
        ImgLetters = null;
        ImgLetters = new List<Bitmap> ();

        BlobCounter blobCounter  = new BlobCounter ();

        // Sort order
        blobCounter.ObjectsOrder = ObjectsOrder.XY;            
        blobCounter.ProcessImage (SourceImg);
        Blob[] blobs             = blobCounter.GetObjects (SourceImg, false);            

        // Adding images into the image list            
        UnmanagedImage currentImg;            
        foreach (Blob blob in blobs)
        {
            currentImg = blob.Image;
            ImgLetters.Add (currentImg.ToManagedImage ());
        }            

        return ImgLetters.Count == LettersCount;
    }

现在让我们看一下:

public static bool ApplyBlobExtractor (Bitmap SourceImg, int LettersCount, out List<Bitmap> ImgLetters)

Bitmap SourceImg - 图片,其中将找到 blob

int LettersCount - 我们要提取的 blob(数字)

列表 ImgLetters< /强> - ???

第三个参数有什么作用(如何调用这个函数)?

Bitmap image1 = new Bitmap(@"C:\1.png");    
..
ApplyBlobExtractor (image1, 1, ??? )
..
image2.save(@"C:\2.png")

Following function solves the problem, but I don't understand how to call it, especially "out List ImgLetters" part.

  public static bool ApplyBlobExtractor (Bitmap SourceImg, int LettersCount, out List<Bitmap> ImgLetters)
    {
        ImgLetters = null;
        ImgLetters = new List<Bitmap> ();

        BlobCounter blobCounter  = new BlobCounter ();

        // Sort order
        blobCounter.ObjectsOrder = ObjectsOrder.XY;            
        blobCounter.ProcessImage (SourceImg);
        Blob[] blobs             = blobCounter.GetObjects (SourceImg, false);            

        // Adding images into the image list            
        UnmanagedImage currentImg;            
        foreach (Blob blob in blobs)
        {
            currentImg = blob.Image;
            ImgLetters.Add (currentImg.ToManagedImage ());
        }            

        return ImgLetters.Count == LettersCount;
    }

Now lets look at this:

public static bool ApplyBlobExtractor (Bitmap SourceImg, int LettersCount, out List<Bitmap> ImgLetters)

Bitmap SourceImg - picture, where blobs will be found

int LettersCount - blob that we are going to extract (number)

out List ImgLetters - ???

What does 3rd parameter do (how to call this function)?

Bitmap image1 = new Bitmap(@"C:\1.png");    
..
ApplyBlobExtractor (image1, 1, ??? )
..
image2.save(@"C:\2.png")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2025-01-14 10:29:43

out 参数允许您从方法调用中获取结果,而不是通过返回参数。 http://msdn.microsoft.com/en -us/library/t3c3bfhx(v=vs.80).aspx

在您的示例中,方法 ApplyBlobExtractor 似乎需要一个源 Bitmap 和 LetterCount(大概是您期望找到的字母数),然后使用此 Blobcounter 对象将其切碎。如果它找到的字母数量与您期望找到的字母数量相同,它将返回 true。它还将通过 out 参数以列表形式为您提供输出图像。

调用它会做类似的事情...

Bitmap img1 = new Bitmap(@"C:\1.png");

List<Bitmap> foundImages;

bool result = ApplyBlobExtractor(img1, 1, out foundImages);

an out parameter allows you to get results back from a method call other than through the return parameter. http://msdn.microsoft.com/en-us/library/t3c3bfhx(v=vs.80).aspx

In your example the method ApplyBlobExtractor it appears to take a source Bitmap, and a LetterCount (presumably the number of letters you expect to find) it then uses this Blobcounter object to chop it up. It will return true if it finds the same number of letter you expect to find. It will also provide you the output images as a list back through the out parameter.

to call it would would do something like...

Bitmap img1 = new Bitmap(@"C:\1.png");

List<Bitmap> foundImages;

bool result = ApplyBlobExtractor(img1, 1, out foundImages);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文