0

我只是想开始学习 OpenCV。我的理解是 ExtractSURF 应该返回 0 到 360 之间的角度。出于某种原因,关键点总是为我返回 90 的方向。任何想法为什么?

这段代码:

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
4

1 回答 1

1

您缺少_upright参数,该参数告诉 OpenCV 是否计算角度。所以我假设如果你不指定 OpenCV 决定只返回 90 度。我不记得是否有办法在旧cv界面中指定它。然而,在较新的cv2界面中,这很容易:

import cv2

指定所需的 SURF 参数:

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

请注意,传递uprightas1将始终返回角度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这是我总是建议人们切换到较新界面的众多原因之一。自从我进行了切换,我就不必再处理诸如缺少参数之类的事情了。

我希望这可以帮助你!

于 2012-11-12T17:50:43.053 回答