2016-03-25 4 views
0

Ich entwickle eine Bildklassifizierer svm.In die Merkmalextraktionsphase mit i PKA als feature.How verwenden können, das PKA eines Bildes mit Python zu finden und opencv.what mein Plan istWie finde ich den Pca eines Bildes mit Python und Opencv?

  1. Suche pca jeder Bild in Trainingssatz und speichern sie in einem array.It kann Liste von Listen
  2. Shop Klasse Etiketten in einer anderen Liste
  3. Pass dies als Argument SVM

bin ich richtig Direction.Please Hilfe gehen Ich

Antwort

1

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))  
Verwandte Themen