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

标签 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

最佳答案

您缺少 _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/

相关文章:

Python pandas 空相关矩阵

opencv - 在 OpenCV 中找到天空/地面分离

python-2.7 - 错误:(-5) 图像为空或函数 cv::SIFT::operator () 中的深度不正确 (!=CV_8U)

OpenCV putText UTF-8 字符

python - 对服装照片进行分类有哪些好的特征?

python - 导入和 reshape MNIST 数据,numpy

python - 使用 ffmpeg-python 将视频分割成图像

Python CSV 阅读器类型错误 : string pattern on bytes object

python - 在一个子像素位置将一个图像补丁插入另一个图像

python - 使用 python 将 CSV 文件转换为 JSON 文件