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;
}
相关推荐
LOnghas121138 分钟前
电动汽车充电接口自动识别与定位_yolo13-C3k2-Converse_六种主流充电接口检测分类
人工智能·目标跟踪·分类
编码小哥40 分钟前
OpenCV图像滤波技术详解:从均值滤波到双边滤波
人工智能·opencv·均值算法
阿杰学AI42 分钟前
AI核心知识78——大语言模型之CLM(简洁且通俗易懂版)
人工智能·算法·ai·语言模型·rag·clm·语境化语言模型
新缸中之脑1 小时前
氛围编程一个全栈AI交易应用
人工智能
码云数智-大飞1 小时前
Oracle RAS:AI时代守护企业数据安全的智能盾牌
数据库·人工智能·oracle
余俊晖1 小时前
Qwen3-VL-0.6B?Reyes轻量化折腾:一个从0到1开始训练的0.6B参数量的多模态大模型
人工智能·自然语言处理·多模态
zuozewei1 小时前
7D-AI系列:DeepSeek Engram 架构代码分析
人工智能·架构
love530love1 小时前
技术复盘:llama-cpp-python CUDA 编译实战 (Windows)
人工智能·windows·python·llama·aitechlab·cpp-python·cuda版本
Katecat996631 小时前
基于YOLO11-HAFB-1的五种羊品种分类识别系统详解
人工智能·数据挖掘
旧日之血_Hayter1 小时前
Java线程池实战:高效并发编程技巧
人工智能