-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperEstimateRelativePose.m
More file actions
66 lines (59 loc) · 1.98 KB
/
Copy pathhelperEstimateRelativePose.m
File metadata and controls
66 lines (59 loc) · 1.98 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [orientation, location, inlierIdx,CEM,EPPfail] = ...
helperEstimateRelativePose(matchedPoints1, matchedPoints2, cameraParams)
mem=-1;
EPPfail=false;
if ~isnumeric(matchedPoints1)
matchedPoints1 = matchedPoints1.Location;
end
if ~isnumeric(matchedPoints2)
matchedPoints2 = matchedPoints2.Location;
end
CEM=true;
for i = 1:200
% Estimate the essential matrix.
[E, inlierIdx,status] = estimateEssentialMatrix(matchedPoints1, matchedPoints2,...
cameraParams,'Confidence',99,'MaxNumTrials',200,'MaxDistance' ,0.5);
if status~=0
EPPfail=true;
orientation=NaN;
location=NaN;
inlierIdx=NaN;
return;
end
%estimates the essential matrix from corresponding points in a pair of images using the M-estimator SAmple
%Consensus (MSAC) algorithm.
% Make sure we get enough inliers
if sum(inlierIdx) / numel(inlierIdx) < .3% originally this was .3
continue;
end
% Get the epipolar inliers.
inlierPoints1 = matchedPoints1(inlierIdx, :);
inlierPoints2 = matchedPoints2(inlierIdx, :);
% Compute the camera pose from the fundamental matrix. Use half of the
% points to reduce computation.
[orientation, location, validPointFraction] = ...
relativeCameraPose(E, cameraParams, inlierPoints1(1:2:end, :),...
inlierPoints2(1:2:end, :));
% validPointFraction is the fraction of inlier points that project in
% front of both cameras. If the this fraction is too small, then the
% fundamental matrix is likely to be incorrect.
if validPointFraction > 0.6
return;
end
if mem<validPointFraction
mem= validPointFraction;
Ori= orientation;
Loc=location;
Inl=inlierIdx;
end
end
% After 200 attempts validPointFraction is still too low and best match
% will send out
CEM=false;
orientation=Ori;
location=Loc;
inlierIdx=Inl;
clear Ori;
clear Loc;
clear Inl;
end