java opencv surf_opencv python SURF

理论

在上一章中,我们看到了SIFT的关键点检测和描述,但它相对较慢,人们需要更加快速的版本,所以2006年引入了一种名为SURF的新算法, 顾名思义,它是SIFT的加速版本.

作为尺度不变特征变换(SIFT)算法的加速版,SURF算法在适中的条件下完成两幅图像中物体的匹配基本实现了实时处理,其快速的基础实际上只有一个——积分图像haar求导.

SURF算法原理:

构建Hessian矩阵构造高斯金字塔尺度空间

利用非极大值抑制初步确定特征点

精确定位极值点

选取特征点的主方向

构造surf特征点描述算子

OpenCV中的SURF

import numpy as np

import cv2

img = cv2.imread('img.jpg')

# Create SURF object. You can specify params here or later.

# Here I set Hessian Threshold to 400

surf = cv2.xfeatures2d.SURF_create(400)

# Find keypoints and descriptors directly

kp, des = surf.detectAndCompute(img,None)

print(len(kp))

output:3477

# Check present Hessian threshold

print( surf.getHessianThreshold() )

output:400.0

# We set it to some 50000. Remember, it is just for representing in picture.

# In actual cases, it is better to have a value 300-500

surf.setHessianThreshold(50000)

#Again compute keypoints and check its number.

kp, des = surf.detectAndCompute(img,None)

print( len(kp) )

output:2

img2 = cv2.drawKeypoints(img,kp,None,(255,0,0),4)

plt.imshow(img2),plt.show()

33ceb8a5b02a704a8154d07ae13ec9e3.png

# Check upright flag, if it False, set it to True

print( surf.getUpright() )

output:False

surf.setUpright(True)

# Recompute the feature points and draw it

kp = surf.detect(img,None)

img2 = cv2.drawKeypoints(img,kp,None,(255,0,0),4)

plt.imshow(img2),plt.show()

53d246d1e132628b240a912ab9c07bac.png

比之前更快了

# Find size of descriptor

print( surf.descriptorSize() )

output: 64

# That means flag, "extended" is False.

surf.getExtended()

output: False

# So we make it to True to get 128-dim descriptors.

surf.setExtended(True)

kp, des = surf.detectAndCompute(img,None)

print( surf.descriptorSize() )

print( des.shape )

output:

128

(2, 128)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值