-
Notifications
You must be signed in to change notification settings - Fork 0
/
ransacH.asv
29 lines (26 loc) · 931 Bytes
/
ransacH.asv
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
function [H,ni,nf] = ransacH(pts1,pts2,MIN_INLIER_PER,TH,MAX_ITR)
nf = size(pts1,2);
MIN_INLIERS = round(MIN_INLIER_PER*nf);
maxInlierCount = 0;
H = zeros(3,3);
for i=1:MAX_ITR
sampleIdx = randperm(nf,4); % select 4 random points to estimate H
H1 = computeH(pts1(:,sampleIdx),pts2(:,sampleIdx));
pts3 = H1 * [pts1;ones(1,nf)];
pts3 = pts3(1:2,:)./repmat(pts3(3,:),2,1);
d = sum((pts2-pts3).^2,1);
inliers = find(d<TH);
inlierCount = length(inliers);
if inlierCount < MIN_INLIERS
continue;
end
if(inlierCount>maxInlierCount)
maxInlierCount = inlierCount;
ni = maxInlierCount;
H = computeH(pts1(:,inliers),pts2(:,inliers));
end
end
pts3 = H * [pts1;ones(1,nf)];
pts3 = pts3(1:2,:)./repmat(pts3(3,:),2,1);
d = sum(sum((pts2-pts3).^2,1);
end