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;
}
相关推荐
果粒橙_LGC2 分钟前
论文阅读系列(一)Qwen-Image Technical Report
论文阅读·人工智能·学习
雷达学弱狗17 分钟前
backward怎么计算的是torch.tensor(2.0, requires_grad=True)变量的梯度
人工智能·pytorch·深度学习
Seeklike19 分钟前
diffuxers学习--AutoPipeline
人工智能·python·stable diffusion·diffusers
CoovallyAIHub32 分钟前
为高空安全上双保险!无人机AI护航,YOLOv5秒判安全带,守护施工生命线
深度学习·算法·计算机视觉
杨过过儿35 分钟前
【Task01】:简介与环境配置(第一章1、2节)
人工智能·自然语言处理
小妖同学学AI36 分钟前
deepseek一键生成word和excel并一键下载
人工智能·word·excel·deepseek
黎燃44 分钟前
AI助力垃圾分类与回收的可行性研究:从算法到落地的深度解析
人工智能
强盛小灵通专卖员1 小时前
DL00291-联邦学习以去中心化锂离子电池健康预测模型完整实现
人工智能·机器学习·深度强化学习·核心期刊·导师·小论文·大论文
Hello123网站1 小时前
多墨智能-AI一键生成工作文档/流程图/思维导图
人工智能·流程图·ai工具
才思喷涌的小书虫1 小时前
小白玩转 DINO-X MCP(2):基于 DINO-X MCP 搭建饮食规划工作流
计算机视觉·mcp