标签:操作 href points style 类型 sub output tree tail
凸包的定义:
包含点集 S 所有点的最小凸多边形称为凸包。
凸包绘制原理:Graham 扫描法
寻找凸包:convexHull 函数
void convexHull(InputArray points, OutputArray hull, bool clockwise = false, bool returnPoints = true);
代码示例:
#include<opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(){
Mat src = imread("C:/Users/齐明洋/Desktop/1.jpg");
imshow("src", src);
Mat gray, bin_img;
cvtColor(src, gray, COLOR_BGR2GRAY);
medianBlur(gray, gray, 3);//中值滤波,去除椒盐噪声
imshow("gray", gray);
//获得二值图像,canny 和 threshold 两种方法都可以
//Canny(gray, bin_img, 20, 40, 3);
threshold(gray, bin_img, 80, 255, THRESH_BINARY);
imshow("bin_img", bin_img);
//获取轮廓
vector<vector<Point> >contours;
findContours(bin_img, contours, RETR_TREE, CHAIN_APPROX_NONE);
//获取凸包
vector<vector<Point> >hull(contours.size());
Mat dst = Mat(src.size(), src.type());
for (int i = 0; i < contours.size(); i++) {
convexHull(contours[i], hull[i]);
drawContours(dst, hull, i, Scalar(0, 0, 255), 1);
}
imshow("dst", dst);
waitKey(0);
}
效果演示:
借鉴博客:https://blog.csdn.net/just_tree/article/details/89296985
标签:操作 href points style 类型 sub output tree tail
原文地址:https://www.cnblogs.com/bjxqmy/p/12344543.html