OpenCV 对白色像素进行分组
我已经完成了艰苦的工作,将 MacBook 上的 iSight 摄像头变成了红外摄像头,对其进行了转换,设置了阈值等。现在得到的图像如下所示:
我现在的问题是;我需要通过对白色像素进行分组来了解图像上有多少斑点。我不想使用 cvBlob
/cvBlobsLib
,我宁愿只使用 OpenCV 中已有的内容。
我可以循环遍历像素并通过检查(阈值)触摸白色像素来对它们进行分组,但我猜测 OpenCV 可能有一种非常简单的方法可以做到这一点?
我猜我不能使用 cvFindContours
因为这将检索一个大数组中的所有白色像素,而不是将它们分成“组”。有人可以推荐吗? (请注意,这些不是圆圈,只是小型红外 LED 发出的光)
提前非常感谢!
汤姆德
I've done the hard work, turning my iSight camera on my MacBook into an infrared camera, converted it, set the threshold etc.. and now have an image that looks something like this:
My problem is now; I need to know how many blobs are on my image by grouping the white pixels. I don't want to use cvBlob
/cvBlobsLib
, I'd rather just use what is already in OpenCV.
I can loop through the pixels and group them by checking for (thresholded) touching white pixels, but I'm guessing there is probably a really easy way of doing this from OpenCV?
I'm guessing I can't use cvFindContours
as this will retrieve all the white pixels in one big array, rather than separating them into "groups". Could anyone recommend? (Note these are not circles, just the light emitted from little IR LEDs)
Many Thanks in advance!
tommed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
循环遍历图像寻找白色像素。当您遇到这种情况时,您可以使用
cvFloodFill
并将该像素作为种子。然后增加每个区域的填充值,以便每个区域具有不同的颜色。这称为标签。Loop through the image looking for white pixels. When you encounter one you use
cvFloodFill
with that pixel as seed. Then increment the fill value for every region so that each region has a different color. This is called labeling.是的,您可以使用
cvFindContours()
来完成。它返回指向找到的第一个序列的指针。使用该指针,您可以遍历找到的所有序列。除了这个方法之外,我建议您看看
cvBlobs
或cvBlobsLib
。后者作为官方斑点检测库集成在 OpenCV 2.0 中。Yes, you can do it with
cvFindContours()
. It returns the pointer to the first sequence that was found. Using that pointer you can traverse through all of the sequences found.Besides this method, I would advise you to take a look at
cvBlobs
orcvBlobsLib
. Latter one is integrated in OpenCV 2.0 as official blob detection lib.