Ja, Sie können PCA + SVM machen, einige könnten argumentieren, dass PCA nicht die beste Funktion ist, oder SVM ist nicht der beste Klassifikationsalgorithmus. Aber hey, ein guter Anfang ist besser als herumzusitzen.
zu tun PCA mit OpenCV, versuchen Sie so etwas wie (ich habe die Codes nicht überprüft, nur um Ihnen eine Vorstellung zu bekommen):
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))