34 | opengv::sac::MultiSampleConsensus::MultiSampleConsensus(
35 | int maxIterations,
36 | double threshold,
37 | double probability) :
38 | max_iterations_(maxIterations),
39 | threshold_(threshold),
40 | probability_(probability)
41 | {}
42 |
43 | template
44 | opengv::sac::MultiSampleConsensus::~MultiSampleConsensus()
45 | {}
46 |
--------------------------------------------------------------------------------
/third_party/opengv/include/opengv/sac/implementation/SampleConsensus.hpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Authors: Laurent Kneip & Paul Furgale *
3 | * Contact: kneip.laurent@gmail.com *
4 | * License: Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved. *
5 | * *
6 | * Redistribution and use in source and binary forms, with or without *
7 | * modification, are permitted provided that the following conditions *
8 | * are met: *
9 | * * Redistributions of source code must retain the above copyright *
10 | * notice, this list of conditions and the following disclaimer. *
11 | * * Redistributions in binary form must reproduce the above copyright *
12 | * notice, this list of conditions and the following disclaimer in the *
13 | * documentation and/or other materials provided with the distribution. *
14 | * * Neither the name of ANU nor the names of its contributors may be *
15 | * used to endorse or promote products derived from this software without *
16 | * specific prior written permission. *
17 | * *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21 | * ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE *
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
28 | * SUCH DAMAGE. *
29 | ******************************************************************************/
30 |
31 | //Note: has been derived from ROS
32 |
33 | template
34 | opengv::sac::SampleConsensus::SampleConsensus(
35 | int maxIterations, double threshold, double probability) :
36 | max_iterations_(maxIterations),
37 | threshold_(threshold),
38 | probability_(probability)
39 | {}
40 |
41 | template
42 | opengv::sac::SampleConsensus::~SampleConsensus(){}
43 |
--------------------------------------------------------------------------------
/third_party/opengv/manifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | opengv
5 |
6 |
7 | Laurent Kneip
8 | FreeBSD
9 |
10 | http://ros.org/wiki/opengv
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/benchmark_absolute_pose_execution_times.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % central case -> only one camera
11 | cam_number = 1;
12 | % let's only get 6 points, and generate new ones in each iteration
13 | pt_number = 50;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 iterations
17 | iterations = 1000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'p2p'; 'p3p_kneip'; 'p3p_gao'; 'epnp'; 'upnp' };
21 | % This defines the number of points used for every algorithm
22 | indices = { [1, 2]; [1, 2, 3]; [1, 2, 3]; [1:1:50]; [1:1:50] };
23 | % The name of the algorithms on the plots
24 | names = { 'P2P'; 'P3P (Kneip)'; 'P3P (Gao)'; 'EPnP (50pts)'; 'UPnP (50pts)'};
25 |
26 | % The noise in this experiment
27 | noise = 1.0;
28 |
29 | %% Run the benchmark
30 |
31 | %prepare the overall result array
32 | num_algorithms = size(algorithms,1);
33 | execution_times = zeros(num_algorithms,iterations);
34 | counter = 0;
35 |
36 | for i=1:iterations
37 |
38 | % generate experiment
39 | [points,v,t,R] = create2D3DExperiment(pt_number,cam_number,noise,outlier_fraction);
40 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
41 | T_perturbed = [R_perturbed,t_perturbed];
42 |
43 | % run all algorithms
44 | for a=1:num_algorithms
45 | tic;
46 | T = opengv_donotuse(algorithms{a},indices{a},points,v,T_perturbed);
47 | execution_times(a,i) = toc/20.0;
48 | end
49 |
50 | counter = counter + 1;
51 | if counter == 100
52 | counter = 0;
53 | display(['Iteration ' num2str(i) ' of ' num2str(iterations)]);
54 | end
55 | end
56 |
57 | %% Plot the results
58 |
59 | bins = [0.000001:0.000001:0.00001];
60 | hist(execution_times',bins)
61 | legend(names,'Location','NorthWest')
62 | xlabel('execution times [s]')
63 | grid on
64 |
65 | mean(execution_times')
66 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/benchmark_absolute_pose_noncentral_execution_timing.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % central case -> only one camera
11 | cam_number = 4;
12 | % let's only get 6 points, and generate new ones in each iteration
13 | pt_number = 50;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 iterations
17 | iterations = 1000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'gp3p'; 'gpnp'; 'upnp'};
21 | % This defines the number of points used for every algorithm
22 | indices = { [1, 2, 3]; [1:1:50]; [1:1:50] };
23 | % The name of the algorithms on the plots
24 | names = { 'GP3P'; 'GPnP (50pts)'; 'UPnP (50pts)' };
25 |
26 | % The noise in this experiment
27 | noise = 1.0;
28 |
29 | %% Run the benchmark
30 |
31 | %prepare the overall result arrays
32 | num_algorithms = size(algorithms,1);
33 | execution_times = zeros(num_algorithms,iterations);
34 | counter = 0;
35 |
36 | for i=1:iterations
37 |
38 | % generate experiment
39 | [points,v,t,R] = create2D3DExperiment(pt_number,cam_number,noise,outlier_fraction);
40 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
41 | T_perturbed = [R_perturbed,t_perturbed];
42 |
43 | for a=1:num_algorithms
44 | tic
45 | T = opengv_donotuse(algorithms{a},indices{a},points,v,T_perturbed);
46 | execution_times(a,i) = toc/20.0;
47 | end
48 |
49 | counter = counter + 1;
50 | if counter == 100
51 | counter = 0;
52 | display(['Iteration ' num2str(i) ' of ' num2str(iterations) '(noise level ' num2str(noise) ')']);
53 | end
54 | end
55 |
56 | %% Plot the results
57 |
58 | hist(execution_times')
59 | legend(names,'Location','NorthWest')
60 | xlabel('execution times [s]')
61 | grid on
62 |
63 | mean(execution_times')
64 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/benchmark_relative_pose_execution_times.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % central case -> only one camera
11 | cam_number = 1;
12 | % Getting 10 points, and testing all algorithms with the respective number of points
13 | pt_number = 10;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 iterations
17 | iterations = 1000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'twopt';'fivept_stewenius'; 'fivept_nister'; 'fivept_kneip'; 'sevenpt'; 'eightpt'; 'eigensolver' };
21 | % This defines the number of points used for every algorithm
22 | indices = { [1,2]; [1, 2, 3, 4, 5]; [1, 2, 3, 4, 5]; [1, 2, 3, 4, 5]; [1, 2, 3, 4, 5, 6, 7]; [1, 2, 3, 4, 5, 6, 7, 8]; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] };
23 | % The name of the algorithms in the final plots
24 | names = { '2pt';'5pt (Stewenius)'; '5pt (Nister)'; '5pt (Kneip)'; '7pt'; '8pt'; 'eigensolver' };
25 |
26 | % noise in this experiment
27 | noise = 1.0;
28 |
29 | %% Run the benchmark
30 |
31 | %prepare the overall result arrays
32 | num_algorithms = size(algorithms,1);
33 | execution_times = zeros(num_algorithms,iterations);
34 | counter = 0;
35 |
36 | for i=1:iterations
37 |
38 | % generate experiment
39 | [v1,v2,t,R] = create2D2DExperiment(pt_number,cam_number,noise,outlier_fraction);
40 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
41 | T_perturbed = [R_perturbed,t_perturbed];
42 |
43 | for a=1:num_algorithms
44 | tic
45 | Out = opengv_donotuse(algorithms{a},indices{a},v1,v2,T_perturbed);
46 | execution_times(a,i) = toc/20.0;
47 | end
48 |
49 | counter = counter + 1;
50 | if counter == 100
51 | counter = 0;
52 | display(['Iteration ' num2str(i) ' of ' num2str(iterations)]);
53 | end
54 | end
55 |
56 | %% Plot the results
57 |
58 | hist(execution_times')
59 | legend(names,'Location','NorthWest')
60 | xlabel('execution times [s]')
61 | grid on
62 |
63 | mean(execution_times')
64 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/benchmark_relative_pose_noncentral2.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % noncentral case
11 | cam_number = 4;
12 | % Getting 17 points, and testing all algorithms with the respective number of points
13 | pt_number = 17;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 tests per noise level
17 | iterations = 1000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'sixpt'; 'ge'; 'ge'; 'seventeenpt'; 'rel_nonlin_noncentral' };
21 | % This defines the number of points used for every algorithm
22 | indices = { [1:1:6]; [1:1:8]; [1:1:17]; [1:1:17]; [1:1:17] };
23 | % The name of the algorithms in the final plots
24 | names = { '6pt'; 'ge (8pt)'; 'ge (17pt)'; '17pt'; 'nonlin. opt. (17pt)' };
25 |
26 | % The maximum noise to analyze
27 | max_noise = 5.0;
28 | % The step in between different noise levels
29 | noise_step = 0.1;
30 |
31 | %% Run the benchmark
32 |
33 | %prepare the overall result arrays
34 | number_noise_levels = max_noise / noise_step + 1;
35 | num_algorithms = size(algorithms,1);
36 | mean_rotation_errors = zeros(num_algorithms,number_noise_levels);
37 | median_rotation_errors = zeros(num_algorithms,number_noise_levels);
38 | noise_levels = zeros(1,number_noise_levels);
39 |
40 | %Run the experiment
41 | for n=1:number_noise_levels
42 |
43 | noise = (n - 1) * noise_step;
44 | noise_levels(1,n) = noise;
45 | display(['Analyzing noise level: ' num2str(noise)])
46 |
47 | rotation_errors = zeros(num_algorithms,iterations);
48 |
49 | counter = 0;
50 |
51 | for i=1:iterations
52 |
53 | % generate experiment
54 | [v1,v2,t,R] = create2D2DOmniExperiment(pt_number,cam_number,noise,outlier_fraction);
55 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
56 | T_perturbed = [R_perturbed,t_perturbed];
57 | T_init = [eye(3),zeros(3,1)];
58 | T_gt = [R,t];
59 |
60 | for a=1:num_algorithms
61 |
62 | if strcmp(algorithms{a},'ge')
63 | Out = opengv(algorithms{a},indices{a},v1,v2,T_init);
64 | else
65 | Out = opengv(algorithms{a},indices{a},v1,v2,T_perturbed);
66 | end
67 |
68 | if a > 3 %if a bigger than 4, we obtain entire transformation, and need to "cut" the rotation
69 | temp = Out(:,1:3);
70 | Out = temp;
71 | end
72 |
73 | rotation_error = evaluateRotationError( R, Out );
74 | rotation_errors(a,i) = rotation_error;
75 | end
76 |
77 | counter = counter + 1;
78 | if counter == 100
79 | counter = 0;
80 | display(['Iteration ' num2str(i) ' of ' num2str(iterations) '(noise level ' num2str(noise) ')']);
81 | end
82 | end
83 |
84 | %Now compute the mean and median value of the error for each algorithm
85 | for a=1:num_algorithms
86 | mean_rotation_errors(a,n) = mean(rotation_errors(a,:));
87 | median_rotation_errors(a,n) = median(rotation_errors(a,:));
88 | end
89 |
90 | end
91 |
92 | %% Plot the results
93 |
94 | figure(1)
95 | plot(noise_levels,mean_rotation_errors,'LineWidth',2)
96 | legend(names,'Location','NorthWest')
97 | xlabel('noise level [pix]')
98 | ylabel('mean rot. error [rad]')
99 | grid on
100 |
101 | figure(2)
102 | plot(noise_levels,median_rotation_errors,'LineWidth',2)
103 | legend(names,'Location','NorthWest')
104 | xlabel('noise level [pix]')
105 | ylabel('median rot. error [rad]')
106 | grid on
--------------------------------------------------------------------------------
/third_party/opengv/matlab/benchmark_relative_pose_noncentral_execution_times.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % central case -> only one camera
11 | cam_number = 4;
12 | % Getting 10 points, and testing all algorithms with the respective number of points
13 | pt_number = 50;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 iterations
17 | iterations = 1000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'seventeenpt' };
21 | % This defines the number of points used for every algorithm
22 | indices = { [1:1:17] };
23 | % The name of the algorithms in the final plots
24 | names = { '17pt' };
25 |
26 | % The noise in this experiment
27 | noise = 1.0;
28 |
29 | %% Run the benchmark
30 |
31 | %prepare the overall result arrays
32 | num_algorithms = size(algorithms,1);
33 | execution_times = zeros(num_algorithms,iterations);
34 | counter = 0;
35 |
36 | for i=1:iterations
37 |
38 | % generate experiment
39 | [v1,v2,t,R] = create2D2DExperiment(pt_number,cam_number,noise,outlier_fraction);
40 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
41 | T_perturbed = [R_perturbed,t_perturbed];
42 |
43 | for a=1:num_algorithms
44 | tic
45 | Out = opengv_donotuse(algorithms{a},indices{a},v1,v2,T_perturbed);
46 | execution_times(a,i) = toc/20.0;
47 | end
48 |
49 | counter = counter + 1;
50 | if counter == 100
51 | counter = 0;
52 | display(['Iteration ' num2str(i) ' of ' num2str(iterations) '(noise level ' num2str(noise) ')']);
53 | end
54 | end
55 |
56 | %% Plot the results
57 |
58 | hist(execution_times')
59 | legend(names,'Location','NorthWest')
60 | xlabel('execution times [s]')
61 | grid on
62 |
63 | mean(execution_times')
64 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/benchmark_relative_pose_noncentral_execution_times2.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % central case -> only one camera
11 | cam_number = 4;
12 | % Getting 17 points, and testing all algorithms with the respective number of points
13 | pt_number = 17;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 iterations
17 | iterations = 1000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'sixpt'; 'ge'; 'seventeenpt' };
21 | % This defines the number of points used for every algorithm
22 | indices = { [1:1:6]; [1:1:8]; [1:1:17] };
23 | % The name of the algorithms in the final plots
24 | names = { '6pt';'ge (8pt)'; '17pt' };
25 |
26 | % The noise in this experiment
27 | noise = 0.5;
28 |
29 | %% Run the benchmark
30 |
31 | %prepare the overall result arrays
32 | num_algorithms = size(algorithms,1);
33 | execution_times = zeros(num_algorithms,iterations);
34 | counter = 0;
35 |
36 | for i=1:iterations
37 |
38 | % generate experiment
39 | [v1,v2,t,R] = create2D2DOmniExperiment(pt_number,cam_number,noise,outlier_fraction);
40 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
41 | T_perturbed = [R_perturbed,t_perturbed];
42 | T_init = [eye(3) zeros(3,1)];
43 |
44 | for a=1:num_algorithms
45 | tic
46 | Out = opengv_donotuse(algorithms{a},indices{a},v1,v2,T_init);
47 | execution_times(a,i) = toc/20.0;
48 | end
49 |
50 | counter = counter + 1;
51 | if counter == 1
52 | counter = 0;
53 | display(['Iteration ' num2str(i) ' of ' num2str(iterations) '(noise level ' num2str(noise) ')']);
54 | end
55 | end
56 |
57 | %% Plot results
58 |
59 | hist(log10(execution_times)')
60 |
61 | legend(names,'Location','NorthWest')
62 | xlabel('execution time [s]')
63 | ylabel('occurence')
64 | grid on
65 |
66 | %% print the mean and median execution time on the console
67 |
68 | display( 'mean execution times:' )
69 | display(['sixpt: ' num2str(mean(execution_times(1,:)'))] );
70 | display(['ge: ' num2str(mean(execution_times(2,:)'))] );
71 | display(['seventeenpt: ' num2str(mean(execution_times(3,:)'))] );
72 |
73 | %% Plot the results
74 | %
75 | % [y1,x1] = hist(execution_times(1,:));
76 | % [y2,x2] = hist(execution_times(2,:));
77 | % [y3,x3] = hist(execution_times(3,:));
78 | %
79 | % y1 = y1 / (x1(1,2) - x1(1,1));
80 | % y2 = y2 / (x2(1,2) - x2(1,1));
81 | % y3 = y3 / (x3(1,2) - x3(1,1));
82 | %
83 | % figure(2)
84 | % hold on
85 | % plot(x1,y1,'b');
86 | % plot(x2,y2,'g');
87 | % plot(x3,y3,'r');
88 | % legend(names,'Location','NorthWest')
89 | % xlabel('execution time [s]')
90 | % ylabel('probability')
91 | % grid on
92 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/addNoise.m:
--------------------------------------------------------------------------------
1 | function v_noisy = addNoise(v_clean,focal_length,pixel_noise)
2 |
3 | %find good vector in normal plane based on good conditioning
4 | inPlaneVector1 = zeros(3,1);
5 |
6 | if v_clean(1,1) > v_clean(2,1) && v_clean(1,1) > v_clean(3,1)
7 | inPlaneVector1(2,1) = 1.0;
8 | inPlaneVector1(3,1) = 0.0;
9 | inPlaneVector1(1,1) = 1.0/v_clean(1,1) * (-v_clean(2,1));
10 | else
11 | if v_clean(2,1) > v_clean(3,1) && v_clean(2,1) > v_clean(1,1)
12 | inPlaneVector1(3,1) = 1.0;
13 | inPlaneVector1(1,1) = 0.0;
14 | inPlaneVector1(2,1) = 1.0/v_clean(2,1) * (-v_clean(3,1));
15 | else
16 | %v_clean(3,1) > v_clean(1,1) && v_clean(3,1) > v_clean(2,1)
17 | inPlaneVector1(1,1) = 1.0;
18 | inPlaneVector1(2,1) = 0.0;
19 | inPlaneVector1(3,1) = 1.0/v_clean(3,1) * (-v_clean(1,1));
20 | end
21 | end
22 |
23 | %normalize the in-plane vector
24 | inPlaneVector1 = inPlaneVector1 / norm(inPlaneVector1);
25 | inPlaneVector2 = cross(v_clean,inPlaneVector1);
26 |
27 | noiseX = pixel_noise * (rand-0.5)*2.0;% / sqrt(2);
28 | noiseY = pixel_noise * (rand-0.5)*2.0;% / sqrt(2);
29 |
30 | v_noisy = focal_length * v_clean + noiseX * inPlaneVector1 + noiseY * inPlaneVector2;
31 |
32 | v_noisy_norm = norm(v_noisy);
33 | v_noisy = v_noisy ./ v_noisy_norm;
34 |
35 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/cayley2rot.m:
--------------------------------------------------------------------------------
1 | function R = cayley2rot(v)
2 |
3 | cayley0 = v(1,1);
4 | cayley1 = v(2,1);
5 | cayley2 = v(3,1);
6 |
7 | R = zeros(3,3);
8 | scale = 1+cayley0^2+cayley1^2+cayley2^2;
9 |
10 | R(1,1) = 1+cayley0^2-cayley1^2-cayley2^2;
11 | R(1,2) = 2*(cayley0*cayley1-cayley2);
12 | R(1,3) = 2*(cayley0*cayley2+cayley1);
13 | R(2,1) = 2*(cayley0*cayley1+cayley2);
14 | R(2,2) = 1-cayley0^2+cayley1^2-cayley2^2;
15 | R(2,3) = 2*(cayley1*cayley2-cayley0);
16 | R(3,1) = 2*(cayley0*cayley2-cayley1);
17 | R(3,2) = 2*(cayley1*cayley2+cayley0);
18 | R(3,3) = 1-cayley0^2-cayley1^2+cayley2^2;
19 |
20 | R = (1/scale) * R;
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/evaluateRotationError.m:
--------------------------------------------------------------------------------
1 | function rotation_error = evaluateRotationError(R_gt,R)
2 |
3 | temp = size(size(R));
4 | numberSolutions = 1;
5 | if temp(1,2) == 3
6 | temp2 = size(R);
7 | numberSolutions = temp2(1,3);
8 | end
9 |
10 | if numberSolutions == 1
11 |
12 | %rotation_error = norm(rodrigues(R_gt'*R));
13 | rotation_error = norm( rodrigues(R_gt) - rodrigues(R) );
14 |
15 | else
16 |
17 | rotation_errors = zeros(1,numberSolutions);
18 |
19 | index = 0;
20 |
21 | for i=1:numberSolutions
22 |
23 | %Check if there is any Nan
24 | if ~isnan(R(1,1,i))
25 | index = index + 1;
26 | %rotation_errors(1,index) = norm(rodrigues(R_gt'*R(:,:,i)));
27 | rotation_errors(1,index) = norm( rodrigues(R_gt) - rodrigues(R(:,:,i)) );
28 | end
29 | end
30 |
31 | %find the smallest error (we are the most "nice" to algorithms returning multiple solutions,
32 | %and do the disambiguation by hand)
33 | [~,minIndex] = min(rotation_errors(1,1:index));
34 | rotation_error = rotation_errors(1,minIndex);
35 |
36 | end
37 |
38 | end
39 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/evaluateTransformationError.m:
--------------------------------------------------------------------------------
1 | function [position_error,rotation_error] = evaluateTransformationError(T_gt,T)
2 |
3 | temp = size(size(T));
4 | numberSolutions = 1;
5 | if temp(1,2) == 3
6 | temp2 = size(T);
7 | numberSolutions = temp2(1,3);
8 | end
9 |
10 | if numberSolutions == 1
11 |
12 | position_error = norm(T_gt(:,4)-T(:,4));
13 | rotation_error = norm(rodrigues(T_gt(:,1:3)'*T(:,1:3)));
14 |
15 | else
16 |
17 | position_errors = zeros(1,numberSolutions);
18 | rotation_errors = zeros(1,numberSolutions);
19 |
20 | index = 0;
21 |
22 | for i=1:numberSolutions
23 |
24 | %Check if there is any Nan
25 | if ~isnan(T(1,1,i))
26 | index = index + 1;
27 | position_errors(1,index) = norm(T_gt(:,4)-T(:,4,i));
28 | rotation_errors(1,index) = norm(rodrigues(T_gt(:,1:3)'*T(:,1:3,i)));
29 | end
30 | end
31 |
32 | %find the smallest error (we are the most "nice" to algorithms returning multiple solutions,
33 | %and do the disambiguation by hand)
34 | [~,minIndex] = min(position_errors(1,1:index));
35 | position_error = position_errors(1,minIndex);
36 | rotation_error = rotation_errors(1,minIndex);
37 |
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/generateBoundedR.m:
--------------------------------------------------------------------------------
1 | function R = generateBoundedR( bound )
2 | rpy = bound*2.0*(rand(3,1)-repmat(0.5,3,1));
3 |
4 | R1 = zeros(3,3);
5 | R1(1,1) = 1.0;
6 | R1(2,2) = cos(rpy(1,1));
7 | R1(2,3) = -sin(rpy(1,1));
8 | R1(3,2) = -R1(2,3);
9 | R1(3,3) = R1(2,2);
10 |
11 | R2 = zeros(3,3);
12 | R2(1,1) = cos(rpy(2,1));
13 | R2(1,3) = sin(rpy(2,1));
14 | R2(2,2) = 1.0;
15 | R2(3,1) = -R2(1,3);
16 | R2(3,3) = R2(1,1);
17 |
18 | R3 = zeros(3,3);
19 | R3(1,1) = cos(rpy(3,1));
20 | R3(1,2) = -sin(rpy(3,1));
21 | R3(2,1) =-R3(1,2);
22 | R3(2,2) = R3(1,1);
23 | R3(3,3) = 1.0;
24 |
25 | R = R3 * R2 * R1;
26 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/generateRandomR.m:
--------------------------------------------------------------------------------
1 | function R = generateRandomR()
2 | rpy = pi()*2.0*(rand(3,1)-repmat(0.5,3,1));
3 | rpy(2,1) = 0.5*rpy(2,1);
4 |
5 | R1 = zeros(3,3);
6 | R1(1,1) = 1.0;
7 | R1(2,2) = cos(rpy(1,1));
8 | R1(2,3) = -sin(rpy(1,1));
9 | R1(3,2) = -R1(2,3);
10 | R1(3,3) = R1(2,2);
11 |
12 | R2 = zeros(3,3);
13 | R2(1,1) = cos(rpy(2,1));
14 | R2(1,3) = sin(rpy(2,1));
15 | R2(2,2) = 1.0;
16 | R2(3,1) = -R2(1,3);
17 | R2(3,3) = R2(1,1);
18 |
19 | R3 = zeros(3,3);
20 | R3(1,1) = cos(rpy(3,1));
21 | R3(1,2) = -sin(rpy(3,1));
22 | R3(2,1) =-R3(1,2);
23 | R3(2,2) = R3(1,1);
24 | R3(3,3) = 1.0;
25 |
26 | R = R3 * R2 * R1;
27 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/perturb.m:
--------------------------------------------------------------------------------
1 | function [t_perturbed,R_perturbed] = perturb(t,R,amplitude)
2 |
3 | t_perturbed = t;
4 | r = rodrigues(R);
5 |
6 | for i=1:3
7 | t_perturbed(i,1) = t_perturbed(i,1) + (rand-0.5)*2.0*amplitude;
8 | r(i,1) = r(i,1) + (rand-0.5)*2.0*amplitude;
9 | end
10 |
11 | R_perturbed = rodrigues(r);
12 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/rot2cayley.m:
--------------------------------------------------------------------------------
1 | function v = rot2cayley(R)
2 |
3 | C1 = R-eye(3);
4 | C2 = R+eye(3);
5 | C = C1 * inv(C2);
6 |
7 | v = zeros(3,1);
8 | v(1,1) = -C(2,3);
9 | v(2,1) = C(1,3);
10 | v(3,1) = -C(1,2);
11 |
12 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/helpers/transformEssentials.m:
--------------------------------------------------------------------------------
1 | function Rs = transformEssentials(Es)
2 |
3 | temp = size(size(Es));
4 | numberSolutions = 1;
5 | if temp(1,2) == 3
6 | temp2 = size(Es);
7 | numberSolutions = temp2(1,3);
8 | end
9 |
10 | if numberSolutions == 1
11 |
12 | Rs = zeros(3,3,2);
13 | [U,~,V] = svd(Es);
14 | W = [0 -1 0; 1 0 0; 0 0 1];
15 | Rs(1:3,1:3) = U * W * V';
16 | Rs(1:3,4:6) = U * W' * V';
17 |
18 | if( det(Rs(1:3,1:3)) < 0 )
19 | Rs(1:3,1:3) = -Rs(1:3,1:3);
20 | end
21 | if( det(Rs(1:3,4:6)) < 0 )
22 | Rs(1:3,4:6) = -Rs(1:3,4:6);
23 | end
24 |
25 | else
26 |
27 | Rs_temp = zeros(3,3,2*numberSolutions);
28 | index = 0;
29 |
30 | for i=1:numberSolutions
31 |
32 | %Check if there is any Nan
33 | if ~isnan(Es(1,1,i))
34 | [U,~,V] = svd(Es(:,:,i));
35 | W = [0 -1 0; 1 0 0; 0 0 1];
36 | index = index + 1;
37 | Rs_temp( :,:, index ) = U * W * V';
38 | if(det(Rs_temp( :,:, index )) < 0)
39 | Rs_temp( :,:, index ) = -Rs_temp( :,:, index );
40 | end
41 | index = index + 1;
42 | Rs_temp( :,:, index ) = U * W' * V';
43 | if(det(Rs_temp( :,:, index )) < 0)
44 | Rs_temp( :,:, index ) = -Rs_temp( :,:, index );
45 | end
46 | end
47 | end
48 |
49 | Rs = Rs_temp(:,:,1:index);
50 |
51 | end
52 |
53 | end
54 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/make_mex.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Generate MEX files by compiling from Matlab
3 | # This scripts intends to automate the compilation process
4 | # by following the instructions provided in
5 | # http://laurentkneip.github.io/opengv/page_installation.html#sec_installation_5
6 | # We assume the installation configuration is standard
7 | # so that every dependency can be found in an automated way
8 |
9 | # We assume a launcher command is available: matlab
10 | # Add OpenGV library directory to the path
11 | export LD_LIBRARY_PATH=../build/lib:$LD_LIBRARY_PATH
12 |
13 | # Find path to Eigen library (assumes CMake has cached EIGEN_INCLUDE_DIRS)
14 | # See https://stackoverflow.com/questions/8474753/how-to-get-a-cmake-variable-from-the-command-line
15 | EigenPath=$(cmake -L ../build | grep EIGEN_INCLUDE_DIRS | cut -d "=" -f2)
16 |
17 | # Call Matlab with the compilation command
18 | matlab -nodisplay -nosplash -nodesktop \
19 | -r "mex -I../include -I${EigenPath} -L../build/lib -lopengv opengv.cpp -cxx, mex -I../include -I${EigenPath} -L../build/lib -lopengv opengv_donotuse.cpp -cxx, exit"
20 |
21 |
22 |
--------------------------------------------------------------------------------
/third_party/opengv/matlab/opengv.mexa64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ckchng/MRO/6256415d8c4885fc229c57aace7c38738c97257a/third_party/opengv/matlab/opengv.mexa64
--------------------------------------------------------------------------------
/third_party/opengv/matlab/plot_arun_error.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % noncentral case
11 | cam_number = 4;
12 | % Getting 17 points, and testing all algorithms with the respective number of points
13 | pt_number = 8;
14 | % noise test, so no outliers
15 | outlier_fraction = 0.0;
16 | % repeat 1000 tests per noise level
17 | iterations = 10000;
18 |
19 | % The algorithms we want to test
20 | algorithms = { 'ge2' };
21 | % This defines the number of points used for every algorithm
22 | indices = { [1:1:8] };
23 | % The name of the algorithms in the final plots
24 | names = { 'arun (8pt)' };
25 |
26 | % The maximum noise to analyze
27 | noise = 0.5;
28 |
29 | %% Run the benchmark
30 |
31 | %Run the experiment
32 |
33 | rotation_errors = zeros(1,iterations);
34 |
35 | counter = 0;
36 |
37 | for i=1:iterations
38 |
39 | % generate experiment
40 | [v1,v2,t,R] = create2D2DOmniExperiment(pt_number,cam_number,noise,outlier_fraction);
41 | [t_perturbed,R_perturbed] = perturb(t,R,0.01);
42 | T_perturbed = [R_perturbed,t_perturbed];
43 | T_init = [eye(3),zeros(3,1)];
44 | T_gt = [R,t];
45 |
46 | Out = opengv(algorithms{1},indices{1},v1,v2,T_perturbed);
47 |
48 | rotation_error = evaluateRotationError( R, Out(1:3,1:3) );
49 | rotation_errors(1,i) = rotation_error;
50 |
51 |
52 | counter = counter + 1;
53 | if counter == 100
54 | counter = 0;
55 | display(['Iteration ' num2str(i) ' of ' num2str(iterations) '(noise level ' num2str(noise) ')']);
56 | end
57 | end
58 |
59 | %% Plot the results
60 | hist(rad2deg(rotation_errors))
61 | xlabel('rotation error [deg]')
62 | ylabel('occurence')
63 | grid on
--------------------------------------------------------------------------------
/third_party/opengv/matlab/plot_expected_iterations.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % The algorithms we want to test
11 | algorithms = [ 6; 8; 17 ];
12 | % The name of the algorithms in the final plots
13 | names = { '6pt'; 'ge (8pt)'; '17pt'};
14 |
15 | % The main experiment parameters
16 | min_outlier_fraction = 0.05;%0.05;
17 | max_outlier_fraction = 0.25;
18 | outlier_fraction_step = 0.025;
19 |
20 | p = 0.99;
21 |
22 | %% Run the benchmark
23 |
24 | %prepare the overall result arrays
25 | number_outlier_fraction_levels = round((max_outlier_fraction - min_outlier_fraction) / outlier_fraction_step + 1);
26 | num_algorithms = size(algorithms,1);
27 | expected_number_iterations = zeros(num_algorithms,number_outlier_fraction_levels);
28 | outlier_fraction_levels = zeros(1,number_outlier_fraction_levels);
29 |
30 | %Run the experiment
31 | for n=1:number_outlier_fraction_levels
32 |
33 | outlier_fraction = (n - 1) * outlier_fraction_step + min_outlier_fraction;
34 | outlier_fraction_levels(1,n) = outlier_fraction;
35 | display(['Analyzing outlier fraction level: ' num2str(outlier_fraction)])
36 |
37 | %Now compute the mean and median value of the error for each algorithm
38 | for a=1:num_algorithms
39 | expected_number_iterations(a,n) = log(1-p)/log(1-(1-outlier_fraction)^(algorithms(a,1)));
40 | end
41 |
42 | end
43 |
44 | %% Plot the results
45 |
46 | figure(1)
47 | plot(outlier_fraction_levels,expected_number_iterations,'LineWidth',2)
48 | legend(names,'Location','NorthWest')
49 | xlabel('outlier fraction')
50 | ylabel('expected number iterations')
51 | grid on
--------------------------------------------------------------------------------
/third_party/opengv/matlab/ransac_experiment.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % noncentral case
11 | cam_number = 4;
12 | % set maximum and minimum number of points per cam
13 | pt_number_per_cam = 50;
14 | % set maximum and minimum number of outliers
15 | min_outlier_fraction = 0.1;
16 | max_outlier_fraction = 0.2;
17 | % repeat 10000 iterations
18 | iterations = 1000;
19 |
20 | % The name of the algorithms in the final plots
21 | names = { 'Homogeneous'; 'Vanilla' };
22 |
23 | % The noise in this experiment
24 | noise = 0.5;
25 |
26 | %% Run the benchmark
27 |
28 | %prepare the overall result arrays
29 | ransac_iterations = zeros(2,iterations);
30 |
31 | %Run the RANSAC with homogeneous sampling
32 | counter = 0;
33 |
34 | for i=1:iterations
35 |
36 | %generate random outlier fraction
37 | outlier_fraction = rand() * (max_outlier_fraction - min_outlier_fraction) + min_outlier_fraction;
38 |
39 | % generate experiment
40 | [v1,v2,cam_offsets,t,R] = createMulti2D2DExperiment(pt_number_per_cam,cam_number,noise,outlier_fraction);
41 | Out = opengv_experimental1( v1{1,1}, v1{2,1}, v1{3,1}, v1{4,1}, v2{1,1}, v2{2,1}, v2{3,1}, v2{4,1}, cam_offsets, 2 );
42 | ransac_iterations(1,i) = Out(1,5);
43 |
44 | counter = counter + 1;
45 | if counter == 100
46 | counter = 0;
47 | display(['Homogeneous sampling: Iteration ' num2str(i) ' of ' num2str(iterations)]);
48 | end
49 | end
50 |
51 | %Run the RANSAC with vanilla sampling
52 | counter = 0;
53 |
54 | for i=1:iterations
55 |
56 | %generate random outlier fraction
57 | outlier_fraction = rand() * (max_outlier_fraction - min_outlier_fraction) + min_outlier_fraction;
58 |
59 | % generate experiment
60 | [v1,v2,t,R] = create2D2DExperiment(pt_number_per_cam*cam_number,cam_number,noise,outlier_fraction);
61 | Out = opengv_experimental2( v1, v2, 2 );
62 | ransac_iterations(2,i) = Out(1,5);
63 |
64 | counter = counter + 1;
65 | if counter == 100
66 | counter = 0;
67 | display(['Vanilla sampling: Iteration ' num2str(i) ' of ' num2str(iterations)]);
68 | end
69 | end
70 |
71 | %% Plot the results
72 |
73 | figure(1)
74 | hist(ransac_iterations')
75 | [Y,X] = hist(ransac_iterations')
76 | legend(names,'Location','NorthEast')
77 | xlabel('number of iterations')
78 | grid on
--------------------------------------------------------------------------------
/third_party/opengv/matlab/ransac_experiment2.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | rng shuffle
9 |
10 | %% Configure the benchmark
11 |
12 | % noncentral case
13 | cam_number = 4;
14 | % Getting 10 points, and testing all algorithms with the respective number of points
15 | pt_per_cam = 20;
16 | % outlier test, so constant noise
17 | noise = 0.5;
18 | % repeat 100 tests per outlier-ratio
19 | iterations = 50;
20 |
21 | % The algorithms we want to test
22 | algorithms = [ 0; 1; 2 ];
23 | % The name of the algorithms in the final plots
24 | names = { '6pt'; 'ge (8pt)'; '17pt'};
25 |
26 | % The main experiment parameters
27 | min_outlier_fraction = 0.05;
28 | max_outlier_fraction = 0.45;
29 | outlier_fraction_step = 0.05;
30 |
31 | %% Run the benchmark
32 |
33 | %prepare the overall result arrays
34 | number_outlier_fraction_levels = round((max_outlier_fraction - min_outlier_fraction) / outlier_fraction_step + 1);
35 | num_algorithms = size(algorithms,1);
36 |
37 | %Run the experiment
38 | for n=1:number_outlier_fraction_levels
39 |
40 | outlier_fraction = (n - 1) * outlier_fraction_step + min_outlier_fraction;
41 | display(['Analyzing outlier fraction level: ' num2str(outlier_fraction)])
42 |
43 | clear number_iterations
44 | clear execution_times
45 |
46 | counter = 0;
47 |
48 | temp_file_name1 = ['number_iterations_' num2str(outlier_fraction) '.mat'];
49 | temp_file_name2 = ['execution_times_' num2str(outlier_fraction) '.mat'];
50 |
51 | if exist(temp_file_name1,'file') > 0
52 | display(['number_iterations_' num2str(outlier_fraction) '.mat exists already'])
53 | load(temp_file_name1)
54 | load(temp_file_name2)
55 | startingIteration = size(number_iterations,2) + 1;
56 | display(['starting at ' num2str(startingIteration)])
57 | else
58 | startingIteration = 1;
59 | end
60 |
61 | if startingIteration <= iterations
62 | for i=startingIteration:iterations
63 |
64 | % generate experiment
65 | [v1,v2,cam_offsets,t,R] = createMulti2D2DOmniExperiment(pt_per_cam,cam_number,noise,outlier_fraction);
66 |
67 | for a=1:num_algorithms
68 |
69 | if strcmp(names{a,1},'6pt') && outlier_fraction > 0.25
70 | Out = zeros(4,5);
71 | time = 10000000.0;
72 | else
73 | tic
74 | Out = opengv_experimental1( v1{1,1}, v1{2,1}, v1{3,1}, v1{4,1}, v2{1,1}, v2{2,1}, v2{3,1}, v2{4,1}, cam_offsets, algorithms(a,1) );
75 | time = toc;
76 | end
77 |
78 | number_iterations(a,i) = Out(1,5);
79 | execution_times(a,i) = time;
80 | end
81 |
82 | save(temp_file_name1,'number_iterations');
83 | save(temp_file_name2,'execution_times');
84 |
85 | counter = counter + 1;
86 | if counter == 1
87 | counter = 0;
88 | display(['Iteration ' num2str(i) ' of ' num2str(iterations) '(outlier_fraction level ' num2str(outlier_fraction) ')']);
89 | end
90 | end
91 | end
92 | end
--------------------------------------------------------------------------------
/third_party/opengv/matlab/ransac_experiment3.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | %% Configure the benchmark
9 |
10 | % The name of the algorithms in the final plots
11 | names = { '6pt'; 'ge (8pt)'; '17pt'};
12 |
13 | % The main experiment parameters
14 | min_outlier_fraction = 0.05;
15 | max_outlier_fraction = 0.45;
16 | outlier_fraction_step = 0.05;
17 |
18 | %% Run the benchmark
19 |
20 | %prepare the overall result arrays
21 | number_outlier_fraction_levels = round((max_outlier_fraction - min_outlier_fraction) / outlier_fraction_step + 1);
22 | num_algorithms = size(names,1);
23 | mean_number_iterations = zeros(num_algorithms,number_outlier_fraction_levels);
24 | mean_execution_times = zeros(num_algorithms,number_outlier_fraction_levels);
25 | outlier_fraction_levels = zeros(1,number_outlier_fraction_levels);
26 |
27 | %Run the experiment
28 | for n=1:number_outlier_fraction_levels
29 |
30 | outlier_fraction = (n - 1) * outlier_fraction_step + min_outlier_fraction;
31 | outlier_fraction_levels(1,n) = outlier_fraction;
32 | display(['Analyzing outlier fraction level: ' num2str(outlier_fraction)])
33 |
34 | clear number_iterations
35 | clear execution_times
36 | temp_file_name1 = ['number_iterations_' num2str(outlier_fraction) '.mat'];
37 | temp_file_name2 = ['execution_times_' num2str(outlier_fraction) '.mat'];
38 | load(temp_file_name1)
39 | load(temp_file_name2)
40 |
41 | %Now compute the mean and median value of the error for each algorithm
42 | for a=1:num_algorithms
43 | mean_number_iterations(a,n) = mean(number_iterations(a,:));
44 | mean_execution_times(a,n) = mean(execution_times(a,:));
45 | end
46 | end
47 |
48 | %% Plot the results
49 |
50 | figure(1)
51 | plot(outlier_fraction_levels,mean_number_iterations,'LineWidth',2)
52 | legend(names,'Location','NorthWest')
53 | xlabel('outlier fraction')
54 | ylabel('mean number iterations')
55 | axis([0.05 0.25 0 1500])
56 | grid on
57 |
58 | figure(2)
59 | hold on
60 | plot(outlier_fraction_levels(1,1:6),mean_execution_times(1,1:6),'LineWidth',2)
61 | plot(outlier_fraction_levels,mean_execution_times(2:3,:),'LineWidth',2)
62 | legend(names,'Location','NorthWest')
63 | xlabel('outlier fraction')
64 | ylabel('mean execution time [s]')
65 | axis([0.05 0.45 0 40])
66 | grid on
--------------------------------------------------------------------------------
/third_party/opengv/matlab/ransac_test.m:
--------------------------------------------------------------------------------
1 | %% Reset everything
2 |
3 | clear all;
4 | clc;
5 | close all;
6 | addpath('helpers');
7 |
8 | % central case -> only one camera
9 | cam_number = 1;
10 | % let's only get 6 points, and generate new ones in each iteration
11 | pt_number = 100;
12 | % noise test, so no outliers
13 | outlier_fraction = 0.1;
14 |
15 | noise = 0.0;
16 | [points,v,t,R] = create2D3DExperiment(pt_number,cam_number,noise,outlier_fraction);
17 | [X, inliers] = opengv('p3p_kneip_ransac',points,v);
--------------------------------------------------------------------------------
/third_party/opengv/modules/Config.cmake.in:
--------------------------------------------------------------------------------
1 | @PACKAGE_INIT@
2 |
3 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
4 | check_required_components("@PROJECT_NAME@")
5 |
--------------------------------------------------------------------------------
/third_party/opengv/modules/FindEigen.cmake:
--------------------------------------------------------------------------------
1 | # - Try to find Eigen3 lib
2 | #
3 | # This module supports requiring a minimum version, e.g. you can do
4 | # find_package(Eigen3 3.1.2)
5 | # to require version 3.1.2 or newer of Eigen3.
6 | #
7 | # Once done this will define
8 | #
9 | # EIGEN_FOUND - system has eigen lib with correct version
10 | # EIGEN_INCLUDE_DIR - the eigen include directory
11 | # EIGEN_VERSION - eigen version
12 |
13 | # Copyright (c) 2006, 2007 Montel Laurent,
14 | # Copyright (c) 2008, 2009 Gael Guennebaud,
15 | # Copyright (c) 2009 Benoit Jacob
16 | # Redistribution and use is allowed according to the terms of the 2-clause BSD license.
17 |
18 | if(NOT Eigen_FIND_VERSION)
19 | if(NOT Eigen_FIND_VERSION_MAJOR)
20 | set(Eigen_FIND_VERSION_MAJOR 2)
21 | endif(NOT Eigen_FIND_VERSION_MAJOR)
22 | if(NOT Eigen_FIND_VERSION_MINOR)
23 | set(Eigen_FIND_VERSION_MINOR 91)
24 | endif(NOT Eigen_FIND_VERSION_MINOR)
25 | if(NOT Eigen_FIND_VERSION_PATCH)
26 | set(Eigen_FIND_VERSION_PATCH 0)
27 | endif(NOT Eigen_FIND_VERSION_PATCH)
28 |
29 | set(Eigen_FIND_VERSION "${Eigen_FIND_VERSION_MAJOR}.${Eigen_FIND_VERSION_MINOR}.${Eigen_FIND_VERSION_PATCH}")
30 | endif(NOT Eigen_FIND_VERSION)
31 |
32 | macro(_eigen3_check_version)
33 | file(READ "${EIGEN_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
34 |
35 | string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
36 | set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}")
37 | string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
38 | set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}")
39 | string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
40 | set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}")
41 |
42 | set(EIGEN_VERSION ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})
43 | if(${EIGEN_VERSION} VERSION_LESS ${Eigen_FIND_VERSION})
44 | set(EIGEN_VERSION_OK FALSE)
45 | else(${EIGEN_VERSION} VERSION_LESS ${Eigen_FIND_VERSION})
46 | set(EIGEN_VERSION_OK TRUE)
47 | endif(${EIGEN_VERSION} VERSION_LESS ${Eigen_FIND_VERSION})
48 |
49 | if(NOT EIGEN_VERSION_OK)
50 |
51 | message(STATUS "Eigen version ${EIGEN_VERSION} found in ${EIGEN_INCLUDE_DIR}, "
52 | "but at least version ${Eigen_FIND_VERSION} is required")
53 | endif(NOT EIGEN_VERSION_OK)
54 | endmacro(_eigen3_check_version)
55 |
56 | if (EIGEN_INCLUDE_DIRS)
57 |
58 | # in cache already
59 | _eigen3_check_version()
60 | set(EIGEN_FOUND ${EIGEN_VERSION_OK})
61 |
62 | else ()
63 |
64 | find_path(EIGEN_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
65 | PATHS
66 | ${CMAKE_INSTALL_PREFIX}/include
67 | ${KDE4_INCLUDE_DIR}
68 | PATH_SUFFIXES eigen3 eigen
69 | )
70 |
71 | if(EIGEN_INCLUDE_DIR)
72 | _eigen3_check_version()
73 | endif(EIGEN_INCLUDE_DIR)
74 |
75 | include(FindPackageHandleStandardArgs)
76 | find_package_handle_standard_args(Eigen DEFAULT_MSG EIGEN_INCLUDE_DIR EIGEN_VERSION_OK)
77 |
78 | mark_as_advanced(EIGEN_INCLUDE_DIR)
79 | SET(EIGEN_INCLUDE_DIRS ${EIGEN_INCLUDE_DIR} CACHE PATH "The Eigen include path.")
80 |
81 | endif()
82 |
83 |
--------------------------------------------------------------------------------
/third_party/opengv/python/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_subdirectory(pybind11)
3 |
4 | include_directories(${PYTHON_INCLUDE_DIRS})
5 |
6 |
7 | pybind11_add_module(pyopengv pyopengv.cpp)
8 | target_link_libraries(pyopengv PRIVATE opengv)
9 |
10 |
11 | # Find where to install python libs.
12 | execute_process(COMMAND
13 | ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print('/'.join(distutils.sysconfig.get_python_lib().split('/')[-3:]))"
14 | OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
15 |
16 | set(PYTHON_INSTALL_DIR
17 | "${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGES}"
18 | CACHE PATH "Path where to install pyopengv")
19 |
20 | install(TARGETS pyopengv DESTINATION "${PYTHON_INSTALL_DIR}")
21 |
22 | message(python executable ${PYTHON_EXECUTABLE})
--------------------------------------------------------------------------------
/third_party/opengv/python/types.hpp:
--------------------------------------------------------------------------------
1 | #ifndef __TYPES_H__
2 | #define __TYPES_H__
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 |
10 |
11 | namespace pyopengv {
12 |
13 | namespace py = pybind11;
14 |
15 | typedef py::array_t pyarray_d;
16 |
17 | template
18 | py::array_t py_array_from_data(const T *data, size_t shape0) {
19 | py::array_t res({shape0});
20 | std::copy(data, data + shape0, res.mutable_data());
21 | return res;
22 | }
23 |
24 | template
25 | py::array_t py_array_from_data(const T *data, size_t shape0, size_t shape1) {
26 | py::array_t res({shape0, shape1});
27 | std::copy(data, data + shape0 * shape1, res.mutable_data());
28 | return res;
29 | }
30 |
31 | template
32 | py::array_t py_array_from_vector(const std::vector &v) {
33 | const T *data = v.size() ? &v[0] : NULL;
34 | return py_array_from_data(data, v.size());
35 | }
36 |
37 |
38 | }
39 |
40 | #endif // __TYPES_H__
41 |
--------------------------------------------------------------------------------
/third_party/opengv/src/absolute_pose/modules/gpnp1/code.cpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Author: Laurent Kneip *
3 | * Contact: kneip.laurent@gmail.com *
4 | * License: Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved. *
5 | * *
6 | * Redistribution and use in source and binary forms, with or without *
7 | * modification, are permitted provided that the following conditions *
8 | * are met: *
9 | * * Redistributions of source code must retain the above copyright *
10 | * notice, this list of conditions and the following disclaimer. *
11 | * * Redistributions in binary form must reproduce the above copyright *
12 | * notice, this list of conditions and the following disclaimer in the *
13 | * documentation and/or other materials provided with the distribution. *
14 | * * Neither the name of ANU nor the names of its contributors may be *
15 | * used to endorse or promote products derived from this software without *
16 | * specific prior written permission. *
17 | * *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21 | * ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE *
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
28 | * SUCH DAMAGE. *
29 | ******************************************************************************/
30 |
31 |
32 | #include
33 |
34 |
35 | void
36 | opengv::absolute_pose::modules::gpnp1::compute(
37 | Eigen::Matrix & groebnerMatrix )
38 | {
39 | sPolynomial3(groebnerMatrix);
40 |
41 | sPolynomial4(groebnerMatrix);
42 | groebnerRow3_0_f(groebnerMatrix,4);
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/third_party/opengv/src/absolute_pose/modules/gpnp1/reductors.cpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Author: Laurent Kneip *
3 | * Contact: kneip.laurent@gmail.com *
4 | * License: Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved. *
5 | * *
6 | * Redistribution and use in source and binary forms, with or without *
7 | * modification, are permitted provided that the following conditions *
8 | * are met: *
9 | * * Redistributions of source code must retain the above copyright *
10 | * notice, this list of conditions and the following disclaimer. *
11 | * * Redistributions in binary form must reproduce the above copyright *
12 | * notice, this list of conditions and the following disclaimer in the *
13 | * documentation and/or other materials provided with the distribution. *
14 | * * Neither the name of ANU nor the names of its contributors may be *
15 | * used to endorse or promote products derived from this software without *
16 | * specific prior written permission. *
17 | * *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21 | * ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE *
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
28 | * SUCH DAMAGE. *
29 | ******************************************************************************/
30 |
31 |
32 | #include
33 |
34 |
35 | void
36 | opengv::absolute_pose::modules::gpnp1::groebnerRow3_0_f( Eigen::Matrix & groebnerMatrix, int targetRow )
37 | {
38 | double factor = groebnerMatrix(targetRow,1) / groebnerMatrix(3,1);
39 | groebnerMatrix(targetRow,1) = 0.0;
40 | groebnerMatrix(targetRow,2) -= factor * groebnerMatrix(3,2);
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/third_party/opengv/src/absolute_pose/modules/gpnp1/spolynomials.cpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Author: Laurent Kneip *
3 | * Contact: kneip.laurent@gmail.com *
4 | * License: Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved. *
5 | * *
6 | * Redistribution and use in source and binary forms, with or without *
7 | * modification, are permitted provided that the following conditions *
8 | * are met: *
9 | * * Redistributions of source code must retain the above copyright *
10 | * notice, this list of conditions and the following disclaimer. *
11 | * * Redistributions in binary form must reproduce the above copyright *
12 | * notice, this list of conditions and the following disclaimer in the *
13 | * documentation and/or other materials provided with the distribution. *
14 | * * Neither the name of ANU nor the names of its contributors may be *
15 | * used to endorse or promote products derived from this software without *
16 | * specific prior written permission. *
17 | * *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21 | * ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE *
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
28 | * SUCH DAMAGE. *
29 | ******************************************************************************/
30 |
31 |
32 | #include
33 |
34 |
35 | void
36 | opengv::absolute_pose::modules::gpnp1::sPolynomial3( Eigen::Matrix & groebnerMatrix )
37 | {
38 | groebnerMatrix(3,1) = (groebnerMatrix(0,1)/(groebnerMatrix(0,0))-groebnerMatrix(1,1)/(groebnerMatrix(1,0)));
39 | groebnerMatrix(3,2) = (groebnerMatrix(0,2)/(groebnerMatrix(0,0))-groebnerMatrix(1,2)/(groebnerMatrix(1,0)));
40 | }
41 |
42 | void
43 | opengv::absolute_pose::modules::gpnp1::sPolynomial4( Eigen::Matrix & groebnerMatrix )
44 | {
45 | groebnerMatrix(4,1) = (groebnerMatrix(1,1)/(groebnerMatrix(1,0))-groebnerMatrix(2,1)/(groebnerMatrix(2,0)));
46 | groebnerMatrix(4,2) = (groebnerMatrix(1,2)/(groebnerMatrix(1,0))-groebnerMatrix(2,2)/(groebnerMatrix(2,0)));
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/third_party/opengv/src/absolute_pose/modules/gpnp2/code.cpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Author: Laurent Kneip *
3 | * Contact: kneip.laurent@gmail.com *
4 | * License: Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved. *
5 | * *
6 | * Redistribution and use in source and binary forms, with or without *
7 | * modification, are permitted provided that the following conditions *
8 | * are met: *
9 | * * Redistributions of source code must retain the above copyright *
10 | * notice, this list of conditions and the following disclaimer. *
11 | * * Redistributions in binary form must reproduce the above copyright *
12 | * notice, this list of conditions and the following disclaimer in the *
13 | * documentation and/or other materials provided with the distribution. *
14 | * * Neither the name of ANU nor the names of its contributors may be *
15 | * used to endorse or promote products derived from this software without *
16 | * specific prior written permission. *
17 | * *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21 | * ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE *
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
28 | * SUCH DAMAGE. *
29 | ******************************************************************************/
30 |
31 |
32 | #include
33 |
34 |
35 | void
36 | opengv::absolute_pose::modules::gpnp2::compute(
37 | Eigen::Matrix