在 Python 中将 Sift 关键点写入 CSV 文件

Writing Sift Key-Points in CSV file in Python

我想获取 CSV 文件中的 KP 值,以便将多个特征值收集到机器学习分类器中

import cv2
img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
sift = cv2.xfeatures2d.SIFT_create(400)
kp = sift.detect(img,None)
img = cv2.drawKeypoints(img, kp, None)
cv2.imshow("",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import csv
with open('f:/sift.csv', 'w') as f:
        writer = csv.writer(f)
        writer.writerow(['sift'])
        writer.writerows(kp)

Spyder output screen

import cv2
import csv
path = 'an image.jpg'
im=cv2.imread(path)
gr=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
d = cv2.xfeatures2d.SIFT_create(500)
kp=d.detect(gr)
gr = cv2.drawKeypoints(gr, kp, None)
cv2.imshow("Sift",gr)
cv2.waitKey(0)
cv2.destroyAllWindows()
index = []
for point in kp:
    temp = (point.pt, point.size, point.angle, point.response, point.octave,point.class_id)
    index.append(temp)
with open('c:/sift.csv', 'w') as myfile:
     wr = csv.writer(myfile)
     wr.writerows(index)