项目需要SURF算法作为相似度判别时
因SURF中detecetAndCompute阶段时间过长
故先将特征点保存后再使用时直接调用即可
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 14 14:56:27 2019
@author: jwjiang
"""
import cv2
import numpy as np
inputImgPath = 'C:\\Users\\jwjiang\\Desktop\\Python\\pythonFile\\similar_sift\\1.jpg'
outputImgPath = 'C:\\Users\\jwjiang\\Desktop\\Python\\pythonFile\\similar_sift\\results\\1.txt'
# featureSun:计算特征点个数
featureSum = 0
img = cv2.imread(inputImgPath)
gray = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
detector = cv2.xfeatures2d.SURF_create(200)
# 找到关键点
kps , des = detector.detectAndCompute(gray,None)
# 绘制关键点
img=cv2.drawKeypoints(gray,kps,img)
# 将特征点保存
np.savetxt(outputImgPath ,des , fmt='%.5e')
featureSum += len(kps)
cv2.imshow('result',img)
print('kps:' + str(featureSum))
有问题欢迎留言提问讨论