如何在opencv中指向mat?

时间:2017-12-29 18:20:11

标签: c++ opencv eigen

我编写了以下代码来实现LDA。在此部分代码的末尾,我想通过eigenvaluesOpenCV指针将eigvalue分配给eigenvectorsOpenCVeigvector.data,但即使eigenvaluesOpenCV并且eigenvaluesOpenCV不是NULLeigvectoreigvalue变为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;

}

1 个答案:

答案 0 :(得分:1)

您应该传递uchar **或uchar&amp; *,您需要通过副本传递指针然后修改它们指向的内容。但这并没有转化为功能之外的范围。