KeyPoint descriptor OpenCV

帅比萌擦擦* 提交于 2020-01-01 03:41:34

问题


I am trying to understand how to get the descriptor for a given KeyPoint in OpenCV. So far my code looks like follows:

#include <iostream>
#include "opencv2/opencv.hpp"

typedef cv::Mat Image;

int main(int argc, const char * argv[])
{

    Image imgA = cv::imread("images/buddhamulticam_total100.png",
                              CV_LOAD_IMAGE_GRAYSCALE);
    Image imgB = cv::imread("images/buddhamulticam_total101.png", 
                            CV_LOAD_IMAGE_GRAYSCALE);

    cv::Ptr<cv::FeatureDetector> detector = 
                    cv::FeatureDetector::create("ORB");
    cv::Ptr<cv::DescriptorExtractor> descriptor = 
                    cv::DescriptorExtractor::create("ORB");

    std::vector<cv::KeyPoint> keyPointsA, keyPointsB;

    keyPointsA.push_back(cv::KeyPoint(0,0,5));
    keyPointsB.push_back(cv::KeyPoint(10,10,5));

    cv::Mat descriptorA, descriptorB;
    descriptor->compute(imgA, keyPointsA, descriptorA);
    descriptor->compute(imgB, keyPointsB, descriptorB);

    std::cout << "DescriptorA (" << descriptorA.rows << "," <<
                descriptorA.cols << ")" << std::endl;
    std::cout << "DescriptorB (" << descriptorB.rows << "," 
              << descriptorB.cols << ")" << std::endl;
    return 0;
}

The problem is that I am getting no data in the descriptor. What am I missing? Could you explain in more detail what are the params passed to the KeyPoint object? I am new to computer vision + OpenCV, so probably a better explanation (than OpenCV's documentation) could help.


回答1:


You're trying to computer ORB on the points (0,0) and (10,10), but they are too close to the image border, so ORB can't compute descriptors in those locations. ORB (as well as the other binary descriptors) filters them out.

EDIT: since you asked about usage, I'm editing the answer. You should pass the whole image. I use it as:

Ptr<FeatureDetector> detector = FeatureDetector::create(detector_name);
Ptr<DescriptorExtractor> descriptor = DescriptorExtractor::create(descriptor_name);

detector->detect(imgK, kp);
descriptor->compute(imgK, kp, desc);


来源:https://stackoverflow.com/questions/19467766/keypoint-descriptor-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!