Skip to content

Commit

Permalink
Adding example 13-03 with the image data
Browse files Browse the repository at this point in the history
  • Loading branch information
Prasanna Krishnasamy committed May 21, 2017
1 parent 9147b6a commit ca1ef89
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_executable( example_12-01 example_12-01.cpp )
add_executable( example_12-02 example_12-02.cpp )
add_executable( example_13-01 example_13-01.cpp )
add_executable( example_13-02 example_13-02.cpp )
add_executable( example_13-03 example_13-03.cpp )
add_executable( example_16-01 example_16-01.cpp )

target_link_libraries( example_02-01 ${OpenCV_LIBS} )
Expand Down Expand Up @@ -71,6 +72,7 @@ target_link_libraries( example_12-01 ${OpenCV_LIBS} )
target_link_libraries( example_12-02 ${OpenCV_LIBS} )
target_link_libraries( example_13-01 ${OpenCV_LIBS} )
target_link_libraries( example_13-02 ${OpenCV_LIBS} )
target_link_libraries( example_13-03 ${OpenCV_LIBS} )
target_link_libraries( example_16-01 ${OpenCV_LIBS} )


Expand Down
70 changes: 70 additions & 0 deletions example_13-03.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Example 13-3. Template matching

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;

void help( char** argv ){
cout << "\n"
<<"Example of using matchTemplate(). The call is:\n"
<<"\n"
<<argv[0] <<" template image_to_be_searched\n"
<<"\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";
}

// 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);
}

Binary file added faceScene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added faceTemplate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ca1ef89

Please sign in to comment.