我正在使用CImg和Eigen库进行面部识别项目。我有一切(看似)正在工作,直到我生成特征值向量。然后所有值都相同(-6.27744e + 066),这显然是不正确的。 MSVS 2013 Pro中的代码如下:
int _tmain(int argc, _TCHAR* argv[])
{
CImgList<unsigned char> init_faces;
CImg<float> avg_face;
CImgList<float> face_diffs;
//Code for reading in face images, creating the average image
//and creating the difference images
CImg<double> covariance_matrix(face_diffs.size(), face_diffs.size());
Eigen::MatrixXcd cov_matrix(face_diffs.size(), face_diffs.size());
//Compute covariance matrix using the pictures that show the
//difference from each input from the average
compute_covariance(face_diffs, covariance_matrix);
//convert the matrix from a CImg to an Eigen readable matrix
convert_eigenlib(covariance_matrix, cov_matrix);
//create EigenSolver object, passing the covariance matrix
Eigen::ComplexEigenSolver<Eigen::MatrixXcd> eig_solve(cov_matrix);
//compute the eigenvalues of the covariance matrix
Eigen::VectorXcd eig_vals = eig_solve.eigenvalues();
//This line produces a 25 element long vector of eigenvalues,
//all of which are: -6.27744e+066
cout << "Eigenvalues:" << endl << eig_vals << endl;
return 0;
}
void compute_covariance(CImgList<float> face_diffs, CImg<double> &covariance_matrix)
{
CImgList<float> transpose;
float temp = 0;
for (unsigned int i = 0; i < face_diffs.size(); i++)
{
transpose.insert(face_diffs(i).get_transpose());
}
transpose.display();
for (unsigned int x = 0; x < face_diffs.size(); x++)
{
for (unsigned int y = 0; y < face_diffs.size(); y++)
{
covariance_matrix(x, y, 0, 0) = transpose(x).dot(face_diffs(y));
}
}
}
void convert_eigenlib(CImg<double> covariance_matrix, Eigen::MatrixXcd &cov_matrix)
{
for (int x = 0; x < covariance_matrix.width(); x++)
{
for (int y = 0; y < covariance_matrix.height(); y++)
{
cov_matrix(y, x) = covariance_matrix(x, y, 1, 1);
}
}
}
我认为我的问题包含在显示的2个用户定义函数之一中,因为每个其他步骤都会给出预期的输出。