2013-10-19 194 views
2

我想了解如何獲取OpenCV中給定的KeyPoint的描述符。到目前爲止,我的代碼如下所示:KeyPoint描述符OpenCV

#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

讓我明白,點(0,0)和(10,10)? – GilLevi

+0

是的,這就是opencv的文檔所說的。 – BRabbit27

+0

然後看到我的回答:) – GilLevi

回答

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); 
+0

好吧,我明白了,但創建'KeyPoint'並將其傳遞給'DescriptorExtractor'的方式可以嗎?如果我在圖像中取一個5x5的小塊,計算描述符時應該傳遞整個圖像還是僅傳遞該補丁? – BRabbit27

+0

看我的回答:) – GilLevi