PCACompute Opencv 返回特征向量 = 0

发布于 2025-01-01 22:27:46 字数 1147 浏览 1 评论 0原文

Android Opencv2.3.1 中的 PCACompute 有这个问题,因为当我调用 PCACompute 时,我的特征向量都是 0。所以,我为每个人拍了 10 张照片,并将其保存到 100X100 的 Mat 中。 之后,我使用以下代码将我的 100X100 Mat 转换为一个 Mat 1X10000:

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 张照片时,我使用以下代码将照片的所有 Mat 插入到一个 Mat 中:

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:`

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

所以,datiOriginali是10行10000列的输入Mat,均值和特征向量是输出矩阵。平均矩阵给我一个结果,但特征向量给我全0。你能帮我解决这个问题吗? 提前致谢。MArco

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2025-01-08 22:27:46

我的代码基于 http://www.bytefish.de/blog/pca_in_opencv 上的示例。
我是这样做的:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文