本文整理汇总了C#中AForge.Imaging.BlobCounter.GetObjectsInformation方法的典型用法代码示例。如果您正苦于以下问题:C# BlobCounter.GetObjectsInformation方法的具体用法?C# BlobCounter.GetObjectsInformation怎么用?C# BlobCounter.GetObjectsInformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AForge.Imaging.BlobCounter
的用法示例。
在下文中一共展示了BlobCounter.GetObjectsInformation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: calcDescriptorInfo
public override void calcDescriptorInfo(Bitmap inImage)
{
shapeCount = new int[6];
originalImage = image;
image = imgProcessor.preProcessImage(inImage);
g = Graphics.FromImage(originalImage);
BlobCounter bCounter = new BlobCounter();
bCounter.ProcessImage(image);
Blob[] blobs = bCounter.GetObjectsInformation();
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
for (int i = 0; i < blobs.Length; i++)
{
if (blobs[i].Area < 100)
{
continue;
}
List<IntPoint> edgePts = bCounter.GetBlobsEdgePoints(blobs[i]);
checkShape(shapeChecker, edgePts);
}
g.Dispose();
}
示例2: CropImage
/// <summary>
/// Celem metody jest przykadrowanie otrzymanego obrazka, tak aby widok zawierał jedynie kartkę papieru, oraz zwrócenie go do metody UploadFile
/// </summary>
/// <param name="img"></param>
/// <returns></returns>
public System.Drawing.Image CropImage(System.Drawing.Image img)
{
//DocumentSkewChecker skewChecker = new DocumentSkewChecker();
//double angle = skewChecker.GetSkewAngle(image);
//RotateBilinear rotationFilter = new RotateBilinear(-angle);
//rotationFilter.FillColor = Color.White;
//Bitmap rotatedImage = rotationFilter.Apply(image);
Bitmap image = new Bitmap(img);
UnmanagedImage grayImage = null;
if (image.PixelFormat == PixelFormat.Format8bppIndexed)
{
grayImage = UnmanagedImage.FromManagedImage(image);
}
else
{
grayImage = UnmanagedImage.Create(image.Width, image.Height,
PixelFormat.Format8bppIndexed);
Grayscale.CommonAlgorithms.BT709.Apply(UnmanagedImage.FromManagedImage(image), grayImage);
}
CannyEdgeDetector edgeDetector = new CannyEdgeDetector();
UnmanagedImage edgesImage = edgeDetector.Apply(grayImage);
OtsuThreshold thresholdFilter = new OtsuThreshold();
thresholdFilter.ApplyInPlace(edgesImage);
Dilatation DilatationFilter = new Dilatation();
DilatationFilter.Apply(edgesImage);
Opening OpeningFilter = new Opening();
OpeningFilter.Apply(edgesImage);
BlobCounter blobCounter = new BlobCounter();
blobCounter.MinHeight = 32;
blobCounter.MinWidth = 32;
blobCounter.FilterBlobs = true;
blobCounter.ObjectsOrder = ObjectsOrder.Size;
blobCounter.ProcessImage(edgesImage);
Blob[] blobs = blobCounter.GetObjectsInformation();
ExtractBiggestBlob BiggestBlob = new ExtractBiggestBlob();
Bitmap biggestBlobsImage = BiggestBlob.Apply(edgesImage.ToManagedImage());
AForge.IntPoint BiggestBlogCorners = BiggestBlob.BlobPosition;
Crop cropFilter = new Crop(new Rectangle(BiggestBlogCorners.X, BiggestBlogCorners.Y, biggestBlobsImage.Width, biggestBlobsImage.Height));
Bitmap croppedImage = cropFilter.Apply(image);
return croppedImage;
}
示例3: Execute
// 如果活动返回值,则从 CodeActivity<TResult>
// 派生并从 Execute 方法返回该值。
protected override void Execute(CodeActivityContext context)
{
// create an instance of blob counter algorithm
BlobCounterBase bc = new BlobCounter();
// set filtering options
bc.FilterBlobs = true;
bc.MinWidth = context.GetValue(最小宽度);
bc.MinHeight = context.GetValue(最小高度);
// set ordering options
bc.ObjectsOrder = ObjectsOrder.Size;
// process binary image
bc.ProcessImage(context.GetValue(处理目标));
var blobs = bc.GetObjectsInformation();
context.SetValue(输出目标, blobs);
}
示例4: Rectangle
public static void Rectangle(WriteableBitmap bitmap, DrawingContext dc)
{
// locating objects
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MaxHeight = 375;
blobCounter.MaxWidth = 375;
System.Drawing.Bitmap image;
using (var stream = new MemoryStream())
{
var encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.Save(stream);
image = new System.Drawing.Bitmap(stream);
}
blobCounter.ProcessImage(image);
Blob[] blobs = blobCounter.GetObjectsInformation();
// check for rectangles
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
foreach (var blob in blobs)
{
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);
List<IntPoint> cornerPoints;
// use the shape checker to extract the corner points
if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
{
// only do things if the corners form a rectangle
if (shapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
{
// here i use the graphics class to draw an overlay, but you
// could also just use the cornerPoints list to calculate your
// x, y, width, height values.
List<AForge.Point> Points = new List<AForge.Point>();
foreach (var point in cornerPoints)
{
Points.Add(new AForge.Point(point.X, point.Y));
}
var path = new PathFigure(new System.Windows.Point(Points.First().X, Points.First().Y), Points.Select(row => new System.Windows.Media.LineSegment(new System.Windows.Point(row.X, row.Y), false)), true);
dc.DrawGeometry(Brushes.Red, null, new PathGeometry(new PathFigure[] { path }));
}
}
}
}
示例5: FindPlate
private WriteableBitmap FindPlate(IEnumerable<Rect> rects, WriteableBitmap image)
{
WriteableBitmap bestCandidate = null;
foreach (var rect in rects)
{
var croppedImage = image.Crop(rect);
var edgeFilter = new CannyEdgeDetector();
var smoothFilter = new Median();
var grayFilter = new Grayscale(0.2125, 0.7154, 0.0721);
var blobCounter = new BlobCounter();
var cutTop = croppedImage.PixelHeight * 0.3;
croppedImage = croppedImage.Crop(new Rect(0, cutTop, croppedImage.PixelWidth, croppedImage.PixelHeight));
var bitmap = (Bitmap)croppedImage;
var grayImage = grayFilter.Apply(bitmap);
bitmap = smoothFilter.Apply(grayImage);
edgeFilter.ApplyInPlace(bitmap);
blobCounter.ProcessImage(bitmap);
var blobs = blobCounter.GetObjectsInformation();
var possibleChars = new List<Rectangle>();
foreach (var blob in blobs)
{
var objRectangle = blob.Rectangle;
var ratio = (double)objRectangle.Height / (double)objRectangle.Width;
if (ratio >= 1.16d && ratio <= 6.3d)
{
possibleChars.Add(objRectangle);
}
}
if (possibleChars.Count == 0)
{
continue;
}
bestCandidate = croppedImage;
}
return bestCandidate;
}
示例6: 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;
}
}
示例7: blobRecognition
private static Blob[] blobRecognition(Bitmap thresholdedInverted)
{
//Use the AForge.NET BlobCounter to perform Blob Recognition / Connected Region Analysis
BlobCounter blobRecognition = new BlobCounter();
//Filter out blobs that are abviously the wrong size to be characters
blobRecognition.MinWidth = (int)(thresholdedInverted.Width * (BLOB_FILTER_MIN_DIMENSION_IMAGE_PERCENTAGE / 100));
blobRecognition.MinHeight = (int)(thresholdedInverted.Height * (BLOB_FILTER_MIN_DIMENSION_IMAGE_PERCENTAGE / 100));
blobRecognition.MaxWidth = (int)(thresholdedInverted.Width * (BLOB_FILTER_MAX_DIMENSION_IMAGE_PERCENTAGE / 100));
blobRecognition.MaxHeight = (int)(thresholdedInverted.Height * (BLOB_FILTER_MAX_DIMENSION_IMAGE_PERCENTAGE / 100));
blobRecognition.FilterBlobs = true;
blobRecognition.ProcessImage(thresholdedInverted);
Blob[] blobs = blobRecognition.GetObjectsInformation();
return blobs;
}
示例8: 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();
}
示例9: DetectBlobs
Blob[] DetectBlobs(Bitmap bmp)
{
Invert filter = new Invert();
filter.ApplyInPlace(bmp);
BlobCounter bc = new BlobCounter();
bc.BackgroundThreshold = Color.FromArgb(8, 8, 8);
bc.BlobsFilter = new BlobsFilter(bmp.Size);
bc.FilterBlobs = true;
bc.ProcessImage(bmp);
// Revert back
filter.ApplyInPlace(bmp);
return bc.GetObjectsInformation();
}
示例10: Process
// Process specified image trying to recognize counter's image
public void Process(Bitmap image, IImageProcessingLog log)
{
log.AddMessage("Image size: " + image.Width +
" x " + image.Height);
//get image
byte[] textData = GetImageData();
UnmanagedImage img = CreateImage(textData);
log.AddImage("Raw Image", img.ToManagedImage());
//resize Image
AForge.Imaging.Filters.ResizeNearestNeighbor resizeFilter = new AForge.Imaging.Filters.ResizeNearestNeighbor(500, (int)(500 / res));
UnmanagedImage resizedImage = resizeFilter.Apply(img);
log.AddImage("Resized Image", resizedImage.ToManagedImage());
//filter floor
UnmanagedImage floorFilteredImage = FilterFloor(resizedImage, textData);
log.AddImage("Floor filtered", floorFilteredImage.ToManagedImage());
// 1- grayscale image
Bitmap grayImage =
Grayscale.CommonAlgorithms.BT709.Apply(resizedImage.ToManagedImage());
log.AddImage("Grayscale", resizedImage.ToManagedImage());
// 2 - Otsu thresholding
OtsuThreshold threshold = new OtsuThreshold();
Bitmap binaryImage = threshold.Apply(grayImage);
log.AddImage("Binary", binaryImage);
log.AddMessage("Otsu threshold: " + threshold.ThresholdValue);
//resive image
// 3 - Blob counting
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinWidth = 1;
blobCounter.MinWidth = 1;
blobCounter.ProcessImage(binaryImage);
Blob[] blobs = blobCounter.GetObjectsInformation();
log.AddMessage("Found blobs (min width/height = 24): " +
blobs.Length);
}
示例11: ProcessFrame
public Bitmap ProcessFrame(Bitmap inputBitmap, int x, int y)
{
// Create an image for AForge to process
Bitmap workingImage = new Bitmap(inputBitmap.Width, inputBitmap.Height);
workingImage = AForge.Imaging.Image.Clone(inputBitmap, PixelFormat.Format24bppRgb);
// Create a mask for ROI selection
Rectangle roi = new Rectangle(x - 30, y-30, 80, 80);
Crop roicrop = new Crop(roi);
Bitmap outimage = roicrop.Apply(workingImage);
BlobCounter blobCounter = new BlobCounter();
blobCounter.ObjectsOrder = ObjectsOrder.Area;
Blob[] blobs;
// Find the blobs
blobCounter.ProcessImage(outimage);
blobs = blobCounter.GetObjectsInformation();
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[0]);
GrahamConvexHull grahamScan = new GrahamConvexHull();
List<IntPoint> hullPoints = grahamScan.FindHull(edgePoints);
Graphics g = Graphics.FromImage(outimage);
Pen redPen = new Pen(Color.Red, 2);
g.DrawPolygon(redPen, ToPointsArray(hullPoints));
//g.Clear(Color.Black);
//g.DrawImage(handImage, x, y);
//g.DrawRectangle(redPen, roi);
//g.DrawEllipse(redPen, x, y, 20, 20);
ResizeNearestNeighbor resizeFilter = new ResizeNearestNeighbor(160, 160);
Bitmap resizedImage = resizeFilter.Apply(outimage);
return resizedImage;
}
示例12: Quadrilaterals
public static List<List<IntPoint>> Quadrilaterals(Bitmap img, int minWidth, int minHeight)
{
Bitmap thresholdedImg = FilterCombinations.AdaptiveThreshold(img);
//Use blob recognition on the image to find all blobs meeting the specified minimum width & height
BlobCounter blobCounter = new BlobCounter();
//Filter out small blobs
blobCounter.MinWidth = minWidth;
blobCounter.MinHeight = minHeight;
blobCounter.FilterBlobs = true;
//Order the blobs by size (desc), as since we're looking for quads of a minimum size, it's likely we'll be more interested in the laregr ones
blobCounter.ObjectsOrder = ObjectsOrder.Size;
//Check if each blob is approximately a quadriateral, and if so store the 4 corners
List<List<IntPoint>> foundQuads = new List<List<IntPoint>>();
//Shape checker to be used to test if a blob is a quadrilateral
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
//Find the blobs
blobCounter.ProcessImage(thresholdedImg);
Blob[] blobs = blobCounter.GetObjectsInformation();
foreach(Blob b in blobs)
{
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(b);
List<IntPoint> corners = null;
//Is this blob approximately a quadrilateral?
if(shapeChecker.IsQuadrilateral(edgePoints, out corners))
{
//Store the Quad's corners
foundQuads.Add(corners);
}
}
return foundQuads;
}
示例13: GetRedBlobCenter
public static AForge.Point GetRedBlobCenter(Bitmap image)
{
BlobCounter bCounter = new BlobCounter();
bCounter.ProcessImage(image);
Blob[] blobs = bCounter.GetObjectsInformation();
Rectangle[] rects = bCounter.GetObjectsRectangles();
Pen pen = new Pen(Color.Red, 2);
Brush brush = new SolidBrush(Color.Red);
Graphics g = Graphics.FromImage(image);
if (rects.Length > 0) { g.FillRectangle(brush, rects[0]); }
if (blobs.Length > 0)
{
detected = true;
lastPos = blobs[0].CenterOfGravity;
AForge.Point rPos = new AForge.Point();
rPos.Y = ((lastPos.Y / 5) / 100) * 768;
rPos.X = ((lastPos.X / 5) / 100) * 1366;
return rPos;
}
else
{
detected = false;
if (lastPos != null)
{
return lastPos;
}
else
{
return new AForge.Point(50.0f, 50.0f);
}
}
}
示例14: DrawRectanglesFunct
// =========================================================
private Bitmap DrawRectanglesFunct(Bitmap image)
{
// step 1 - turn background to black (done)
// step 2 - locating objects
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinHeight = 3;
blobCounter.MinWidth = 3;
blobCounter.ProcessImage(image);
Blob[] blobs = blobCounter.GetObjectsInformation();
// step 3 - check objects' type and do what you do:
Graphics g = Graphics.FromImage(image);
Pen pen = new Pen(Color.DarkOrange, 2);
for (int i = 0, n = blobs.Length; i < n; i++)
{
SimpleShapeChecker ShapeChecker = new SimpleShapeChecker();
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
List<IntPoint> cornerPoints;
// fine tune ShapeChecker
ShapeChecker.AngleError = 15; // default 7
ShapeChecker.LengthError = 0.3F; // default 0.1 (10%)
ShapeChecker.MinAcceptableDistortion = 0.9F; // in pixels, default 0.5
ShapeChecker.RelativeDistortionLimit = 0.2F; // default 0.03 (3%)
// use the Outline checker to extract the corner points
if (ShapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
{
// only do things if the corners form a rectangle
if (ShapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
{
List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints);
g.DrawPolygon(pen, ToPointsArray(corners));
}
}
}
return (image);
}
示例15: FindCirclesFunct
// ==========================================================================================================
// Circles:
// ==========================================================================================================
private List<Shapes.Circle> FindCirclesFunct(Bitmap bitmap)
{
// locating objects
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinHeight = 5;
blobCounter.MinWidth = 5;
blobCounter.ProcessImage(bitmap);
Blob[] blobs = blobCounter.GetObjectsInformation();
List<Shapes.Circle> Circles = new List<Shapes.Circle>();
for (int i = 0, n = blobs.Length; i < n; i++)
{
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
AForge.Point center;
float radius;
// is circle ?
if (shapeChecker.IsCircle(edgePoints, out center, out radius))
{
if (radius > 3) // MirrFilter out some noise
{
Circles.Add(new Shapes.Circle(center.X, center.Y, radius));
}
}
}
return (Circles);
}