Skip to content

Commit ca1ef89

Browse files
author
Prasanna Krishnasamy
committed
Adding example 13-03 with the image data
1 parent 9147b6a commit ca1ef89

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_executable( example_12-01 example_12-01.cpp )
3838
add_executable( example_12-02 example_12-02.cpp )
3939
add_executable( example_13-01 example_13-01.cpp )
4040
add_executable( example_13-02 example_13-02.cpp )
41+
add_executable( example_13-03 example_13-03.cpp )
4142
add_executable( example_16-01 example_16-01.cpp )
4243

4344
target_link_libraries( example_02-01 ${OpenCV_LIBS} )
@@ -71,6 +72,7 @@ target_link_libraries( example_12-01 ${OpenCV_LIBS} )
7172
target_link_libraries( example_12-02 ${OpenCV_LIBS} )
7273
target_link_libraries( example_13-01 ${OpenCV_LIBS} )
7374
target_link_libraries( example_13-02 ${OpenCV_LIBS} )
75+
target_link_libraries( example_13-03 ${OpenCV_LIBS} )
7476
target_link_libraries( example_16-01 ${OpenCV_LIBS} )
7577

7678

example_13-03.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Example 13-3. Template matching
2+
3+
#include <opencv2/opencv.hpp>
4+
#include <iostream>
5+
6+
using namespace std;
7+
8+
void help( char** argv ){
9+
cout << "\n"
10+
<<"Example of using matchTemplate(). The call is:\n"
11+
<<"\n"
12+
<<argv[0] <<" template image_to_be_searched\n"
13+
<<"\n"
14+
<<" This routine will search using all methods:\n"
15+
<<" cv::TM_SQDIFF 0\n"
16+
<<" cv::TM_SQDIFF_NORMED 1\n"
17+
<<" cv::TM_CCORR 2\n"
18+
<<" cv::TM_CCORR_NORMED 3\n"
19+
<<" cv::TM_CCOEFF 4\n"
20+
<<" cv::TM_CCOEFF_NORMED 5\n"
21+
<<"\n";
22+
}
23+
24+
// Display the results of the matches
25+
//
26+
int main( int argc, char** argv ) {
27+
28+
if( argc != 3) {
29+
help( argv );
30+
return -1;
31+
}
32+
33+
cv::Mat src, templ, ftmp[6]; // ftmp is what to display on
34+
35+
// Read in the template to be used for matching:
36+
//
37+
if((templ=cv::imread(argv[1], 1)).empty()) {
38+
cout << "Error on reading template " << argv[1] << endl;
39+
help( argv );return -1;
40+
}
41+
42+
// Read in the source image to be searched:
43+
//
44+
if((src=cv::imread(argv[2], 1)).empty()) {
45+
cout << "Error on reading src image " << argv[2] << endl;
46+
help( argv );return -1;
47+
}
48+
49+
// Do the matching of the template with the image
50+
for(int i=0; i<6; ++i){
51+
cv::matchTemplate( src, templ, ftmp[i], i);
52+
cv::normalize(ftmp[i],ftmp[i],1,0,cv::NORM_MINMAX);
53+
}
54+
55+
// Display
56+
//
57+
cv::imshow( "Template", templ );
58+
cv::imshow( "Image", src );
59+
cv::imshow("SQDIFF", ftmp[0] );
60+
cv::imshow("SQDIFF_NORMED", ftmp[1] );
61+
cv::imshow("CCORR", ftmp[2] );
62+
cv::imshow("CCORR_NORMED", ftmp[3] );
63+
cv::imshow("CCOEFF", ftmp[4] );
64+
cv::imshow("CCOEFF_NORMED", ftmp[5] );
65+
66+
// Let user view results:
67+
//
68+
cv::waitKey(0);
69+
}
70+

faceScene.jpg

167 KB
Loading

faceTemplate.jpg

2.36 KB
Loading

0 commit comments

Comments
 (0)