[37] | 1 | function [F, inls] = rEG(u,th,th4,conf,ss) |
---|
| 2 | % REG robust estimation of the epipolar geometry via RANSAC |
---|
| 3 | % |
---|
| 4 | % [H, inls] = rRG(u,th,{th4=th,conf=0.99,ss=8}) |
---|
| 5 | % u ... 6xN pairs homogenous coordinates |
---|
| 6 | % th ... inlier tolerance in pixels |
---|
| 7 | % th4 ... currently not used |
---|
| 8 | % conf ... confidence, the higher -> more samples |
---|
| 9 | % ss ... sample size |
---|
| 10 | % |
---|
| 11 | % F ... 3x3 fundamental matrix |
---|
| 12 | % inls ... 1xN logical 1->inlier. 0->outlier |
---|
| 13 | % |
---|
| 14 | % $Id: rEG.m,v 1.1 2005/05/23 16:16:00 svoboda Exp $ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | MAX_SAM = 100000; % maimal number of random samples |
---|
| 18 | |
---|
| 19 | len = size(u,2); |
---|
| 20 | |
---|
| 21 | % parsing the inputs |
---|
| 22 | if nargin < 3 |
---|
| 23 | th4 = th; |
---|
| 24 | end |
---|
| 25 | |
---|
| 26 | if nargin < 4 |
---|
| 27 | conf = 0.99; |
---|
| 28 | end |
---|
| 29 | |
---|
| 30 | if nargin < 5 |
---|
| 31 | ss = 8; % sample size |
---|
| 32 | end |
---|
| 33 | |
---|
| 34 | len = size(u,2); |
---|
| 35 | ptr = 1:len; |
---|
| 36 | max_i = 5; |
---|
| 37 | max_sam = MAX_SAM; |
---|
| 38 | |
---|
| 39 | no_sam = 0; |
---|
| 40 | no_mod = 0; |
---|
| 41 | |
---|
| 42 | th = 2*th^2; |
---|
| 43 | |
---|
| 44 | while no_sam < max_sam |
---|
| 45 | for pos = 1:ss |
---|
| 46 | idx = pos + ceil(rand * (len-pos)); |
---|
| 47 | ptr([pos, idx]) = ptr([idx, pos]); |
---|
| 48 | end; |
---|
| 49 | |
---|
| 50 | no_sam = no_sam +1; |
---|
| 51 | |
---|
| 52 | sF = u2Fdlt(u(:,ptr(1:ss)),0); |
---|
| 53 | errs = Fsampson(sF,u); |
---|
| 54 | v = errs < th; |
---|
| 55 | no_i = sum(v); |
---|
| 56 | |
---|
| 57 | if max_i < no_i |
---|
| 58 | inls = v; |
---|
| 59 | F = sF; |
---|
| 60 | max_i = no_i; |
---|
| 61 | max_sam = min([max_sam,nsamples(max_i, len, ss, conf)]); |
---|
| 62 | end |
---|
| 63 | end |
---|
| 64 | |
---|
| 65 | %%% |
---|
| 66 | % refine the F by using all detected outliers and with point normalization |
---|
| 67 | F = u2Fdlt(u(:,inls),1); |
---|
| 68 | |
---|
| 69 | if no_sam == MAX_SAM |
---|
| 70 | warning(sprintf('RANSAC - termination forced after %d samples expected number of samples is %d', no_sam, exp_sam)); |
---|
| 71 | else |
---|
| 72 | disp(sprintf('RANSAC: %d samples, %d inliers out of %d points',no_sam,sum(inls),len)) |
---|
| 73 | end; |
---|
| 74 | |
---|
| 75 | return; |
---|