1 Star 0 Fork 0

lewlovehow / Learning-OpenCV-3_examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example_13-03.cpp 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
Gary Bradski 提交于 2017-07-02 02:02 . checked 12 and 13. Minor fixes
// Example 13-3. Template matching
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
void help( char** argv ){
cout << "\n"
<<"\nExample 13-3: using matchTemplate(). The call is:\n"
<<"\n"
<<argv[0] <<" <template> <image_to_be_searched?\n"
<< "\nExample:\n" << argv[0] << "../BlueCup.jpg ../adrian.jpg"
<<"\n"
<<" This routine will search using all methods:\n"
<<" cv::TM_SQDIFF 0\n"
<<" cv::TM_SQDIFF_NORMED 1\n"
<<" cv::TM_CCORR 2\n"
<<" cv::TM_CCORR_NORMED 3\n"
<<" cv::TM_CCOEFF 4\n"
<<" cv::TM_CCOEFF_NORMED 5\n"
<<"\n" << endl;
}
// Display the results of the matches
//
int main( int argc, char** argv ) {
if( argc != 3) {
help( argv );
return -1;
}
cv::Mat src, templ, ftmp[6]; // ftmp is what to display on
// Read in the template to be used for matching:
//
if((templ=cv::imread(argv[1], 1)).empty()) {
cout << "Error on reading template " << argv[1] << endl;
help( argv );return -1;
}
// Read in the source image to be searched:
//
if((src=cv::imread(argv[2], 1)).empty()) {
cout << "Error on reading src image " << argv[2] << endl;
help( argv );return -1;
}
// Do the matching of the template with the image
for(int i=0; i<6; ++i){
cv::matchTemplate( src, templ, ftmp[i], i);
cv::normalize(ftmp[i],ftmp[i],1,0,cv::NORM_MINMAX);
}
// Display
//
cv::imshow( "Template", templ );
cv::imshow( "Image", src );
cv::imshow("SQDIFF", ftmp[0] );
cv::imshow("SQDIFF_NORMED", ftmp[1] );
cv::imshow("CCORR", ftmp[2] );
cv::imshow("CCORR_NORMED", ftmp[3] );
cv::imshow("CCOEFF", ftmp[4] );
cv::imshow("CCOEFF_NORMED", ftmp[5] );
// Let user view results:
//
cv::waitKey(0);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lewlovehow/Learning-OpenCV-3_examples.git
git@gitee.com:lewlovehow/Learning-OpenCV-3_examples.git
lewlovehow
Learning-OpenCV-3_examples
Learning-OpenCV-3_examples
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891