将Mat转换为关键点? [英] Converting Mat to Keypoint?

查看:251
本文介绍了将Mat转换为关键点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将两个描述符(SurfDescriptorExtractor输出)和关键点(SurfFeatureDetector输出)写入一个XML文件。
在将关键点(std :: vector)转换为Mat之前,完成以下操作(下面:将关键点转换为mat或将它们保存到文本文件opencv )。对于描述符不是必需的,它们已经是Mat。
所以这两个都保存为Mat,读取也没有问题。但是当使用FlannBasedMatcher,然后使用drawMatches,这个方法要求关键点数据。

I'm writing both descriptors (SurfDescriptorExtractor output) and keypoints (SurfFeatureDetector output) to an XML file. Before writing keypoints (std::vector) conversion to Mat is done ( following this: convert keypoints to mat or save them to text file opencv ). For descriptors isn't neccesary, they're Mat already. So both are saved as Mat, there's no problem on reading either. But when using a FlannBasedMatcher, and then drawMatches, this method asks for keypoint data.

问题是:你如何将Mat转换为Keypoint的向量,最好的方法?

The question is: how would you convert Mat to Keypoint's vector, and which would be the best approach?

推荐答案

通过查看OpenCV源(在/ modules / java / generator / src / cpp / converters .cpp,about line 185):

Just found this by looking at OpenCV source (under /modules/java/generator/src/cpp/converters.cpp, around line 185):

void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
{
    v_kp.clear();
    CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);
    for(int i=0; i<mat.rows; i++)
    {
        Vec<float, 7> v = mat.at< Vec<float, 7> >(i,0);
        KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);
        v_kp.push_back(kp);
    }
    return;
}

我使用它:

vector<KeyPoint> mat_to_keypoints(Mat* mat) {

    vector<KeyPoint>  c_keypoints;

    for ( int i = 0; i < mat->rows; i++) {
        Vec<float, 7> v = mat.at< Vec<float, 7> >(i,0);

        KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);

        c_keypoints.push_back(kp);

    };

    return c_keypoints;

};

这篇关于将Mat转换为关键点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆