Evet, PCA + SVM yapabilirsin, bazıları PCA'nın kullanmanın en iyi özelliği olmadığını veya SVM'nin en iyi sınıflandırma algoritması olmadığını iddia edebilir. Ama hey, iyi bir başlangıç yapmak etrafta oturmaktan daha iyidir.
(Sana az önce bir fikir edinmek için, kodları doğrulamadıysanız), OpenCV ile PCA yapmak gibi bir şey denemek için:
import os
import cv2
import numpy as np
# Construct the input matrix
in_matrix = None
for f in os.listdir('dirpath'):
# Read the image in as a gray level image. Some modifications
# of the codes are needed if you want to read it in as a color
# image. For simplicity, let's use gray level images for now.
im = cv2.imread(os.path.join('dirpath', f), cv2.IMREAD_GRAYSCALE)
# Assume your images are all the same size, width w, and height h.
# If not, let's resize them to w * h first with cv2.resize(..)
vec = im.reshape(w * h)
# stack them up to form the matrix
try:
in_matrix = np.vstack((in_matrix, vec))
except:
in_matrix = vec
# PCA
if in_matrix is not None:
mean, eigenvectors = cv2.PCACompute(in_matrix, np.mean(in_matrix, axis=0).reshape(1,-1))