-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathransac_test.cc
103 lines (75 loc) · 2.75 KB
/
ransac_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#define _USE_MATH_DEFINES
#include <Eigen/Dense>
#include <Eigen/Geometry>
#include <limits>
#include <RansacLib/ransac.h>
#include <time.h>
#include <cmath>
#include <iostream>
#include <numeric>
#include "radialpose.h"
#include "misc/ransac_estimator.h"
#include "misc/unit_test_misc.h"
bool test_simple_ransac_no_outliers() {
Matrix<double, 2, Dynamic> x;
Matrix<double, 3, Dynamic> X;
Camera pose_gt;
std::vector<double> params2 = { -0.12, 0.034 };
larsson_iccv19::Solver<2, 0, true> estimator;
generate_scene_and_image(100, 2, 20, 70, false, &pose_gt, &x, &X, 1.0);
add_rational_distortion(params2, 2, 0, &pose_gt, &x);
add_focal(2000.0, &pose_gt, &x);
add_noise(0.5, &x);
RansacEstimator<larsson_iccv19::Solver<2, 0, true>> solver(x, X, estimator);
ransac_lib::LORansacOptions options;
options.squared_inlier_threshold_ = 4;
ransac_lib::LocallyOptimizedMSAC<Camera,
std::vector<Camera>,
RansacEstimator<larsson_iccv19::Solver<2, 0, true>>> lomsac;
ransac_lib::RansacStatistics ransac_stats;
Camera best_model;
int num_ransac_inliers = lomsac.EstimateModel(options, solver, &best_model, &ransac_stats);
std::cout << " ... LOMSAC found " << num_ransac_inliers
<< " inliers in " << ransac_stats.num_iterations
<< " iterations with an inlier ratio of "
<< ransac_stats.inlier_ratio << std::endl;
return (ransac_stats.inlier_ratio > 0.99);
}
bool test_simple_ransac_some_outliers() {
Matrix<double, 2, Dynamic> x;
Matrix<double, 3, Dynamic> X;
Camera pose_gt;
std::vector<double> params2 = { -0.12, 0.034 };
larsson_iccv19::Solver<2, 0, true> estimator;
generate_scene_and_image(100, 2, 20, 70, false, &pose_gt, &x, &X, 1.0);
add_rational_distortion(params2, 2, 0, &pose_gt, &x);
add_focal(2000.0, &pose_gt, &x);
add_noise(1.0, &x);
for (int i = 0; i < 20; ++i) {
Vector2d n; n.setRandom(); n *= 0.2 * pose_gt.focal;
x.col(i) += n;
}
RansacEstimator<larsson_iccv19::Solver<2, 0, true>> solver(x, X, estimator);
ransac_lib::LORansacOptions options;
options.squared_inlier_threshold_ = 4;
ransac_lib::LocallyOptimizedMSAC<Camera,
std::vector<Camera>,
RansacEstimator<larsson_iccv19::Solver<2, 0, true>>> lomsac;
ransac_lib::RansacStatistics ransac_stats;
Camera best_model;
int num_ransac_inliers = lomsac.EstimateModel(options, solver, &best_model, &ransac_stats);
std::cout << " ... LOMSAC found " << num_ransac_inliers
<< " inliers in " << ransac_stats.num_iterations
<< " iterations with an inlier ratio of "
<< ransac_stats.inlier_ratio << std::endl;
return (ransac_stats.inlier_ratio > .79);
}
int main() {
std::cout << "Running tests...\n\n";
srand((unsigned int)time(0));
//srand(2.0);
int passed = 0;
int num_tests = 0;
TEST(test_simple_ransac_no_outliers);
TEST(test_simple_ransac_some_outliers);
}