Saya ingin mendapatkan nilai KP dalam file CSV untuk mengumpulkan beberapa nilai fitur ke dalam pengklasifikasi pembelajaran mesin

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)

Layar keluaran Spyder

1
Bareq Raad 4 November 2020, 20:28

1 menjawab

Jawaban Terbaik
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)
0
Bareq Raad 12 Desember 2020, 10:39