forked from oreillymedia/Learning-OpenCV-3_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding example 13-03 with the image data
- Loading branch information
Prasanna Krishnasamy
committed
May 21, 2017
1 parent
9147b6a
commit ca1ef89
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.