Sie sind auf Seite 1von 3

#include

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

<stdio.h>
"opencv2/core/core.hpp"
"opencv2/features2d/features2d.hpp"
"opencv2/highgui/highgui.hpp"
"opencv2/nonfree/nonfree.hpp"
<iostream>
<sstream>
<string>
<opencv\highgui.h>
<opencv\cv.h>
"../src/SiftGPU/SiftGPU.h"

using namespace std;


using namespace cv;
void GetTrainingImages()
{
VideoCapture cap(CV_CAP_ANY);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
if (!cap.isOpened())
cout << "Error opening Camera";
Mat img;
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
char k;
while (true)
{
cap >> img;
if (!img.data)
continue;
k = waitKey(20);
if (k == 13) //Enter Key
{
break;
}
}
}
int main(int argc, char** argv)
{
//GetTrainingImages();
Mat img1 = imread("D:\\Images\\flyer.jpg", CV_LOAD_IMAGE_GRAYSCALE);
SiftDescriptorExtractor detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
SiftDescriptorExtractor extractor;
Mat descriptors1;
extractor.compute(img1, keypoints1, descriptors1);
//BFMatcher matcher(NORM_L2);
FlannBasedMatcher matcher;
vector<DMatch> matches;
VideoCapture cap(CV_CAP_ANY);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);

cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
if (!cap.isOpened())
cout << "Error opening Camera";
Mat img;
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
char k;
while (true)
{
cap >> img;
if (!img.data)
continue;
Mat descriptors2;
Mat img_matches;
detector.detect(img, keypoints2);
extractor.compute(img, keypoints2, descriptors2);
matcher.match(descriptors1, descriptors2, matches);
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoi
nts
for( int i = 0; i < descriptors1.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
//-- Draw only "good" matches (i.e. whose distance is less tha
n 2*min_dist )
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors1.rows; i++ )
{ if( matches[i].distance < 2*min_dist )
{ good_matches.push_back( matches[i]); }
}
if(good_matches.size() > 10)
{
Size size = img.size();
//-- Draw only "good" matches
/* drawMatches( img1, keypoints1, img, keypoints2,
good_matches, img_matches, Scalar::al
l(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT
_DRAW_SINGLE_POINTS );*/
putText(img, "Matched", Point(0, cvRound(size.height - 30)), F
ONT_HERSHEY_SCRIPT_SIMPLEX, 1, Scalar(0,0,255));
drawKeypoints(img,keypoints2,img);
//-- Show detected matches
imshow( "video capture", img );
}
else imshow("video capture",img);
k = waitKey(20);
if (k == 13) //Enter Key
{
break;
}
}
return 0;

Das könnte Ihnen auch gefallen