ExtractSURF始终返回相同的方向

时间:2012-11-11 07:23:33

标签: python opencv computer-vision

我只是想开始学习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

1 个答案:

答案 0 :(得分:1)

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

import cv2

指定所需的SURF参数:

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

请注意,将upright作为1传递将始终返回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界面的众多原因之一。自从我进行切换后,我不再需要处理丢失参数之类的东西了。

我希望这可以帮到你!