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;
}
相关推荐
Csvn2 小时前
输出脱敏了,trace 里全是明文——用户数据的四个落点都得堵(S04)
人工智能·aigc·agent
Csvn2 小时前
WorkBuddy 使用指南:模板、SOP、技能、自动化的正确顺序
人工智能
IvanCodes2 小时前
模型如何自我改进?拆解 RSI 的模型权重与 Harness 两条路线
人工智能·算法·ai·论文·agent·rsi
罗西的思考2 小时前
【轻量化复刻大模型 / KIMI K3】MXFP4 / MXFP8 量化感知训练(QAT)& 演示
人工智能·算法·机器学习
ZhengEnCi2 小时前
韩国高考 AI 作弊:防作弊为什么总比作弊慢一步
人工智能·chatgpt
zs1996_3 小时前
推荐系统学习笔记
人工智能·深度学习·推荐算法
2的n次方_3 小时前
鸿蒙 PC 适配:把 Bluefish 图语言库做成可安装的桌面应用
人工智能
BillDev3 小时前
让 AI 智能体帮你在 PLM 里找物料:一个能落地的 Tool Calling 实战(附 5 个高频踩坑)
人工智能
阿enna4 小时前
从训练到部署:导出ONNX并检查YOLO26n的一致性
人工智能·深度学习·神经网络·yolo·目标检测·计算机视觉·cnn
汤姆宝库4 小时前
补全PPO:价值函数、GAE与裁剪
人工智能