AForge Blobcounter - 如何统计分裂的物体? [英] AForge Blobcounter -how to count splitted objects?
问题描述
我在计算图像上的小物体时遇到问题。在示例中,我使用了BlobCounter类(来自AForge框架)。但它不识别分裂的对象。这是函数输出
http://s3.postimg .org / cwkexxucj / result.jpg [ ^ ]
这是方法产生的门槛
http://s29.postimg.org/y0rze5ulj/treshold.jpg [ ^ ]
这是代码
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?
推荐答案
没有分裂对象这样的东西。从斑点识别的角度来看,它们只是不同的对象(在这个问题上正确计算)。这只是你的风景没有很好的定义。在应用blob识别之前,您可以使用对比度和其他滤镜。这种操作通常是不可避免的。仅保留原始图像,仅使用已过滤的图像进行blob识别。
-SA
There is no such thing as "splitted" objects. From the blob recognition standpoint, they are just different objects (calculated correctly, for this matter). It's just your scenery is not well defined. You can play with contrast and other filters before applying blob recognition. Such manipulations are usual and unavoidable. Only preserve original image, use the filtered one only to feed to the blob recognition.
—SA
这篇关于AForge Blobcounter - 如何统计分裂的物体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!