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;
}
相关推荐
一切皆是因缘际会3 分钟前
掌控信息论:同源星际通信基础理论
人工智能·算法·ai
库拉大叔4 分钟前
知漫剧、豆包、可灵,角色一致性谁更强
人工智能·aigc
飞哥数智坊30 分钟前
AI 帮我把 Mac 下的 3D 鱼缸搬到了 Windows
人工智能·ai编程
飞猫的边缘AI39 分钟前
边缘AI为什么加速上车了?
人工智能·自动驾驶·辅助驾驶·vla·noa·边缘ai·ai场景
goujunwe1 小时前
GEO 内容写作标准:4 套可直接复制、更容易被 AI 采信的结构化模板
人工智能
看浪的路人1 小时前
第4讲:数据投毒与模型完整性保护
人工智能
通信瓦工1 小时前
高功率密度AI数据中心的Mega AALC(高级辅助液体冷却)解决方案
大数据·人工智能
u1301301 小时前
GitHub 热榜项目:日榜(2026-10-06)
人工智能·github
DongQiShanRen1 小时前
裁决台账双向互校(中):五向一致性链——②向解读与③向实现
人工智能·深度学习·自然语言处理·集成学习·vllm
小宋10211 小时前
Speculative Decoding 什么时候真能提速:接受率、草稿模型与瓶颈定位
人工智能