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?