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;
}
相关推荐
国产化创客几秒前
基于AI大模型智能硬件--小智AI项目PC端部署测试
人工智能
海边夕阳20062 分钟前
【每天一个AI小知识】:什么是零样本学习?
人工智能·经验分享·学习
平凡而伟大(心之所向)5 分钟前
云架构设计与实践:从基础到未来趋势
人工智能·阿里云·系统架构·安全架构
数据与后端架构提升之路6 分钟前
构建一个可进化的自动驾驶数据管道:规则引擎与异常检测的集成
人工智能·机器学习·自动驾驶
2401_841495641 小时前
【自然语言处理】轻量版生成式语言模型GPT
人工智能·python·gpt·深度学习·语言模型·自然语言处理·transformer
梵得儿SHI1 小时前
(第三篇)Spring AI 基础入门:PromptTemplate 与对话工程实战(从字符串拼接到底层模板引擎的进阶之路)
人工智能·prompt·大模型应用·spring ai·prompttemplate·ai 响应的质量与准确性·上下文管理策略
Yolo566Q1 小时前
OpenLCA生命周期评估模型构建与分析
java·开发语言·人工智能
是Yu欸1 小时前
【博资考5】网安2025
网络·人工智能·经验分享·笔记·网络安全·ai·博资考
云和数据.ChenGuang1 小时前
tensorflow生成随机数和张量
人工智能·python·tensorflow