OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3057|回复: 0

SIFT算法中的匹配器FlannBasedMatcher

[复制链接]
发表于 2019-2-16 21:47:59 | 显示全部楼层 |阅读模式
用同样的两张图进行两次匹配,用FlannBasedMatcher匹配器进行匹配,两次的匹配点数量为什么会不一样?希望大神解答下,万分感谢!!代码如下:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "imgproc/imgproc.hpp"  
#include <opencv2/features2d/features2d.hpp>
#include "opencv2/xfeatures2d/nonfree.hpp"
#include <vector>
#include "opencv2/opencv.hpp"
#include <cmath>
#include<iostream>
using namespace cv;
using namespace std;

int main(int argc, char *argv[])
{
        Mat image02 = imread("D:\\Chrome Download\\dataset\\CAB\\P1010477.JPG");
        Mat image01 = imread("D:\\Chrome Download\\dataset\\CAB\\P1010478.JPG");
        //灰度图转换  
        Mat image1, image2;
        cvtColor(image01, image1, CV_BGR2GRAY);
        cvtColor(image02, image2, CV_BGR2GRAY);

        //提取特征点   
        int minHessian = 1000;//2000
        Ptr<xfeatures2d::SURF> surfDetector = xfeatures2d::SURF::create(minHessian);
        vector<KeyPoint> keyPoint1, keyPoint2, keyPoint3, keyPoint4;
        vector<Point2f> imagePoints1, imagePoints2;
        surfDetector->detect(image1, keyPoint1);
        surfDetector->detect(image2, keyPoint2);

        //特征点描述,为下边的特征点匹配做准备   
        Mat imageDesc1, imageDesc2;
        surfDetector->compute(image1, keyPoint1, imageDesc1);
        surfDetector->compute(image2, keyPoint2, imageDesc2);


        //获得匹配特征点,并提取最优配对     
        FlannBasedMatcher matcher;
        vector<vector<DMatch> > InitMatchePoints1, InitMatchePoints2;
        vector<DMatch> GoodMatchePoints1, GoodMatchePoints2;
        matcher.knnMatch(imageDesc1, imageDesc2, InitMatchePoints1, 2);
        //Lowe's algorithm,获取优秀匹配点
        for (int i = 0; i < InitMatchePoints1.size(); i++)
        {
                if (InitMatchePoints1[i][0].distance < 0.8 * InitMatchePoints1[i][1].distance)
                {
                        GoodMatchePoints1.push_back(InitMatchePoints1[i][0]);
                }
        }
        cout << "匹配点的个数: " << GoodMatchePoints1.size() << endl;
       
        matcher.knnMatch(imageDesc1, imageDesc2, InitMatchePoints2, 2);
        //Lowe's algorithm,获取优秀匹配点
        for (int i = 0; i < InitMatchePoints2.size(); i++)
        {
                if (InitMatchePoints2[i][0].distance < 0.8 * InitMatchePoints2[i][1].distance)
                {
                        GoodMatchePoints2.push_back(InitMatchePoints2[i][0]);
                }
        }
        cout << "匹配点的个数: " << GoodMatchePoints2.size() << endl;
        return 0;

}





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-4-18 21:48 , Processed in 0.008983 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表