之前考虑到区域生长、形态学但是都不能很好的解决问题,最后基于依稀啊方式进行了解决,具体测试图像如下所示:
代码实现:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
// 读取二值图像
Mat src = imread("C:\\Users\\Desktop\\客户项目\\2.png", IMREAD_GRAYSCALE);
// 查找轮廓
vector<vector<Point>> contours;
findContours(src, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// 遍历每个轮廓
for (int i = 0; i < contours.size();