我编写了以下代码来实现LDA
。在此部分代码的末尾,我想通过eigenvaluesOpenCV
指针将eigvalue
分配给eigenvectorsOpenCV
和eigvector
到.data
,但即使eigenvaluesOpenCV
并且eigenvaluesOpenCV
不是NULL
,eigvector
和eigvalue
变为NULL
。为什么会发生这种情况以及如何解决这个问题?
void main()
{
.
.
.
uchar* EVectors = NULL;
uchar* EValues = NULL;
MYLDA(train_labels, train_data, EVectors, EValues);
.
.
.
}
void MYLDA(vector<int> gnd, Mat_<float> _data, uchar* eigvector, uchar* eigvalue)
{
.
.
.
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());
uchar* mPtr = new uchar[eigenvectorsOpenCV.total()];
memcpy(mPtr, eigenvectorsOpenCV.data, eigenvectorsOpenCV.total());
eigvector = mPtr;
Mat eigenvaluesOpenCV(eigenvaluesInEigen.rows(),
eigenvaluesInEigen.cols(), CV_32FC1, eigenvaluesInEigen.data());
uchar* nPtr = new uchar[eigenvaluesOpenCV.total()];
memcpy(mPtr, eigenvaluesOpenCV.data, eigenvaluesOpenCV.total());
eigvalue = nPtr;
}
答案 0 :(得分:1)
您应该传递uchar **或uchar&amp; *,您需要通过副本传递指针然后修改它们指向的内容。但这并没有转化为功能之外的范围。