如何创建 SIFT 描述符(图像)数据库?我在 Pyhton 2.7 中使用 OpenCV,我的目的是在支持向量机上实现监督训练集。
到目前为止,这是我的代码,用于 1 张图片
import cv2
import numpy as np
img = cv2.imread('C:\Python27\.Clocktower1.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT()
kp = sift.detect(gray,None)
img=cv2.drawKeypoints(gray,kp)
cv2.imwrite('sift_keypoints.jpg',img)
kp, des = sift.detectAndCompute(gray,None)
cv2.imshow('image',img)
k = cv2.waitKey(0)
if k == 27:
cv2.destroyAllWindows()
elif k == ord('s'):
cv2.destroyAllWindows()
a = np.arange(127*127).reshape(127, 127)
np.set_printoptions(edgeitems=127)
f = open('file.txt','w')
f.write('answer:'+str(des))
f.close()
我在保存包含 kypoint 向量的矩阵 des 时遇到了麻烦,而且我仍然不知道一个函数可以将算法自动化到每个周期超过 1 个图像。
谢谢你
编辑:
输出格式为:
answer:[[ 5. 1. 0. 7. 14. 1. 3. 8. 2. 1. 0. 0.
0. 3. 12. 8. 0. 7. 14. 3. 2. 4. 3. 1.
1. 1. 6. 6. 17. 3. 0. 1. 29. 32. 4. 10.
29. 77. 22. 14. 98. 31. 1. 0. 4. 41. 84. 76.
13. 14. 38. 10. 59. 115. 53. 22. 16. 4. 21. 13.
56. 90. 72. 31. 45. 19. 7. 3. 10. 89. 85. 46.
115. 12. 2. 6. 16. 27. 115. 103. 55. 3. 4. 20.
115. 101. 15. 29. 113. 8. 16. 40. 33. 53. 61. 47.
65. 16. 0. 0. 5. 24. 90. 86. 8. 0. 8. 47.
63. 33. 67. 51. 6. 1. 19. 64. 89. 73. 36. 18.
21. 8. 60. 115. 31. 58. 11. 8.] ...
(other 128-numbers vectors)
为了限制我在输出中获得的关键点数量,我需要选择 n 个最佳描述符;有实现吗?
最佳答案
SIFT 可以采用一个参数来说明要保留的最佳特征的数量
当你实例化 SIFT 时,你应该这样做
筛选 = cv2.SIFT(n)
引用
http://docs.opencv.org/trunk/modules/nonfree/doc/feature_detection.html
关于python - 如何[使用 Python] 创建 SIFT 的描述符数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20388774/