简体   繁体   English

用 Python 在 CSV 文件中编写筛选关键点

[英]Writing Sift Key-Points in CSV file in Python

I want to get the values of KP in CSV file to get to the gather multiple feature values into the machine learning classifier我想在 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 Spyder 输出屏幕

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM