PCACompute opencv的回报特征向量= 0 [英] PCACompute Opencv return eigenvectors = 0

查看:1095
本文介绍了PCACompute opencv的回报特征向量= 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这个问题,PCACompute Android中Opencv2.3.1,因为当我打电话PCACompute我的特征向量都是0,所以,我把10张照片的每个人,我把它保存为100X100的垫。
在那之后,我转换我100X100垫一垫1X10000这个code:

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

在此之后,当我把10张照片,我插入的照片都垫到一个垫子与此code:

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

在这之后,我叫PCACompute这个code:`

After that, i call PCACompute with this code: `

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

所以,datiOriginali是10行和10000 COLS输入垫,平均值和特征向量是输出矩阵。意味着矩阵给我一个结果,但特征向量给我所有0你能帮我解决这个问题?
谢谢advance.MArco

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

推荐答案

我根据我的$ C $上的​​ http://www.bytefish.de/blog/pca_in_opencv
以下是我做:

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);

这篇关于PCACompute opencv的回报特征向量= 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆