# PCACompute Opencv devuelve autovectores = 0

have this problem with PCACompute in Android Opencv2.3.1 because when i call PCACompute my eigenvectors are all 0. So, i take 10 photos for each people and i save it into a Mat of 100X100. After that, i convert my 100X100 Mat in one Mat 1X10000 with this code:

``````double [] elem = null;
for(int riga=0;riga<m.rows();riga++)
{
for(int colonna=0;colonna<m.cols();colonna++)
{
elem = m.get(riga, colonna);
mrow.put(0,((riga*100)+colonna), elem[0]);
}//for colonna
}//for riga
``````

After that, when i take 10 photos, i insert all Mat of the photos into one mat with this code:

``````double b[] = null;
for (int i = 0; i< listafoto.size(); i++)
{
Mat t = listafoto.get(i);
for(int riga = 0;riga<t.rows();riga++)
{
for(int colonna =0;colonna<t.cols();colonna++)
{
b = t.get(riga, colonna);
datiOriginali.put(i, colonna, b[0]);
}//for colonna
}//for riga
}//for lista e contemporaneamente riga datiOriginali
``````

After that, i call PCACompute with this code: `

`````` org.opencv.core.Core.PCACompute(datiOriginali,mean, eigenvectors, 10);`
``````

So, datiOriginali is the input Mat of 10 rows and 10000 cols, mean and eigenvectors are the output matrix. mean matrix give me a result, but eigenvectors give me all 0. Can you help me to resolve this problem? Thanks in advance.MArco

preguntado el 02 de febrero de 12 a las 10:02

## 1 Respuestas

I based my code on the example at http://www.bytefish.de/blog/pca_in_opencv. Here's how I did this:

``````    Vector trainingImages = new Vector();;
trainingImages.add(Highgui.imread("/sdcard/facedatabase/s1/1.pgm",0));
trainingImages.add(Highgui.imread("/sdcard/facedatabase/s1/2.pgm",0));

Mat x = (Mat) trainingImages.get(0);
int total = x.rows() * x.cols();

// build matrix (column)
// This matrix will have one col for each image and imagerows x imagecols rows
Mat mat = new Mat(total, trainingImages.size(), CvType.CV_32FC1);
for(int i = 0; i < trainingImages.size(); i++) {
Mat X = mat.col(i);
Mat c = (Mat) trainingImages.get(i);
c.reshape(1,total).convertTo(X, CvType.CV_32FC1);
}

Mat eigenVectors = new Mat();
Mat mean = new Mat();
Core.PCACompute(mat, mean, eigenVectors);
``````

Respondido 17 Feb 12, 01:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.