gpt4 book ai didi

python - ExtractSURF 总是返回相同的方向

转载 作者:行者123 更新时间:2023-12-02 17:53:32 26 4
gpt4 key购买 nike

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

最佳答案

您缺少 _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 的众多原因之一。界面。自从我进行了切换,我就不必再处理诸如缺少参数之类的事情了。

我希望这可以帮助你!

关于python - ExtractSURF 总是返回相同的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13329357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com