- 本系列历程启发于“禾路老师”的视频课程,学习到两个重要知识点:实战和自己的库!
- 本系列历程多源于answer.opencv论坛的一些牛人的解答,作为小白只是代码的搬运工。
言归正传,请看项目要求:
- 求取印章的文字识别
- 圆形规则的文字等
- 场合应用较为广泛
思路分析一:
思路分析二:
代码实现:
- 预处理找到圆心和半径,怎么预处理方法太多了,如果有实际项目可以博文留言,大家一起讨论!
- Cart to Polar Translation
- 后期的投影变换之前做过,大家可以看另一篇博文--->>投影变换
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
Mat img=imread("123.png",0);
threshold(img,img,200,255,CV_THRESH_BINARY_INV); // to delete some noise
Mat labels;
connectedComponents(img, labels, 8, CV_16U);//连通域提取
Mat maximage = labels == 1;
maximage.convertTo(maximage, CV_8UC1);
//找圆的范围,因为后面minEnclosingCircle函数需要输入
Mat locations;
findNonZero(maximage, locations);
Point2f center;
float radius;
minEnclosingCircle(locations,center,radius);
Mat showImag = Mat::ones(img.size(),CV_8UC3);
circle(showImag, center, radius, Scalar(0, 255, 255), 2);
//---linear Cart to Polar
Mat matLinearPolar;
linearPolar(
img, matLinearPolar,
center,
radius, INTER_CUBIC);
//log Cart to Polar
Mat matLogPolar;
cv::logPolar(
img,
matLogPolar,
center,
radius/3,
INTER_CUBIC
);
threshold(matLinearPolar, matLinearPolar, 0, 255, CV_THRESH_BINARY_INV|THRESH_OTSU);
threshold(matLogPolar, matLogPolar, 0, 255, CV_THRESH_BINARY_INV|THRESH_OTSU);
return 0;
}
参考资料:
原文:https://www.cnblogs.com/wjy-lulu/p/9161772.html