我试图了解如何在OpenCV中获取给定KeyPoint
的描述符。到目前为止,我的代码如下所示:
#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;
}
问题是我在描述符中没有数据。我错过了什么?
你能更详细地解释传递给KeyPoint
对象的参数是什么吗?我是计算机视觉+ OpenCV的新手,所以可能有更好的解释(比OpenCV的文档)更有帮助。
答案 0 :(得分:1)
您尝试在点(0,0)和(10,10)上计算机ORB,但它们太靠近图像边界,因此ORB无法在这些位置计算描述符。 ORB(以及其他二进制描述符)将它们过滤掉。
编辑:既然你问过用法,我正在编辑答案。你应该传递整个图像。我用它作为:Ptr<FeatureDetector> detector = FeatureDetector::create(detector_name);
Ptr<DescriptorExtractor> descriptor = DescriptorExtractor::create(descriptor_name);
detector->detect(imgK, kp);
descriptor->compute(imgK, kp, desc);