C# and Aforge - extracting images from blobs
문제
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")
해결책
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);