Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <vector>
  5.  
  6. #include "opencv2\opencv.hpp"
  7. #include <opencv2\nonfree\features2d.hpp>
  8.  
  9. using namespace std;
  10. using namespace cv;
  11.  
  12. int main()
  13. {
  14. Mat img_1, img_2;
  15.  
  16. img_1= imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE );
  17. img_2= imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE );
  18. if(img_1.empty()||img_2.empty())
  19. {
  20. cout << "Could not open or find the image" << std::endl ;
  21. return -1;
  22. }
  23.  
  24. /// Resize
  25. resize(img_1,img_1,Size(0,0),0.5,0.5,INTER_LINEAR);
  26. resize(img_2,img_2,Size(0,0),0.5,0.5,INTER_LINEAR);
  27.  
  28. imshow("Image 1", img_1);
  29. imshow("Image 2", img_2);
  30.  
  31. // Step -1, Detect keypoints using SURF detector
  32. int minHessian = 400;
  33. SurfFeatureDetector detector(minHessian);
  34.  
  35. vector<KeyPoint> keypoints_1, keypoints_2;
  36. detector.detect(img_1, keypoints_1);
  37. detector.detect(img_2, keypoints_2);
  38.  
  39. // Step -2, Calculate descriptors (feature vector)
  40. SurfDescriptorExtractor extractor;
  41.  
  42. Mat descriptor_1, descriptor_2;
  43.  
  44. extractor.compute(img_1,keypoints_1,descriptor_1);
  45. extractor.compute(img_2,keypoints_2,descriptor_2);
  46.  
  47. //step - 3, Matching descriptor vectors with a brute force mathcher
  48.  
  49. BFMatcher matcher(NORM_L2);
  50.  
  51. vector<DMatch> matches;
  52. matcher.match(descriptor_1, descriptor_2,matches);
  53.  
  54. //--Draw Matches
  55. Mat img_matches;
  56. drawMatches(img_1,keypoints_1,img_2,keypoints_2,matches,img_matches);
  57.  
  58. //-- Show Detected Matches
  59. imshow("Matches",img_matches);
  60.  
  61. waitKey(0);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement