简体   繁体   English

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

[英]OpenCV how to find a list of connected components in a binary image

I am using OpenCV for a C++ application. 我正在将OpenCV用于C ++应用程序。 I have a 8 bit binary image that has some objects. 我有一个8位二进制图像,有一些对象。 The objects are all colored 255, whereas everything in the background is colored 0. Each object has no vacant (black) pixels inside it. 对象全部为255,而背景中的所有内容都为0.每个对象内部没有空白(黑色)像素。 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: 这是我想要从中提取的内容:

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. 这可能是使用cvConnectedComponents()或其他任何东西。 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? 任何指向OpenCV函数的指针是什么?

从3.0版开始,OpenCV具有connectedComponents功能。

You need to cv::floodFill the contours returned by cv::findCountours. 你需要cv :: floodFill cv :: findCountours返回的轮廓。 See this example for findContours, and this one for floodFill 这个例子对于findContours,和这一次的floodFill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM