Matlab中两个协方差矩阵A和B的黎曼距离计算:
C = sqrt(sum(log(eig(A,B)).^2))
OpenCV与C ++的等价物是什么?
答案 0 :(得分:2)
现在我得到的结果与Matlab相同。遵循我的C ++解决方案:
double calculateRiemannianDistance(cv::Mat A, cv::Mat B) {
Eigen::MatrixXf e_A, e_B;
cv::cv2eigen(A, e_A);
cv::cv2eigen(B, e_B);
/* compute generalized eigenvalues */
Eigen::GeneralizedEigenSolver<Eigen::MatrixXf> ges;
ges.compute(e_A, e_B);
cv::Mat gev;
cv::eigen2cv(Eigen::MatrixXf(ges.eigenvalues().real()), gev);
/* riemannian distance */
cv::Mat partial_res;
cv::log(gev, partial_res);
cv::pow(partial_res, 2, partial_res);
double distance = sqrt(cv::sum(partial_res)[0]);
return distance;
}