简体   繁体   English

如何使用opencv函数计算图像(二进制)的孔数

[英]How to calculate holes number of the image (binary) using opencv function

I want to calculate the Euler Number so i need number of connected component and number of the holes in the image. 我想计算欧拉数,所以我需要连接的零件数和图像中的孔数。 I found the how to find number of connected component. 我找到了如何查找已连接组件的数量。 Using this code; 使用此代码;

vector<vector<Point>>contours;
vector<Vec4i>hierarchy; 
findContours(mat,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE ); 
objects_num=contours.size(); 

But i am not sure of the right code for calculation of the connected components. 但是我不确定用于计算所连接组件的正确代码。 Do you know this code is right? 您知道这段代码正确吗?

Secondly ** but I don't know how to calculte the number of holes?The opencv doc says that all of the contours are organized into a two-level hierarchy, Do you know how to gain the number of the holes. 其次**但我不知道如何计算孔的数量?opencv文档说所有轮廓都组织为两级层次结构,您知道如何获取孔的数量。

I am trying to extract features from the that image. 我正在尝试从该图像中提取特征。 For example I need euler number, filledArea attributes. 例如,我需要欧拉数,filledArea属性。 For this reason; 为此原因; I am trying to figure out the number of the holes in the melanoma picture and number of connected components. 我试图找出黑色素瘤图片中的孔数和连接的组件数。 Do you know any function to find these attributes. 您知道找到这些属性的任何功能吗?

PS: I am working on Android platform using opencv for android. PS:我正在使用opencv for android在Android平台上工作。

So, I can advice you to begin to study how OpenCV handles the blobs (and the contours that describes the blobs). 因此,我可以建议您开始研究OpenCV如何处理斑点(以及描述斑点的轮廓)。

If you are interested in blob property like area, centroid, etc, you can use image moments (also have a look at here ). 如果您对blob属性(例如area,质心等)感兴趣,则可以使用图像矩 (也可以在此处查看 )。

Try to have a look at those tutorials for handling "finding holes" too, here and here . 尝试在这里这里也查看那些用于处理“发现漏洞”的教程。

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

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