C++ OpenCV如何在二进制图像中找到连接组件的列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17565180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV how to find a list of connected components in a binary image
提问by Cricketer
I am using OpenCV for a C++ application. I have a 8 bit binary image that has some objects. The objects are all colored 255, whereas everything in the background is colored 0. Each object has no vacant (black) pixels inside it. In other words, each object is fully white. The objects are NOT connected to each other. Here's what I want to extract from this:
我正在将 OpenCV 用于 C++ 应用程序。我有一个包含一些对象的 8 位二进制图像。对象的颜色均为 255,而背景中的所有内容均为 0。每个对象内部都没有空白(黑色)像素。换句话说,每个对象都是全白的。对象没有相互连接。这是我想从中提取的内容:
I want to extract some kind of list of objects, from which I have some notion of the location of each object in that list. This could be using cvConnectedComponents() or anything else. I need some indication of where each object is located in the image. This could be in the form of bounding rectangle for each object or median or center based on some computation or anything that gives me a measure of the objects location in the image. Any pointers to what OpenCV functions to look into?
我想提取某种对象列表,从中我对该列表中每个对象的位置有一些概念。这可能是使用 cvConnectedComponents() 或其他任何东西。我需要一些指示每个对象在图像中的位置。这可以是基于某些计算或任何可以让我测量图像中对象位置的方法,以每个对象或中值或中心的边界矩形的形式。任何指向 OpenCV 函数的指针?
采纳答案by Francesco Callari
You need to cv::floodFill the contours returned by cv::findCountours. See this examplefor findContours, and this onefor floodFill
您需要 cv::floodFill 由 cv::findCountours 返回的轮廓。见这个例子对于findContours,和这一次的floodFill
回答by Alessandro Jacopson
Starting from version 3.0, OpenCV has connectedComponents
function.
从 3.0 版本开始,OpenCV 有了connectedComponents
功能。