#include <iostream>
#include <vector>

#include "include/opencv2/opencv.hpp"
#include "include/opencv2/core.hpp"

using namespace std;

bool dContoursIsClose(cv::Mat &image)//输入二值化或灰度图像
{
    vector<vector<cv::Point>> vContours;
	vector<cv::Vec4i> hierarchy;
	cv::findContours(image, vContours, hierarchy, cv::RETR_CCOMP, cv::CHAIN_APPROX_NONE);
	int fatherContoursNum = 0;
	for (size_t i = 0; i < hierarchy.size(); i++) {
		if (hierarchy[i][3] == -1) {//父轮廓
			++fatherContoursNum;
			if (hierarchy[i][2] == -1)//若有内嵌轮廓,此轮廓为闭合轮廓,若没有则不是闭合轮廓
			{
				return false;
			}
		}
		else {//当前对象为子轮廓或内嵌轮廓
			if (hierarchy[i][3] > hierarchy.size()) {//若索引越界
				return false;
			}
			if (i == hierarchy[hierarchy[i][3]][2]) {}//判断内嵌轮廓的父轮廓是否存在
			else {
				return false;
			}
		}
	}
	if (fatherContoursNum != (hierarchy.size() / 2)) {//两层结构的轮廓均有父轮廓与嵌套轮廓
		return false;
	}
	return true;
}

GitHub 加速计划 / opencv31 / opencv
218
20
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:28 天前 )
19c41c29 Improved blur #27822 * Perform row and column filter operations in a single pass. * Temporary storage of intermediate results are avoided. * Impacts 32F and 64F inputs for ksize <=5. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 2 小时前
aeea7072 Rename fields in camera calibration results 3 小时前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐