2016-05-03 7 views
1

Hintergrund komprimieren: sagen, ich habe bereits eine PCA in Python mit PCACompute trainiert wie folgt:Wie einzelnes Array mit Python OpenCV cv2.PCAProject

import numpy as np 
import cv2 as cv 

# generate some random data 
data = np.random.sample(128) 
for x in xrange(63): data = np.vstack((data, np.random.sample(128))) 
print data.shape # (64, 128) i.e. 64 arrays of 128 dimensions 

# train the PCA 
mean, eigenvectors = cv.PCACompute(data, maxComponents=32) 
print mean.shape # (1, 128) 
print eigenvectors.shape # (32, 128) 

Problem: jetzt habe ich ein einzelnes Array, die ich komprimieren möchten die PCA mit

sample = np.random.sample(128) 
print sample.shape # (128,) 

compressed_sample = cv.PCAProject(sample, mean, eigenvectors) 

OpenCV Error: Assertion failed (mean.data && eigenvectors.data && ((mean.rows == 1 && mean.cols == data.cols) || (mean.cols == 1 && mean.rows == data.rows)))

Antwort

1

Lösung: nach dieser Eingabe heraus, dass ich es gelöst, kann auf der Post, falls jemand auch tragen läuft sonst in der gleichen Ausgabe.

sample = sample.reshape((1,128)) 
compressed_sample = cv.PCAProject(sample, mean, eigenvectors)