2012-11-11 90 views
0

我只是試圖開始學習OpenCV。我的理解是ExtractSURF應該返回0到360之間的角度。由於某些原因,關鍵點總是爲我返回一個90的方向。任何想法爲什麼?ExtractSURF總是返回相同的方向

此代碼:

import cv 
image = cv.LoadImageM('lena.bmp', cv.CV_LOAD_IMAGE_GRAYSCALE) 
(keypoints, descriptors) = cv.ExtractSURF(image, None, cv.CreateMemStorage(), (0, 6000, 1, 3)) 
for keypoint in keypoints: 
    ((x, y), laplacian, size, dir, hessian) = keypoint 
    print "x=%d y=%d laplacian=%d size=%f dir=%f hessian=%f" % (x, y, laplacian, size, dir, hessian) 

回報

x=345 y=201 laplacian=1 size=22.000000 dir=90.000000 hessian=6674.604492 
x=82 y=270 laplacian=-1 size=18.000000 dir=90.000000 hessian=7615.113770 
x=90 y=278 laplacian=-1 size=15.000000 dir=90.000000 hessian=12525.487305 
x=112 y=254 laplacian=1 size=22.000000 dir=90.000000 hessian=8894.154297 
x=273 y=274 laplacian=-1 size=24.000000 dir=90.000000 hessian=16313.005859 
x=154 y=319 laplacian=-1 size=15.000000 dir=90.000000 hessian=9818.360352 
x=172 y=333 laplacian=-1 size=26.000000 dir=90.000000 hessian=8314.745117 
x=137 y=386 laplacian=-1 size=15.000000 dir=90.000000 hessian=9148.833984 
x=140 y=363 laplacian=-1 size=22.000000 dir=90.000000 hessian=7735.985840 

回答

1

你缺少_upright參數,它告訴OpenCV中是否計算角度與否。所以我假設OpenCV決定只是返回90度,如果你沒有指定它。我不記得是否有方法在較舊的cv界面中指定它。在新的cv2接口,但是,它是很容易的:

import cv2 

指定所需SURF參數:

surf_params = {"_hessianThreshold":1000, 
"_nOctaves":4, 
"_nOctaveLayers":2, 
"_extended":1, 
"_upright":0} 

注意,通過upright1總是返回的90角度。

構建SURF-對象和讀取的圖像:

surf = cv2.SURF(**surf_params) 
image = cv2.imread('img.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE) 
(keypoints, descriptors) = surf.detect(image, mask=None, useProvidedKeypoints=False) 

for keypoint in keypoints: 
    x,y = keypoint.pt 
    size = keypoint.size 
    orientation = keypoint.angle 
    response = keypoint.response 
    octave = keypoint.octave 
    class_id = keypoint.class_id 
    print (x,y), size, orientation 

的什麼這返回(X,Y),大小,取向的一個例子:(我使用的是不同的圖像)

(523.3077392578125, 933.419189453125) 156.0 199.023590088 
(1417.82470703125, 957.7914428710938) 166.0 127.772354126 
(1398.8065185546875, 971.0693359375) 165.0 126.83026123 
(1009.0242309570312, 1032.0604248046875) 176.0 164.367050171 

就是這樣。這是我爲什麼總是建議人們切換到更新的cv2界面的衆多原因之一。由於我做了開關,我不必再處理像缺少參數那樣的東西。

我希望這可以幫助你!

+0

運作良好。謝謝您的幫助!它看起來像網上的大多數例子使用cv而不是cv2。任何關於我應該在哪裏瞭解cv2的建議? –

+0

一般而言,我發現這兩者非常相似,只是對於Python用戶來說'cv2'更直觀。您可以參考[文檔](http://docs.opencv.org/modules/core/doc/core.html)或[參考手冊](http://docs.opencv.org/opencv2refman.pdf) ,但大部分時間我只是最終使用谷歌來找到我需要的東西。不幸的是,OpenCV沒有我們想要的那樣完整地記錄下來。 – casper

+0

感謝您的提示。我沒有意識到Python參考手冊中的綁定。這應該會有所幫助。 –

相關問題