1%% Reset everything 2 3clear all; 4clc; 5close all; 6addpath('helpers'); 7 8%% Configure the benchmark 9 10% noncentral case 11cam_number = 4; 12% Getting 17 points, and testing all algorithms with the respective number of points 13pt_number = 17; 14% noise test, so no outliers 15outlier_fraction = 0.0; 16% repeat 1000 tests per noise level 17iterations = 1000; 18 19% The algorithms we want to test 20algorithms = { 'sixpt'; 'ge'; 'ge'; 'seventeenpt'; 'rel_nonlin_noncentral' }; 21% This defines the number of points used for every algorithm 22indices = { [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 24names = { '6pt'; 'ge (8pt)'; 'ge (17pt)'; '17pt'; 'nonlin. opt. (17pt)' }; 25 26% The maximum noise to analyze 27max_noise = 5.0; 28% The step in between different noise levels 29noise_step = 0.1; 30 31%% Run the benchmark 32 33%prepare the overall result arrays 34number_noise_levels = max_noise / noise_step + 1; 35num_algorithms = size(algorithms,1); 36mean_rotation_errors = zeros(num_algorithms,number_noise_levels); 37median_rotation_errors = zeros(num_algorithms,number_noise_levels); 38noise_levels = zeros(1,number_noise_levels); 39 40%Run the experiment 41for 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 90end 91 92%% Plot the results 93 94figure(1) 95plot(noise_levels,mean_rotation_errors,'LineWidth',2) 96legend(names,'Location','NorthWest') 97xlabel('noise level [pix]') 98ylabel('mean rot. error [rad]') 99grid on 100 101figure(2) 102plot(noise_levels,median_rotation_errors,'LineWidth',2) 103legend(names,'Location','NorthWest') 104xlabel('noise level [pix]') 105ylabel('median rot. error [rad]') 106grid on