mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #20636 from thezane:recoverPoseFromDifferentCameras
Recover pose from different cameras (version 2) * add recoverPose for two different cameras * Address review comments from original PR * Address new review comments * Rename private api Co-authored-by: tompollok <tom.pollok@gmail.com> Co-authored-by: Zane <zane.huang@mail.utoronto.ca>
This commit is contained in:
@@ -2142,7 +2142,17 @@ TEST(CV_RecoverPoseTest, regression_15341)
|
||||
|
||||
// camera matrix with both focal lengths = 1, and principal point = (0, 0)
|
||||
const Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
|
||||
const Mat zeroDistCoeffs = Mat::zeros(1, 5, CV_64F);
|
||||
|
||||
// camera matrix with focal lengths 0.5 and 0.6 respectively and principal point = (100, 200)
|
||||
double cameraMatrix2Data[] = { 0.5, 0, 100,
|
||||
0, 0.6, 200,
|
||||
0, 0, 1 };
|
||||
const Mat cameraMatrix2( 3, 3, CV_64F, cameraMatrix2Data );
|
||||
|
||||
// zero and nonzero distortion coefficients
|
||||
double nonZeroDistCoeffsData[] = { 0.01, 0.0001, 0, 0, 1e-04, 0.2, 0.02, 0.0002 }; // k1, k2, p1, p2, k3, k4, k5, k6
|
||||
vector<Mat> distCoeffsList = {Mat::zeros(1, 5, CV_64F), Mat{1, 8, CV_64F, nonZeroDistCoeffsData}};
|
||||
const auto &zeroDistCoeffs = distCoeffsList[0];
|
||||
|
||||
int Inliers = 0;
|
||||
|
||||
@@ -2158,14 +2168,26 @@ TEST(CV_RecoverPoseTest, regression_15341)
|
||||
|
||||
// Estimation of fundamental matrix using the RANSAC algorithm
|
||||
Mat E, E2, R, t;
|
||||
|
||||
// Check pose when camera matrices are different.
|
||||
for (const auto &distCoeffs: distCoeffsList)
|
||||
{
|
||||
E = findEssentialMat(points1, points2, cameraMatrix, distCoeffs, cameraMatrix2, distCoeffs, RANSAC, 0.999, 1.0, mask);
|
||||
recoverPose(points1, points2, cameraMatrix, distCoeffs, cameraMatrix2, distCoeffs, E2, R, t, RANSAC, 0.999, 1.0, mask);
|
||||
EXPECT_LT(cv::norm(E, E2, NORM_INF), 1e-4) <<
|
||||
"Two big difference between the same essential matrices computed using different functions with different cameras, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask[13]) << "Detecting outliers in function failed with different cameras, testcase " << testcase;
|
||||
}
|
||||
|
||||
// Check pose when camera matrices are the same.
|
||||
E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask);
|
||||
E2 = findEssentialMat(points1, points2, cameraMatrix, zeroDistCoeffs, cameraMatrix, zeroDistCoeffs, RANSAC, 0.999, 1.0, mask);
|
||||
EXPECT_LT(cv::norm(E, E2, NORM_INF), 1e-4) <<
|
||||
"Two big difference between the same essential matrices computed using different functions, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask[13]) << "Detecting outliers in function findEssentialMat failed, testcase " << testcase;
|
||||
"Two big difference between the same essential matrices computed using different functions with same cameras, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask[13]) << "Detecting outliers in function findEssentialMat failed with same cameras, testcase " << testcase;
|
||||
points2[12] = Point2f(0.0f, 0.0f); // provoke another outlier detection for recover Pose
|
||||
Inliers = recoverPose(E, points1, points2, cameraMatrix, R, t, mask);
|
||||
EXPECT_EQ(0, (int)mask[12]) << "Detecting outliers in function failed, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask[12]) << "Detecting outliers in function failed with same cameras, testcase " << testcase;
|
||||
}
|
||||
else // testcase with mat input data
|
||||
{
|
||||
@@ -2185,14 +2207,26 @@ TEST(CV_RecoverPoseTest, regression_15341)
|
||||
|
||||
// Estimation of fundamental matrix using the RANSAC algorithm
|
||||
Mat E, E2, R, t;
|
||||
|
||||
// Check pose when camera matrices are different.
|
||||
for (const auto &distCoeffs: distCoeffsList)
|
||||
{
|
||||
E = findEssentialMat(points1, points2, cameraMatrix, distCoeffs, cameraMatrix2, distCoeffs, RANSAC, 0.999, 1.0, mask);
|
||||
recoverPose(points1, points2, cameraMatrix, distCoeffs, cameraMatrix2, distCoeffs, E2, R, t, RANSAC, 0.999, 1.0, mask);
|
||||
EXPECT_LT(cv::norm(E, E2, NORM_INF), 1e-4) <<
|
||||
"Two big difference between the same essential matrices computed using different functions with different cameras, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask.at<unsigned char>(13)) << "Detecting outliers in function failed with different cameras, testcase " << testcase;
|
||||
}
|
||||
|
||||
// Check pose when camera matrices are the same.
|
||||
E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask);
|
||||
E2 = findEssentialMat(points1, points2, cameraMatrix, zeroDistCoeffs, cameraMatrix, zeroDistCoeffs, RANSAC, 0.999, 1.0, mask);
|
||||
EXPECT_LT(cv::norm(E, E2, NORM_INF), 1e-4) <<
|
||||
"Two big difference between the same essential matrices computed using different functions, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask.at<unsigned char>(13)) << "Detecting outliers in function findEssentialMat failed, testcase " << testcase;
|
||||
"Two big difference between the same essential matrices computed using different functions with same cameras, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask.at<unsigned char>(13)) << "Detecting outliers in function findEssentialMat failed with same cameras, testcase " << testcase;
|
||||
points2.at<Point2f>(12) = Point2f(0.0f, 0.0f); // provoke an outlier detection
|
||||
Inliers = recoverPose(E, points1, points2, cameraMatrix, R, t, mask);
|
||||
EXPECT_EQ(0, (int)mask.at<unsigned char>(12)) << "Detecting outliers in function failed, testcase " << testcase;
|
||||
EXPECT_EQ(0, (int)mask.at<unsigned char>(12)) << "Detecting outliers in function failed with same cameras, testcase " << testcase;
|
||||
}
|
||||
EXPECT_EQ(Inliers, point_count - invalid_point_count) <<
|
||||
"Number of inliers differs from expected number of inliers, testcase " << testcase;
|
||||
|
||||
Reference in New Issue
Block a user