解决OpenCV中SIFT,SURF不能使用,修改成ORB检测特征

 我们知道因为一些专利的原因,SIFT和SURF不能再OpenCV后续的版本中继续使用。所以我们可以用OpenCV自带的其他检测器:Oriented FAST and Rotated BRIEF。引用官网的话:This algorithm was brought up by Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary R. Bradski in their paper ORB: An efficient alternative to SIFT or SURF in 2011. As the title says, it is a good alternative to SIFT and SURF in computation cost, matching performance and mainly the patents. 

我们可以修改以前的sift生成器,代码如下:

import numpy as np
import cv2 as cv
img = cv.imread('severalpolygons.png')
gray= cv.cvtColor(img,cv.COLOR_BGR2GRAY)

#建立SIFT生成器
#sift = cv.xfeatures2d.SIFT_create()
#ORB修改成
orb=cv.ORB_create()

#计算描述子
#kp = sift.detect(gray,None)
#修改成
kp=orb.detect(gray,None)

#如果要计算
#(kps,features)=sift.detectAndCompute(image,None)
#修改成
(kps,features)=orb.compute(image,kp)
#或者直接修改成
(kps,features)=orb.detectAndCompute(image,None)

#展示图片
img=cv.drawKeypoints(gray,kp,img)
#cv.imshow('sift_keypoints.jpg',img)
cv.imshow('orb_keypoints.jpg',img)
cv.waitKey(0)

猜你喜欢

转载自blog.csdn.net/weixin_40244676/article/details/104329284
今日推荐