OpenCV分组白色像素

我已经完成了艰苦的工作,将我的MacBook上的iSight摄像头转换为红外摄像头,转换它,设置阈值等等。现在有一个看起来像这样的图像:

替代文字

我现在的问题是; 我需要通过分组白色像素来了解我的图像上有多少个斑点。 我不想使用cvBlob / cvBlobsLib ,我宁愿只使用OpenCV中已有的东西。

可以通过检查(阈值)触摸白色像素循环像素并对它们进行分组,但我猜测从OpenCV可能有一种非常简单的方法吗?

我猜我不能使用cvFindContours因为这将检索一个大数组中的所有白色像素,而不是将它们分成“组”。 有人可以推荐吗? (注意这些不是圆圈,只是从小红外LED发出的光)

提前谢谢了!
tommed

循环通过图像寻找白色像素。 当你遇到一个时,你使用cvFloodFill作为种子。 然后增加每个区域的填充值,以便每个区域具有不同的颜色。 这称为标签。

是的,您可以使用cvFindContours() 。 它返回指向找到的第一个序列的指针。 使用该指针,您可以遍历所有找到的序列。

  // your image converted to grayscale IplImage* grayImg = LoadImage(...); // image for drawing contours onto IplImage* colorImg = cvCreateImage(cvGetSize(grayImg), 8, 3); // memory where cvFindContours() can find memory in which to record the contours CvMemStorage* memStorage = cvCreateMemStorage(0); // find the contours on image *grayImg* CvSeq* contours = 0; cvFindContours(grayImg, memStorage, &contours); // traverse through and draw contours for(CvSeq* c = contours; c != NULL; c = c->h_next) { cvCvtColor( grayImg, colorImg, CV_GRAY2BGR ); cvDrawContours( colorImg, c, CVX_RED, CVX_BLUE, 0, // Try different values of max_level, and see what happens 2, 8 ); } 

除了这个方法,我建议你看一下cvBlobscvBlobsLib 。 后者作为官方blob检测库集成在OpenCV 2.0中。