haoyang_feng 2015-03-16 01:56 采纳率: 0%
浏览 10133
已结题

已经用opencv对2副图片进行了SIFT特征点匹配,这一对一对的特征点存储在哪里呢,网上找的代码

已经用opencv对2副图片进行了SIFT特征点匹配,那么这一对一对的特征点存储在哪里呢,怎么提取其中一对特征点的坐标?

#include "stdafx.h"
#include
#include
#include "opencv2/core/core.hpp"//因为在属性中已经配置了opencv等目录,所以把其当成了本地目录一样
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
using namespace std;

void readme();

int main(int argc,char* argv[])
{
Mat img_1=imread("./image/query.png",CV_LOAD_IMAGE_GRAYSCALE);//宏定义时CV_LOAD_IMAGE_GRAYSCALE=0,也就是读取灰度图像
Mat img_2=imread("./image/rs_query.png",CV_LOAD_IMAGE_GRAYSCALE);//一定要记得这里路径的斜线方向,这与Matlab里面是相反的

if(!img_1.data || !img_2.data)//如果数据为空
{
    cout<<"opencv error"<<endl;
    return -1;
}
cout<<"open right"<<endl;

//第一步,用SIFT算子检测关键点

SiftFeatureDetector detector;//构造函数采用内部默认的
std::vector<KeyPoint> keypoints_1,keypoints_2;//构造2个专门由点组成的点向量用来存储特征点

detector.detect(img_1,keypoints_1);//将img_1图像中检测到的特征点存储起来放在keypoints_1中
detector.detect(img_2,keypoints_2);//同理

//在图像中画出特征点
Mat img_keypoints_1,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);

imshow("sift_keypoints_1",img_keypoints_1);//显示特征点
imshow("sift_keypoints_2",img_keypoints_2);

//计算特征向量
SiftDescriptorExtractor extractor;//定义描述子对象

Mat descriptors_1,descriptors_2;//存放特征向量的矩阵

extractor.compute(img_1,keypoints_1,descriptors_1);//计算特征向量
extractor.compute(img_2,keypoints_2,descriptors_2);

//用burte force进行匹配特征向量
BruteForceMatcher<L2<float>>matcher;//定义一个burte force matcher对象
vector<DMatch>matches;
matcher.match(descriptors_1,descriptors_2,matches);

//绘制匹配线段
Mat img_matches;
drawMatches(img_1,keypoints_1,img_2,keypoints_2,matches,img_matches);//将匹配出来的结果放入内存img_matches中

//显示匹配线段
imshow("sift_Matches",img_matches);//显示的标题为Matches
waitKey(0);
return 0;

}

  • 写回答

1条回答 默认 最新

  • haoyang_feng 2015-03-16 01:58
    关注

    代码如下:
    #include "stdafx.h"
    #include
    #include
    #include "opencv2/core/core.hpp"//因为在属性中已经配置了opencv等目录,所以把其当成了本地目录一样
    #include "opencv2/features2d/features2d.hpp"
    #include "opencv2/highgui/highgui.hpp"

    using namespace cv;
    using namespace std;

    void readme();

    int main(int argc,char* argv[])
    {
    Mat img_1=imread("./image/query.png",CV_LOAD_IMAGE_GRAYSCALE);//宏定义时CV_LOAD_IMAGE_GRAYSCALE=0,也就是读取灰度图像
    Mat img_2=imread("./image/rs_query.png",CV_LOAD_IMAGE_GRAYSCALE);//一定要记得这里路径的斜线方向,这与Matlab里面是相反的

    if(!img_1.data || !img_2.data)//如果数据为空
    {
        cout<<"opencv error"<<endl;
        return -1;
    }
    cout<<"open right"<<endl;
    
    //第一步,用SIFT算子检测关键点
    
    SiftFeatureDetector detector;//构造函数采用内部默认的
    std::vector<KeyPoint> keypoints_1,keypoints_2;//构造2个专门由点组成的点向量用来存储特征点
    
    detector.detect(img_1,keypoints_1);//将img_1图像中检测到的特征点存储起来放在keypoints_1中
    detector.detect(img_2,keypoints_2);//同理
    
    //在图像中画出特征点
    Mat img_keypoints_1,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);
    
    imshow("sift_keypoints_1",img_keypoints_1);//显示特征点
    imshow("sift_keypoints_2",img_keypoints_2);
    
    //计算特征向量
    SiftDescriptorExtractor extractor;//定义描述子对象
    
    Mat descriptors_1,descriptors_2;//存放特征向量的矩阵
    
    extractor.compute(img_1,keypoints_1,descriptors_1);//计算特征向量
    extractor.compute(img_2,keypoints_2,descriptors_2);
    
    //用burte force进行匹配特征向量
    BruteForceMatcher<L2<float>>matcher;//定义一个burte force matcher对象
    vector<DMatch>matches;
    matcher.match(descriptors_1,descriptors_2,matches);
    
    //绘制匹配线段
    Mat img_matches;
    drawMatches(img_1,keypoints_1,img_2,keypoints_2,matches,img_matches);//将匹配出来的结果放入内存img_matches中
    
    //显示匹配线段
    imshow("sift_Matches",img_matches);//显示的标题为Matches
    waitKey(0);
    return 0;
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗