轮廓特征属性及应用(六)
1.轮廓最小外接圆——minEnclosingCircle()
2.轮廓的椭圆拟合——fitEllipse()
3.轮廓的多边形逼近——approxPolyDP()
4.计算轮廓面积——contourArea();计算轮廓长度——arcLength()
5.提取不规则轮廓
先上ppt:
代码:1.轮廓最小外接圆
///轮廓最小外接圆
#include "opencv2/opencv.hpp"
using namespace cv;
#include <iostream>
using namespace std;
int main()
{
//1.查找轮廓的预处理
Mat srcImg = imread("10.png",CV_LOAD_IMAGE_COLOR);
Mat copyImg = srcImg.clone();
cvtColor(srcImg,srcImg,CV_BGR2GRAY);
threshold(srcImg,srcImg,100,255,CV_THRESH_BINARY);
imshow("threshold",srcImg);
//2.查找轮廓并绘制所有轮廓
vector < vector<Point> > contours;
findContours(srcImg,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);//最外层轮廓
drawContours(copyImg,contours,-1,Scalar(0,0,255),2,8);
//3.查找最小外接圆
Point2f center;//存储最小外接圆的圆心
float radius;//存储最小外接圆的半径
for (int i