The Origin of Template Matching Algorithm in opencv

The method is as follows:

Routine of image matching using SIFT library under OPENCV

// opencv_empty_proj.cpp: Defines the entry point of the console application.

//

# contains "stdafx.h"

# include & ltopencv 2/opencv . HPP & gt;

# include & ltopencv 2/features 2d/features 2d . HPP & gt;

# include & ltopen cv2/non free/non free . HPP & gt;

# include & ltopencv 2/legacy/legacy . HPP & gt;

# include & ltvector & gt

Use namespace std

Use namespace cv;

int _tmain(int argc,_TCHAR* argv[])

{

const char * imagename = " img.jpg

//Read the image from the file

mat img = im read(imagename);

mat img 2 = im read(" img 2 . jpg ");

//If reading the image fails,

if(img.empty())

{

Fprintf(stderr, "Unable to load image %s\n", imagename);

return- 1;

}

if(img2.empty())

{

Fprintf(stderr, "Unable to load image %s\n", imagename);

return- 1;

}

//Display image

Imshow (IMG);

imshow("image2 before ",img 2);

//sift feature detection

SiftFeatureDetector

Vector & lt Important Hint & gtkp 1, kp2

siftdtc.detect(img,KP 1);

mat outimg 1;

drawKeypoints(img,kp 1,outimg 1);

imshow("image 1 keypoints ",outimg 1);

Key point KP;

Vector & lt Important Tips & gt Iterator itvc

for(itvc = KP 1 . begin(); itvc! = KP 1 . end(); itvc++)

{

Cout & lt& lt "Angle:"<& ltitvc-& gt;; Angle & lt<& lt" \ t "<& ltitvc-& gt;; class _ id & lt& lt" \ t " & lt& ltitvc-& gt; octave & lt& lt" \ t " & lt& ltitvc-& gt; pt & lt& lt" \ t " & lt& ltitvc-& gt; Response & lt& ltendl

}

siftdtc.detect(img2,kp2);

Mat outimg2

Draw key points (img2, kp2, OUTIMG 2);

Imshow ("key point of image 2", OUTI MG 2);

Extractor;

Mat descriptor 1,descriptor2

BruteForceMatcher & ltL2<float & gt& gtmatcher

Vector & ltDMatch & gt match;

Mat img _ matches

extractor.compute(img,kp 1,descriptor 1);

extractor.compute(img2,kp2,descriptor 2);

imshow("desc ",descriptor 1);

cout & lt& ltendl & lt& ltdescriptor 1 & lt; & ltendl

Matcher.match (descriptor 1, descriptor 2, matches);

drawMatches(img,kp 1,img2,kp2,Matches,img _ matches);

imshow("matches ",img _ matches);

//This function waits for the key, and then presses any key on the keyboard to return.

wait key();

Returns 0;

}