How to perform LU-decomposition with OpenCV?

后端 未结 2 1987
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 00:52

The cvInvert() method takes a flag CV_LU that does the LU factorisation to invert an input matrix. However is there any way to obtain the L and U matrices that are formed du

2条回答
  •  盖世英雄少女心
    2021-01-16 01:05

    It is possible to use the function Cholesky() provided by OpenCV (using 2.4.6), see source code of modules\stitching\src\autocalib.cpp. But it needs some scaling to get a comparable result with Matlab:

    Mat chol = mat.clone();
    if (Cholesky(chol.ptr(), chol.step, chol.cols, 0, 0, 0))
    {
        Mat diagElem = chol.diag();
        for (int e = 0; e < diagElem.rows; ++e)
        {
            float elem = diagElem.at(e);
            chol.row(e) *= elem;
            chol.at(e,e) = 1.0f / elem;
        }
    }
    

提交回复
热议问题