opencv 凸包检测 convexHull

cpp 复制代码
#include "iostream"
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main()
{
	Mat  img, temp, temp2,dst, dstbin, distancetransform,rel, rel2,gary, _threshold, temp3, OPEN;

	img = imread("shou2.jpg");

	resize(img, dst, Size(0, 0), 0.1, 0.1);
	dst.copyTo(temp3);

	cvtColor(dst, gary, COLOR_BGR2GRAY);

	threshold(gary, _threshold, 50, 255, THRESH_TOZERO);

	Mat kernel = getStructuringElement(1, Size(3, 3));

	morphologyEx(_threshold, OPEN, MORPH_OPEN, kernel);

	GaussianBlur(OPEN, temp2, Size(5, 5), 5, 0);

	threshold(temp2, rel, 100, 255, THRESH_BINARY);
	Mat canny;
	Canny(rel, canny, 50, 170, 3, false);

	//Mat kernel = getStructuringElement(1, Size(3, 3));

	//erode(canny, canny, kernel);
	dilate(canny, canny, kernel);

	vector<vector<Point>> contours;
	vector<Vec4i> hierarchy;
	findContours(canny, contours, hierarchy, 0, 2, Point());

	for (int i = 0; i < contours.size(); i++)
	{
		vector<Point> pointss;
		convexHull(contours[i], pointss);
	

		for (int j = 0; j < pointss.size(); j++)
		{
			if (j == pointss.size()-1)
			{
				line(dst, pointss[j], pointss[0], Scalar(0, 0, 255));
				break;
			}
			line(dst, pointss[j], pointss[j + 1], Scalar(0, 0, 255));
		}
	
	}
	imshow("dst", dst);
	imshow("temp3", temp3);
	imshow("canny", canny);

	waitKey(0);

	return 1;
}
相关推荐
Jamence14 分钟前
多模态大语言模型arxiv论文略读(113)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
haf-Lydia19 分钟前
金融科技的数字底座
人工智能·科技·金融
shengjk122 分钟前
多智能体大语言模型系统频频翻车?三大失败根源与解决方案全解析
人工智能
北极的树24 分钟前
谁说AI只会模仿,从Google AlphaEvolve项目看算法的自主创新
人工智能·算法·gemini
安思派Anspire28 分钟前
用 LangGraph 构建第一个 AI 智能体完全指南(一)
人工智能
广州正荣29 分钟前
Scrapy-Redis分布式爬虫架构的可扩展性与容错性增强:基于微服务与容器化的解决方案
人工智能·爬虫·科技
加油搞钱加油搞钱31 分钟前
鹰盾加密器基于AI的视频个性化压缩技术深度解析:从智能分析到无损压缩实践
人工智能·音视频·视频加密·鹰盾加密·鹰盾播放器
Baihai_IDP33 分钟前
OCR 识别质量如何影响 RAG 系统的性能?有何解决办法?
人工智能·llm·aigc
新智元35 分钟前
20 人团队提前实现 DeepSeek 构想,AI 算力变天?直击大模型算力成本痛点
人工智能·openai
硬核隔壁老王40 分钟前
从零开始搭建RAG系统系列(十):RAG系统性能优化技巧-生成模块优化 (Optimizing Generator)
人工智能·程序员·llm