matching modification

This commit is contained in:
emiliie 2015-02-03 18:04:34 +01:00
parent f363035712
commit 94c2f49db5
4 changed files with 127 additions and 8 deletions

View File

@ -9,3 +9,8 @@ g++ -std=c++11 -o bin/Calibration.exe obj/Calibration/* %LIBS%
g++ -std=c++11 -c -o obj/DetectionAndMatching/DetectionAndMatching.o src/DetectionAndMatching/DetectionAndMatching.cpp %INCLUDE%
g++ -std=c++11 -o bin/DetectionAndMatching.exe obj/DetectionAndMatching/* %LIBS%
g++ -std=c++11 -c -o obj/DetectionAndMatchingSift/DetectionAndMatchingSift.o src/DetectionAndMatchingSift/DetectionAndMatchingSift.cpp %INCLUDE%
g++ -std=c++11 -o bin/DetectionAndMatchingSift.exe obj/DetectionAndMatchingSift/* %LIBS%
pause

View File

@ -1,5 +1,7 @@
#include <stdio.h>
#include <iostream>
#include <math.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
@ -9,6 +11,7 @@
using namespace cv;
void readme();
std::vector<std::pair<KeyPoint, KeyPoint>> DetectionAndMatching(Mat img_1, Mat img_2);
/** @function main */
int main( int argc, char** argv )
@ -22,12 +25,26 @@ int main( int argc, char** argv )
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
std::vector<std::pair<KeyPoint, KeyPoint>> matchPoints;
matchPoints = DetectionAndMatching(img_1, img_2);
// print matchPoints
std::cout << " affichage des match points" << std::endl;
for(int i=0;i<matchPoints.size();i++) std::cout << matchPoints[i].first.pt.x << " " << matchPoints[i].second.pt.y << std::endl;
return 0;
}
/** @function DetectionAndMatching */
std::vector<std::pair<KeyPoint,KeyPoint>> DetectionAndMatching(Mat img_1, Mat img_2)
{
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 1000;
int minHessian = 500;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
@ -41,7 +58,7 @@ int main( int argc, char** argv )
//-- Show detected (drawn) keypoints
imshow("Keypoints 1", img_keypoints_1 );
imshow("Keypoints 2", img_keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
@ -55,19 +72,34 @@ int main( int argc, char** argv )
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
//-- Draw matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
//-- Show detected matches
imshow("Matches", img_matches );
waitKey(0);
return 0;
//waitKey(0);
// vector of pairs of matching points
std::vector<std::pair<KeyPoint,KeyPoint>> matchPoints;
for(int i=0;i<matches.size();i++)
{
//myPair pair of matching points
std::pair<KeyPoint,KeyPoint> myPair;
//queryIdx index of the point from image 1
myPair.first=keypoints_1[matches[i].queryIdx];
//trainIdx index of the point from image 2
myPair.second=keypoints_2[matches[i].trainIdx];
matchPoints.push_back(myPair);
}
return matchPoints;
}
/** @function readme */
void readme()
{ std::cout << " Usage: DetectionAndMatching.exe <img1> <img2>" << std::endl; }
{ std::cout << " Usage: DetectionAndMatching.exe <img1> <img2>" << std::endl; }

View File

@ -0,0 +1,81 @@
#include <stdio.h>
#include <iostream>
#include <math.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
void readme();
/** @function main */
int main( int argc, char** argv )
{
if( argc != 3 )
{ readme(); return -1; }
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
cv::SiftFeatureDetector detector;
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- Draw keypoints
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
//-- Show detected (drawn) keypoints
imshow("Keypoints 1", img_keypoints_1 );
imshow("Keypoints 2", img_keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors with a brute force matcher
BFMatcher matcher(NORM_L2);
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
//-- Draw matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
//-- Show detected matches
//namedWindow("Matches", CV_WINDOW_AUTOSIZE);
//Mat tmp2 = img_matches;
//Mat dst2 = tmp2;
//cv::pyrDown(tmp2,dst2,Size(tmp.cols/2,tmp.rows/2));
imshow("Matches", img_matches );
waitKey(0);
return 0;
}
/** @function readme */
void readme()
{ std::cout << " Usage: DetectionAndMatching.exe <img1> <img2>" << std::endl; }

View File

@ -29,6 +29,7 @@ cf TP Simone Gasparini
- function :
- tests :
- use the function to match the points between a picture and herself
- use the function with different soft toys on the first and second picture
### Binary filter ?