化相关系数匹配法:method=TM_CCOEFF_NORMED##
这是在一个海港图上截出来的一部分,然后要从这部分识别出日期
#include <opencv2/opencv.hpp>
#include<vector>
using namespace std;
using namespace cv;
//切割方框下方五个部分的区域
void processEnglishBottomImage(cv::Mat amask)
{
int width = amask.size().width;
Mat bottomImg;
cvtColor(amask, bottomImg, CV_BGR2GRAY);
//把括号里的值转化为int型
int newcols = static_cast<int>(bottomImg.cols * 0.25);
Mat newbottomImg = bottomImg(Range(0, bottomImg.rows), Range(0, newcols));
Mat NoticeTem = imread("template1.png", 0);//使用的模版
Mat ResultNot, ResultPub;
//匹配notice
cv::matchTemplate(newbottomImg, NoticeTem, ResultNot, CV_TM_CCOEFF_NORMED);
cv::normalize(ResultNot, ResultNot, 0, 1, NORM_MINMAX, -1, Mat());
double minValN, maxValN, minValP, maxValP;
cv::Point minLocN, maxLocN, minLocP, maxLocP;
//minMaxLoc的作用:在数组中找到全局最小值和最大值,第二三参数表示最小、大值的指针
//第四五参数表示最小、大位置的指针
cv::minMaxLoc(ResultNot, &minValN, &maxValN, &minLocN, &maxLocN, Mat());
/* cv::matchTemplate(newbottomImg, PublishedTem, ResultPub, CV_TM_CCOEFF_NORMED);
cv::normalize(ResultPub, ResultPub, 0, 1, NORM_MINMAX, -1, Mat());
cv::minMaxLoc(ResultPub, &minValP, &maxValP, &minLocP, &maxLocP, Mat());
*/
//截出Edition Data
Mat bottom1 = amask(Range(maxLocN.y+30 , maxLocN.y + NoticeTem.rows+34), Range(maxLocN.x+200, maxLocN.x+500));
// Mat bottom1 = amask(Range(maxLocN.y, maxLocN.y + NoticeTem.rows), Range(maxLocN.x , maxLocN.x + NoticeTem.cols));
imwrite("011.jpg", bottom1);
}
int main(int argc, char* argv[])
{
Mat mask = imread("11.jpg");
processEnglishBottomImage(mask);
waitKey(0);
system("pause");
return 0;
}
这是截出来的日期
这是所用的模板