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;
}
相关推荐
小柒777771 分钟前
PEFT(Parameter-Efficient Fine-Tuning)---LoRa方法
人工智能·深度学习·语言模型
HIT_Weston1 分钟前
20、【Agent】【OpenCode】源码构建(依赖安装)
人工智能·agent·opencode
记忆张量MemTensor2 分钟前
AI 数据迁移指南|Claude 靠提示词搬家,MindDock 一键完整备份记忆
人工智能·python·开源·github·浏览器
爱打代码的小林2 分钟前
OpenCV 实战:为视频添加椒盐噪声并实现中值滤波去噪
人工智能·opencv·计算机视觉
xingyuzhisuan5 分钟前
部署 AI 应用需要什么服务器?
人工智能
天远Date Lab5 分钟前
Python实战:基于天远二手车估值API构建企业车队资产数字化管理方案
大数据·人工智能·python
IT_陈寒5 分钟前
SpringBoot 项目启动慢?这5个优化技巧让你的应用快50%
前端·人工智能·后端
岁岁种桃花儿6 分钟前
AI超级智能开发系列从入门到上天第七篇:PromptTemplate模板
人工智能·llm
code_pgf7 分钟前
Jetson Orin NX 16G部署openclaw及本地化安全配置及建议
人工智能·安全·ai
weixin_668898647 分钟前
RNN解读
人工智能