OpenCV如何在二进制图像中找到连接组件的列表

2022-01-09 00:00:00 opencv computer-vision image c c++

我将 OpenCV 用于 C++ 应用程序.我有一个包含一些对象的 8 位二进制图像.所有对象的颜色均为 255,而背景中的所有内容的颜色均为 0.每个对象内部都没有空白(黑色)像素.换句话说,每个对象都是全白的.这些对象没有相互连接.以下是我想从中提取的内容:

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:

我想提取某种对象列表,从中我可以了解每个对象在该列表中的位置.这可能是使用 cvConnectedComponents() 或其他任何东西.我需要一些指示每个对象在图像中的位置.这可能是每个对象的边界矩形或基于某些计算的中值或中心的形式,或者任何可以让我测量图像中对象位置的东西.任何指向要研究的 OpenCV 函数的指针?

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?

推荐答案

需要对cv::flood填充cv::findCountours返回的轮廓.findContours 参见 本示例,以及 这个 用于 floodFill

You need to cv::floodFill the contours returned by cv::findCountours. See this example for findContours, and this one for floodFill

相关文章