Cholesky function in opencv
Hi,
I want to have choelsky decomposition of a matrix. In opencv doc is here and I think this doc is still good. In following program I try to have cholesky decomposition of matrix A
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main (int argc,char **argv)
{
Mat m1=(Mat_<double>(3,3) << 4,12,-16,12,37,-43,-16,-43,98);
cout<<m1<<endl;
Cholesky ((double*)m1.ptr(),m1.cols*8, 3,NULL, 0, 0);
m1.at<double>(0,1)=0;m1.at<double>(0,2)=0;m1.at<double>(1,2)=0;
cout<<"L = "<<m1<<endl;
cout<<"L' = "<<m1.t()<<endl;
cout << "LL'="<<m1*m1.t()<<endl;
}
Result is
A=[4, 12, -16; 12, 37, -43; -16,
-43, 98]
L = [0.5, 0, 0; 6, 1, 0; -8, 5, 0.3333333333333333] L' = [0.5, 6, -8; 0, 1, 5; 0, 0,
0.3333333333333333]
LL'=[0.25, 3, -4; 3, 37, -43; -4, -43,
89.11111111111111] <> A
Is it a bug or I miss something?
shouldn't
LL'
be a matrix mult (*
) ?Oops! I change source code
@berak have you got HAL with your opencv ? If yes can you test previous program. It should give result whithHAL implementation. I think some lines are missing matrix_decomp.cpp :
Some complementary information:
A = L'L
here)unfortunately, i'm confused, which path it takes no my machine. hal only seems to bind lapack functions (which i don't have)
i tried to copypasta CholImpl, which gives exactly the same results as above (so i guess, my box is using this.) , and your fix seems to work there !