Punkty skalo-niezmiennicze

 

SIFT

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;
int main(){
  initModule_nonfree();
  Mat img = imread("/2.png", 1);
  Mat dst, img_display, img_grey;
  cvtColor(img, img_grey, CV_BGR2GRAY);
  Ptr feature_detector = FeatureDetector::create("SIFT");
  vector<KeyPoint> keypoints;
  feature_detector->detect(img_grey, keypoints);
  drawKeypoints(img, keypoints, img_display, Scalar(0, 0, 255));
  imshow("SIFT", img_display);
  waitKey(0);
  return 0;
}

Dopasowani punktów

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/nonfree/features2d.hpp"

#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
using namespace cv;

int main()
{
  Mat img1 = imread("./st1.png", 1);
  Mat img2 = imread("./st2.png", 1);
  Mat img_grey1, img_grey2;
  cvtColor(img1, img_grey1, CV_BGR2GRAY);
  cvtColor(img2, img_grey2, CV_BGR2GRAY);
  SiftFeatureDetector sift_detector;
  vector<KeyPoint> keypoints1, keypoints2;
  sift_detector.detect(img_grey1, keypoints1);
  sift_detector.detect(img_grey2, keypoints2);
  //-- Step 2: Calculate descriptors (feature vectors)
  SiftDescriptorExtractor sift_extractor;
  Ptr<FeatureDetector>  feature_detector;
  Mat descriptors1, descriptors2;
  sift_extractor.compute(img_grey1, keypoints1, descriptors1);
  sift_extractor.compute(img_grey2, keypoints2, descriptors2);
  //-- Step 3: Matching descriptor vectors using FLANN matcher
  FlannBasedMatcher matcher;
  std::vector< DMatch > matches;
  matcher.match( descriptors1, descriptors2, matches);
  // Display SIFT matches
  Mat display_image;
  drawMatches(img1, keypoints1, img2, keypoints2, matches, display_image);
  imshow("SIFT", display_image);

  waitKey(0);
  return 0;
}

Dopasowani najlepszych punktów

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/nonfree/features2d.hpp"

#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
using namespace cv;

int main(){
{
  Mat img1 = imread("F:/GRAFIKA_STRONA/st1.png", 1);
  Mat img2 = imread("F:/GRAFIKA_STRONA/st2.png", 1);
  Mat img_grey1, img_grey2;
  cvtColor(img1, img_grey1, CV_BGR2GRAY);
  cvtColor(img2, img_grey2, CV_BGR2GRAY);
  SiftFeatureDetector sift_detector;
  vector<KeyPoint> keypoints1, keypoints2;
  sift_detector.detect(img_grey1, keypoints1);
  sift_detector.detect(img_grey2, keypoints2);
  //-- Step 2: Calculate descriptors (feature vectors)
  SiftDescriptorExtractor sift_extractor;
  Ptr<FeatureDetector> feature_detector;// = FeatureDetector::create("SIFT");
  Mat descriptors1, descriptors2;
  //  feature_detector->detect(img_grey1, keypoints1, descriptors1);
  //  feature_detector->detect(img_grey2, keypoints2, descriptors2);
  sift_extractor.compute(img_grey1, keypoints1, descriptors1);
  sift_extractor.compute(img_grey2, keypoints2, descriptors2);

  //-- Step 3: Matching descriptor vectors using FLANN matcher
  FlannBasedMatcher matcher;
  std::vector<DMatch> matches;
  matcher.match(descriptors1, descriptors2, matches);

  double max_dist = 0; double min_dist = 100;
  //-- Quick calculation of max and min distances between keypoints
  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;
  }
  printf("-- Max dist : %f \n", max_dist);
  printf("-- Min dist : %f \n", min_dist);
  //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,S or a small arbitary value ( 0.02 ) in the event that min_dist is very small)
  //-- PS.- radiusMatch can also be used here.
  std::vector< DMatch > good_matches;
  for (int i = 0; i < descriptors1.rows; i++){
    if (matches[i].distance <= max(2 * min_dist, 0.02)){
      good_matches.push_back(matches[i]);
    }
  }
  //-- Draw only "good" matches
  Mat img_matches;
  drawMatches(img1, keypoints1, img2, keypoints2,
    good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
  //-- Show detected matches
  imshow("Good Matches", img_matches);
  for (int i = 0; i < (int)good_matches.size(); i++){
    printf("-- Good Match [%d] Keypoint 1: %d  -- Keypoint 2: %d  \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx);}
  waitKey(0);
  return 0;
}