Emgu CV blob检测灰度图像

时间:2012-02-29 15:19:55

标签: emgucv

我是图像处理的新手。谁能教我如何在灰度图像中进行斑点检测?我们非常感谢示例代码。然后我必须计算出现的blob数量。顺便说一句,输入将来自网络摄像头。还有如何确定blob的大小?喜欢比较尺寸几乎与头部相同?实际上我正在做一个计数器,我必须计算通过门的人数。

1 个答案:

答案 0 :(得分:0)

在我评论的链接示例中:

http://opencv.willowgarage.com/wiki/cvBlobsLib

您可以轻松获得CBlob个对象:

CBlobResult blobs;
int i;
CBlob *currentBlob;
IplImage *original, *originalThr;

// load an image and threshold it
original = cvLoadImage("pic1.png", 0);
cvThreshold( original, originalThr, 100, 0, 255, CV_THRESH_BINARY );

// find non-white blobs in thresholded image
blobs = CBlobResult( originalThr, NULL, 255 );
// exclude the ones smaller than param2 value
blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );

// get mean gray color of biggest blob
CBlob biggestBlob;
CBlobGetMean getMeanColor( original );
double meanGray;

blobs.GetNth( CBlobGetArea(), 0, biggestBlob );
meanGray = getMeanColor( biggestBlob );

// display filtered blobs
cvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );

for (i = 0; i < blobs.GetNumBlobs(); i++ )
{
        currentBlob = blobs.GetBlob(i);
        currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
}

然后您可以根据需要调用AreaPerimeter