[37] | 1 | function [F, inls] = rEG(u, th, th7, conf) |
---|
| 2 | |
---|
| 3 | %rEG Robust computation of epipolar geometry based on RANSAC |
---|
| 4 | % |
---|
| 5 | % [F, inls] = rEG(u, th, th7, conf) |
---|
| 6 | % u point correspondences (6xn), where n is the number of corrs. |
---|
| 7 | % th threshold value for the Sampson's distance (see FDs) |
---|
| 8 | % th7 threshold for inliers to iterate on F (default = th) |
---|
| 9 | % conf confidence level of self-termination (default = .95) |
---|
| 10 | |
---|
| 11 | MAX_SAM = 100000; |
---|
| 12 | iter_amount = .5; |
---|
| 13 | |
---|
| 14 | if nargin < 3 |
---|
| 15 | th7 = th; |
---|
| 16 | end; |
---|
| 17 | |
---|
| 18 | if nargin < 4 |
---|
| 19 | conf = .95; |
---|
| 20 | end; |
---|
| 21 | |
---|
| 22 | len = size(u,2); |
---|
| 23 | ptr = 1:len; |
---|
| 24 | max_i = 8; |
---|
| 25 | max_sam = MAX_SAM; |
---|
| 26 | |
---|
| 27 | no_sam = 0; |
---|
| 28 | no_mod = 0; |
---|
| 29 | |
---|
| 30 | while no_sam < max_sam |
---|
| 31 | for pos = 1:7 |
---|
| 32 | idx = pos + ceil(rand * (len-pos)); |
---|
| 33 | ptr([pos, idx]) = ptr([idx, pos]); |
---|
| 34 | end; |
---|
| 35 | |
---|
| 36 | no_sam = no_sam +1; |
---|
| 37 | |
---|
| 38 | aFs = fu2F7(u(:,ptr(1:7))); |
---|
| 39 | |
---|
| 40 | for i = 1:size(aFs,3) |
---|
| 41 | no_mod = no_mod +1; |
---|
| 42 | aF = aFs(:,:,i); |
---|
| 43 | Ds = mfFDs(aF,u); |
---|
| 44 | % Ds = fFDs(aF,u); |
---|
| 45 | v = Ds < th; |
---|
| 46 | v7 = Ds < th7; |
---|
| 47 | no_i = sum(v); |
---|
| 48 | |
---|
| 49 | if max_i < no_i |
---|
| 50 | inls = v; |
---|
| 51 | F = aF; |
---|
| 52 | max_i = no_i; |
---|
| 53 | max_sam = min([max_sam,nsamples(max_i, len, 7, conf)]); |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | if sum(v7) >= 8 + iter_amount*(max_i - 8) |
---|
| 57 | aF = u2F(u(:,v7)); |
---|
| 58 | Ds = mfFDs(aF,u); |
---|
| 59 | % Ds = fFDs(aF,u); |
---|
| 60 | v = Ds < th; |
---|
| 61 | no_i = sum(v); |
---|
| 62 | if max_i < no_i |
---|
| 63 | inls = v; |
---|
| 64 | F = aF; |
---|
| 65 | max_i = no_i; |
---|
| 66 | exp_sam = nsamples(max_i, len, 7, .95); |
---|
| 67 | max_sam = min([max_sam,exp_sam]); |
---|
| 68 | end |
---|
| 69 | end |
---|
| 70 | end |
---|
| 71 | end |
---|
| 72 | |
---|
| 73 | if no_sam == MAX_SAM |
---|
| 74 | warning(sprintf('RANSAC - termination forced after %d samples expected number of samples is %d', no_sam, exp_sam)); |
---|
| 75 | end; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|