#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
using namespace cv;
using namespace std;
int main()
{
Mat srcImage = imread("1.jpg");
imshow("【原图】", srcImage);
//先对图像进行空间的转换(为了之后要提取二值图像)
Mat grayImage;
cvtColor(srcImage, grayImage, CV_BGR2GRAY);
//对图像进行滤波,达到较好的效果
GaussianBlur(grayImage, grayImage, Size(3, 3), 0, 0);
imshow("【滤波后的图像】", grayImage);
//用边缘检测的方式获取二值图像
Mat cannyImage;
Canny(grayImage, cannyImage, 128, 255, 3);
//在二值图像中提取轮廓
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(cannyImage, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
//对每个轮廓的点集 找逼近多边形
vector<vector<Point>> approxPoint(contours.size());
for (int i = 0; i < (int)contours.size(); i++)
{
approxPolyDP(contours[i], approxPoint[i], 3, true);
}
/******************************************绘制曲线的方
opencv3逼近多边形曲线-approxPolyDP函数在图像中的应用
最新推荐文章于 2024-09-04 00:44:36 发布
该博客介绍了如何利用OpenCV3的approxPolyDP函数处理图像,通过步骤包括图像预处理、边缘检测、轮廓提取和逼近多边形曲线的绘制,展示了如何将图像中的曲线近似为多边形并在图像上显示结果。
摘要由CSDN通过智能技术生成