opencv3逼近多边形曲线-approxPolyDP函数在图像中的应用

该博客介绍了如何利用OpenCV3的approxPolyDP函数处理图像,通过步骤包括图像预处理、边缘检测、轮廓提取和逼近多边形曲线的绘制,展示了如何将图像中的曲线近似为多边形并在图像上显示结果。
摘要由CSDN通过智能技术生成
#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);
	}

	/******************************************绘制曲线的方
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值