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?

edit retag close merge delete

1
1

@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 :

for( i = 0; i < m; i++ )
L[i*astep + i]=1/L[i*astep + i];
3

Some complementary information:

• the correct result should be this (with A = L'L here)
• there is another Cholesky function here
• there is an online compiler 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 !

Sort by » oldest newest most voted

@Eduardo thanks. with link to other cholesky decomposition in opencv result is good. Issue is necessary...

more

Stats

Asked: 2016-08-07 08:44:54 -0500

Seen: 542 times

Last updated: Aug 08 '16