Ask Your Question
2

Cholesky function in opencv

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

LBerger gravatar image

updated 2016-08-08 02:30:51 -0500

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 flag offensive close merge delete

Comments

1

shouldn't LL' be a matrix mult (*) ?

berak gravatar imageberak ( 2016-08-07 09:20:16 -0500 )edit
1

Oops! I change source code

LBerger gravatar imageLBerger ( 2016-08-07 09:43:06 -0500 )edit

@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];
LBerger gravatar imageLBerger ( 2016-08-07 11:07:41 -0500 )edit
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
Eduardo gravatar imageEduardo ( 2016-08-07 19:40:09 -0500 )edit

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 !

berak gravatar imageberak ( 2016-08-08 02:36:15 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-08-08 02:19:38 -0500

LBerger gravatar image

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

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 529 times

Last updated: Aug 08 '16