下面进行第三节的学习,首先上实验的原图
求出轮廓的最小外接圆
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\core\core.hpp>
using namespace cv;
int main()
{
Mat srcImage = imread("1.png");
imshow("【原始图像】", srcImage);
cvtColor(srcImage, srcImage, CV_BGR2GRAY);
threshold(srcImage, srcImage, 0, 255, THRESH_OTSU);
imshow("【二值化图像】", srcImage);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(srcImage, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE);
Mat contoursImage(srcImage.rows, srcImage.cols, CV_8U, Scalar(0));
if (!contours.empty() && !hierarchy.empty())
{
for (int i = 0; i< contours.size(); i++)
{
drawContours(contoursImage, contours, i, Scalar(255), 1, 8, hierarchy);
}
}
imshow("边缘图像", contoursImage);
Mat resultImage(srcImage.rows, srcImage