#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
// Read input binary image
Mat image= imread("./binaryGroup.bmp",0);
if (!image.data)
return 0;
namedWindow("Binary Image");
imshow("Binary Image",image);
// Get the contours of the connected components
vector<vector<Point>> contours;
//findContours的输入是二值图像
findContours(image,
contours, // a vector of contours
CV_RETR_EXTERNAL, // retrieve the external contours
CV_CHAIN_APPROX_NONE); // retrieve all pixels of each contours
// Print contours' length轮廓的个数
cout << "Contours: " << contours.size() << endl;
vector<vector<Point>>::const_iterator itContours= contours.begin();
for ( ; itContours!=contours.end(); ++itContours) {
cout <
opencv轮廓提取与轮廓拟合
OpenCV轮廓提取与拟合实践
最新推荐文章于 2025-08-30 13:10:30 发布
本文介绍了如何在OpenCV中进行轮廓提取和轮廓拟合。首先,文章讲解了相对路径的使用,如在当前目录(cpp目录)和上一级目录下读取文件的方法。接着,展示了通过处理图像,如group.bmp和binaryGroup.bmp,来实现图像的二值化和轮廓识别的过程。

最低0.47元/天 解锁文章
3992

被折叠的 条评论
为什么被折叠?



