为什么跟随EVectors
和EValues
的代码指针是在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;
}
答案 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;
}