Ask Your Question
0

findEssentialMat returns [3x30] or [3x12] Mat

asked 2017-03-26 13:08:33 -0600

ririgo gravatar image

Hi, I tried to use 5 point algorithm to get camera pose. I need [3x3] essential matrix but the cv::findEssentialMat returns [3x30] or [3x12] Mat. The cv::decomposeEssentialMat requires [3x3] Mat so I can't test my code.

Below simple code gives the same 5 2D points to the findEssentialMat and I expected R = identity, and t = 0.

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(){

    vector<Point2f> first_2d_points, second_2d_points;

    for(int i = 0; i < 5; i++){
        first_2d_points.push_back(Point2f(i,i));
        second_2d_points.push_back(Point2f(i,i));
    }

    double focal_length = 600;
    Point2d pricipal_point = Point2d(320, 240);

    Mat essential_matrix = findEssentialMat(first_2d_points,
                        second_2d_points,
                        focal_length,
                        pricipal_point,
                        RANSAC,
                        0.99,
                        2.0);

    cout << essential_matrix.size() << endl;
    cout << essential_matrix << endl;

    cout << endl;

    Mat R1, R2, t;
    decomposeEssentialMat(essential_matrix, R1, R2, t);

    cout << R1 << endl;
    cout << R2 << endl;
    cout << t << endl;

    return 0;
}

This gives me [3x30] Mat as an essential matrix. Below simple code gives [3x12] Mat as an essential matrix.

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(){

    vector<Point2f> first_2d_points, second_2d_points;

    for(int i = 0; i < 5; i++){
        first_2d_points.push_back(Point2f(i,i));
        second_2d_points.push_back(Point2f(i+1,i));
    }

    double focal_length = 600;
    Point2d pricipal_point = Point2d(320, 240);

    Mat essential_matrix = findEssentialMat(first_2d_points,
                        second_2d_points,
                        focal_length,
                        pricipal_point,
                        RANSAC,
                        0.99,
                        2.0);

    cout << essential_matrix.size() << endl;
    cout << essential_matrix << endl;

    cout << endl;

    Mat R1, R2, t;
    decomposeEssentialMat(essential_matrix, R1, R2, t);

    cout << R1 << endl;
    cout << R2 << endl;
    cout << t << endl;

    return 0;
}

What should I do to get a [3x3] essential matrix?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-26 15:25:19 -0600

LBerger gravatar image

It is not possible to find essential matrix using your data. There is result a result 3x30 : [3 x 30]

[-nan(ind), -nan(ind), -nan(ind);
 -nan(ind), -nan(ind), -nan(ind);
 -nan(ind), -nan(ind), -nan(ind);
 3.209083287685636e-17, -0.4082482904638631, -0.4082482904638631;
 ....
]

with an exception :

OpenCV Error: Assertion failed (E.cols == 3 && E.rows == 3) in cv::decomposeEssentialMat, file G:\Lib\opencv\modules\calib3d\src\five-point.cpp, line 648

Now if you have got only five points in each view algorithm used in findEssentialMat is "Nister, An efficient solution to the five-point relative pose problem, PAMI, 2004". It will give you 4 essential matrix. If you want only one essential matrix you will need 8 points (Multiple view geometry R.Hartley- A.Zisserman).

edit flag offensive delete link more

Comments

Thank you for your answer. It works well when I give 8 points to the algorithm as you said. Perhaps I missed some part of that paper. Thank you so much.

ririgo gravatar imageririgo ( 2017-03-26 21:48:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-26 12:57:31 -0600

Seen: 2,460 times

Last updated: Mar 26 '17