Matx33d 点产品在 OpenCV 中不起作用

Matx33d dot product not working in OpenCV

本文关键字:OpenCV 不起作用 Matx33d      更新时间:2023-10-16

我的print函数定义为:

void print(std::string matname, cv::Matx33d A) {
    fprintf(stdout, "%s = [n", matname.c_str());
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            fprintf(stdout, "%15.10lf", A(i,j));
        }   
        fprintf(stdout, "n");
    }   
    fprintf(stdout, "];n");
}

我设计了一个矩阵H并在以下代码中使用它:

print("H", H); 
cv::Matx33d Hinv = H.inv();
print("H^-1", Hinv);
cv::Matx33d HdHinv(H.ddot(Hinv));
print("H*H^-1", HdHinv);
cv::Matx33d HinvdH(Hinv.ddot(H));
print("H^-1*H", HinvdH);

但是,输出如下所示:

H = [
   0.0386192492   0.1756336675   0.0245675072
   0.1756336675   1.3649487597  -0.2727645303
   0.0245675072  -0.2727645303  -0.5635269575
];
H^-1 = [
  45.9140372920  -5.0221718200   4.4325541956
  -5.0221718200   1.2173491959  -0.8081812555
   4.4325541956  -0.8081812555  -1.1901116767
];
H*H^-1 = [
   3.0000000000   0.0000000000   0.0000000000
   0.0000000000   0.0000000000   0.0000000000
   0.0000000000   0.0000000000   0.0000000000
];
H^-1*H = [
   3.0000000000   0.0000000000   0.0000000000
   0.0000000000   0.0000000000   0.0000000000
   0.0000000000   0.0000000000   0.0000000000
];

相反似乎确实工作正常,但是为什么我从点积中得到这些值?我是否使用ddot不正确?我已经在Matlab中测试了这个点积,我得到了单位矩阵(精度高达 10 位小数(,所以我相信HHinv是正确生成的。

"点积" != "矩阵乘法"。事实上,cv::Matx33d::ddot ()甚至不返回矩阵,而是返回标量。我还没有尝试过,但可能operator*会按照你的意图去做——就像这样:

cv::Matx33d HdHinv = H * Hinv;