本文整理汇总了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;
}
}
示例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();
}
示例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);
//.........这里部分代码省略.........
示例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());
}