为什么uchar *指向mat的指针变为null?

时间:2017-12-30 17:41:37

标签: c++ opencv eigen

为什么跟随EVectorsEValues的代码指针是在main函数还是在MYLDA函数中变为null?以及如何解决它?

void main()
    {
      // some code
      Mat EVectors;
      Mat EValues;
      uchar* pEVectors = EVectors.data;
      uchar* pEValues = EValues.data;          
      MYLDA(train_labels, train_data, pEVectors, pEValues);
      // some code
    }

void MYLDA(vector<int> gnd, Mat_<float> _data, uchar* eigvector, uchar* eigvalue)
    {
      // some code
      GeneralizedEigenSolver<MatrixXf> ges;  
      ges.compute(DPrime, WPrime);    
      MatrixXcf eigenvectorsInEigen = ges.eigenvectors();      
      VectorXcf eigenvaluesInEigen = ges.eigenvalues();  
      Mat eigenvectorsOpenCV(eigenvectorsInEigen.rows(), 
      eigenvectorsInEigen.cols(), CV_32FC1, eigenvectorsInEigen.data());
      eigvector = eigenvectorsOpenCV;      
      Mat eigenvaluesOpenCV(eigenvaluesInEigen.rows(), 
      eigenvaluesInEigen.cols(), CV_32FC1, eigenvaluesInEigen.data());
      eigvalue = eigenvaluesOpenCV;   
    }

1 个答案:

答案 0 :(得分:0)

解决此问题的一种方法是:

    void main()
    {
      // some code
      Mat EVectors;
      Mat EValues;

      MYLDA(train_labels, train_data, &EVectors, &EValues);
      // some code
    }

void MYLDA(vector<int> gnd, Mat_<float> _data, Mat* eigvector, MAt* eigvalue)
    {
      // some code
      *eigvector = eigenvectorsOpenCV;      

      *eigvalue = eigenvaluesOpenCV;   
    }