2016-07-14 85 views
1

我試圖使用STAR探測器在OpenCV中3,而它拋出一個錯誤:如何使用STAR探測器在OpenCV中3蟒蛇?

import cv2 

image = cv2.imread('grand_central_terminal.png') 
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 

star = cv2.xfeatures2d.StarDetector_create() 
(kps, descs) = star.detectAndCompute(gray, None) 
print("# of keypoints: {}".format(len(kps))) # should be 459 

它給人的錯誤是:

Traceback (most recent call last): 
    File "quiz.py", line 8, in <module> 
    (kps, descs) = star.detectAndCompute(gray, None) 
cv2.error: /home/travis/miniconda/conda-bld/work/opencv-3.1.0/modules/features2d/src/feature2d.cpp:144: error: (-213) in function detectAndCompute 

以下是圖像: grand_central_terminal.png

在Ubuntu上運行16.04LTS 64位與Python 3.5和蟒蛇。

回答

1

錯誤代碼-213您收到指示該detectAndCompute方法沒有爲STAR檢測器實現。那是因爲STAR只是一個特徵檢測器,而不是一個組合檢測器和描述符。您的代碼可以通過調用detect方法來修復:

kps = star.detect(gray) 
+0

我明白了,那麼star.detectAndCompute應該如何工作? – wordsforthewise

+1

'star.detectAndCompute'不應該工作。這種方法似乎是一種不幸的事故。在'xfeatures2d'模塊中的一些東西是兩個檢測器和描述符(如ORB或SIFT),和那些利用detectAndCompute'的'。 STAR是唯一一個特徵檢測器,但不會計算這些關鍵點的描述符。 – Aurelius