opencv error Assertion failed Mat.cpp line: 537

218 views Asked by At

I am trying to find the eigenvalues and eigenvectors a matrix as shown below:

int m = 5;

float b[5][5] = {
    { 1.96 , -6.49, -0.47, -7.20, -0.65},
    { -6.49,  3.80, -6.39,  1.50, -6.34},
    { -0.47, -6.39,  4.17, -1.51,  2.67},
    { -7.20,  1.50, -1.51,  5.70,  1.80},
    { -0.65, -6.34,  2.67,  1.80, -7.10}
    };

    cv::Mat E, V;
    cv::Mat M(m,m,CV_64FC1,b);
    cv::eigen(M,E,V);

    // eigenvalues sorted desc
    for(int i=0; i < 5; i++)
        std::cout << E.at<float>(0,i) << " \t";
1

There are 1 answers

2
Oliver Wilken On

That works for me:

int m = 5;

double b[5][5] = {
    { 1.96 , -6.49, -0.47, -7.20, -0.65},
    { -6.49,  3.80, -6.39,  1.50, -6.34},
    { -0.47, -6.39,  4.17, -1.51,  2.67},
    { -7.20,  1.50, -1.51,  5.70,  1.80},
    { -0.65, -6.34,  2.67,  1.80, -7.10}
    };

    cv::Mat E, V;
    cv::Mat M(m,m,CV_64FC1,b);

    cout << "M: " << M << endl;

    cv::eigen(M,E,V);

    cout << "E: " << E << endl;
    cout << "V: " << V << endl;

The problem is that "CV_64FC1" is double not float (check CV-types here).