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;
}
相关推荐
cxr82843 分钟前
SPARC方法论在Claude Code基于规则驱动开发中的应用
人工智能·驱动开发·claude·智能体
研梦非凡1 小时前
ICCV 2025|从粗到细:用于高效3D高斯溅射的可学习离散小波变换
人工智能·深度学习·学习·3d
幂简集成1 小时前
Realtime API 语音代理端到端接入全流程教程(含 Demo,延迟 280ms)
人工智能·个人开发
龙腾-虎跃2 小时前
FreeSWITCH FunASR语音识别模块
人工智能·语音识别·xcode
智慧地球(AI·Earth)2 小时前
给AI配一台手机+电脑?智谱AutoGLM上线!
人工智能·智能手机·电脑
Godspeed Zhao2 小时前
自动驾驶中的传感器技术46——Radar(7)
人工智能·机器学习·自动驾驶
limengshi1383922 小时前
机器学习面试:请介绍几种常用的学习率衰减方式
人工智能·学习·机器学习
AKAMAI2 小时前
Sport Network 凭借 Akamai 实现卓越成就
人工智能·云原生·云计算
周末程序猿3 小时前
机器学习|大模型为什么会出现"幻觉"?
人工智能
JoannaJuanCV3 小时前
大语言模型基石:Transformer
人工智能·语言模型·transformer