问题描述
我在计算图像上的小物体时遇到问题。在示例中,我使用了BlobCounter类(来自AForge框架)。但它不识别分裂的对象。这是函数输出
[ []
这是代码
I have a problem with counting small objects on the image. In example I used BlobCounter class (from AForge framework). But it doesnt recognize splitted objects. Here is the function output
http://s3.postimg.org/cwkexxucj/result.jpg[^]
Here is the treshold that method produces
http://s29.postimg.org/y0rze5ulj/treshold.jpg[^]
Here is the code
private void count_Objects_Click(object sender, EventArgs e)
{
Bitmap sample = (Bitmap)picProcessed.Image.Clone();
// create grayscale filter
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
// apply the filter
Bitmap grayImage = filter.Apply(sample);
// create threshold filter
SISThreshold filterT = new SISThreshold();
// apply the filter
filterT.ApplyInPlace(grayImage);
//Because blobcounter looks white objects on black background
//But we have to count black objects
Invert filterInvert = new Invert();
// apply the filter
filterInvert.ApplyInPlace(grayImage);
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinWidth = 2;
blobCounter.MinHeight = 2;
blobCounter.CoupledSizeFiltering = true;
blobCounter.ProcessImage(grayImage);
Blob[] blobs = blobCounter.GetObjectsInformation();
//manipulations to draw borders around founded objects
// create convex hull searching algorithm
GrahamConvexHull hullFinder = new GrahamConvexHull();
Bitmap image = (Bitmap)picProcessed.Image;
Bitmap clonimage = (Bitmap)picProcessed.Image.Clone();
BitmapData data = clonimage.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);
// process each blob
foreach (Blob blob in blobs)
{
List<IntPoint> leftPoints, rightPoints, edgePoints;
edgePoints = new List<IntPoint>();
// get blob's edge points
blobCounter.GetBlobsLeftAndRightEdges(blob,
out leftPoints, out rightPoints);
edgePoints.AddRange(leftPoints);
edgePoints.AddRange(rightPoints);
// blob's convex hull
List<IntPoint> hull = hullFinder.FindHull(edgePoints);
Drawing.Polygon(data, hull, Color.Black);
}
clonimage.UnlockBits(data);
picProcessed.Image = clonimage;
picProcessed.Refresh();
int count = blobs.Length;
MessageBox.Show("Total objects found: " + count);
}
1 blobcount算法的第一个函数处理图像到二进制图像
2然后它寻找blob
3然后它绘制(在原始图像上)blob周围的边界
如何拆分blob?或者也许还有其他方法来计算图像中的对象?
1 First function process image to binary image for blobcount algorithm
2 Then it looks for blobs
3 Then it draws (on original image) borders around blobs
How to split blobs? Or maybe there is other methods for counting objects in image?
推荐答案
这篇关于AForge Blobcounter - 如何统计分裂的物体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!