Skip to content

Commit

Permalink
add file for last commit re #375
Browse files Browse the repository at this point in the history
  • Loading branch information
allenleetc committed Apr 29, 2022
1 parent 73b7ac2 commit 4f4e374
Showing 1 changed file with 71 additions and 9 deletions.
80 changes: 71 additions & 9 deletions matlab/user/CalRigMLStro.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
nonMLinit = false; % if true, obj is not initialized from MATLAB stereo calibration
calSess % scalar Session from ML Stro calibration; or if .nonMLinit, scalar struct mirroring calSession object

eplineComputeMode = 'mostaccurate'; % either 'mostaccurate' or 'fastest'
eplineComputeMode = 'caltech'; % one of 'caltech' or 'zray'
end
properties (Dependent)
stroParams
Expand Down Expand Up @@ -45,7 +45,6 @@
function T = get.TRL(obj)
T = -obj.RLR'*obj.TLR;
end
%function s = get.int(obj)
function s = getInt(obj)
sp = obj.stroParams;

Expand Down Expand Up @@ -99,7 +98,7 @@
obj.nonMLinit = isYamlRig;
obj.int = obj.getInt();

obj.eplineComputeMode = 'mostaccurate';
obj.eplineComputeMode = 'caltech';
%obj.autoCalibrateProj2NormFuncTol();
obj.proj2NormFuncTol = nan; % AL20220302 no longer used

Expand Down Expand Up @@ -707,20 +706,76 @@ function rperrPlot(rperrcam1,rperrcam2)
function [xEPL,yEPL,Xc1,Xc1OOB] = ...
computeEpiPolarLine(obj,iView1,xy1,iViewEpi,roiEpi,varargin)

Xc1 = [];
Xc1OOB = [];
switch obj.eplineComputeMode
case 'mostaccurate'
[xEPL,yEPL,Xc1,Xc1OOB] = obj.computeEpiPolarLineBase(iView1,xy1,iViewEpi,roiEpi,varargin{:});
case 'caltech'
[xEPL,yEPL] = ...
obj.computeEpiPolarLineCaltech(iView1,xy1,iViewEpi,roiEpi,varargin{:});
case 'zray'
[xEPL,yEPL,Xc1,Xc1OOB] = ...
obj.computeEpiPolarLineZRay(iView1,xy1,iViewEpi,roiEpi,varargin{:});
case 'fastest'
warningNoTrace('DEVELOPMENT CODEPATH.');
% This codepath will err if 3rd/4th args are requested
[xEPL,yEPL] = obj.computeEpiPolarLineEPline(iView1,xy1,iViewEpi,roiEpi,varargin{:});
otherwise
error('''eplineComputeMode'' property must be either ''mostaccurate'' or ''fastest''.');
error('Unrecognized value of ''eplineComputeMode'' property.');
end
end

function [xEPL,yEPL] = ...
computeEpiPolarLineCaltech(obj,iView1,xy1,iViewEpi,roiEpi,varargin)

% "view"/"target" nomenclature here a little confusing
% "view": where the EP line will be drawn; corresponds to iViewEpi
% "target": origin of click/xy1; corresponds to iView1
if iView1 == 1 % iViewEpi==2
view_R = obj.RLR;
view_T = obj.TLR;
ints_view = obj.int.cam2;
ints_tgt = obj.int.cam1;
else % iView1==2, iViewEpi==1
view_R = obj.RRL;
view_T = obj.TRL;
ints_view = obj.int.cam1;
ints_tgt = obj.int.cam2;
end
view_fc = ints_view.fc;
view_cc = ints_view.cc-1;
view_kc = ints_view.kc;
view_alpha_c = ints_view.alpha_c;
target_fc = ints_tgt.fc;
target_cc = ints_tgt.cc-1;
target_kc = ints_tgt.kc;
target_alpha_c = ints_tgt.alpha_c;

xLp = [xy1(1), xy1(2)] - 1;
xLp = xLp';
epipole = compute_epipole2(xLp, view_R, view_T, ...
view_fc, view_cc, view_kc, view_alpha_c, ...
target_fc, target_cc, target_kc, target_alpha_c,...
'roi',roiEpi);
xEPL = epipole(1,:) + 1;
yEPL = epipole(2,:) + 1;

% we passed roiEpi to compute_epipole2 above, so we should already be
% ballpark correct, but crop strictly so our axes don't get messed
% up.
CROP_ROI = true;
if CROP_ROI
xlo = roiEpi(1);
xhi = roiEpi(2);
ylo = roiEpi(3);
yhi = roiEpi(4);
tfrm = xEPL<xlo | xEPL>xhi | yEPL<ylo | yEPL>yhi;
xEPL(tfrm) = [];
yEPL(tfrm) = [];
end
end

function [xEPL,yEPL,Xc1,Xc1OOB] = ...
computeEpiPolarLineBase(obj,iView1,xy1,iViewEpi,roiEpi,varargin)
computeEpiPolarLineZRay(obj,iView1,xy1,iViewEpi,roiEpi,varargin)
%
% Xc1: [3 x nz] World coords (coord sys of cam/iView1) of EPline
% Xc1OOB: [nz] indicator vec for Xc1 being out-of-view in iViewEpi
Expand All @@ -744,7 +799,7 @@ function rperrPlot(rperrcam1,rperrcam2)
%Zc1 = 1:.25:5e2;
Xc1 = [xn1(1)*z1Range; xn1(2)*z1Range; z1Range];

switch projectionmeth
switch projectionmeth
case 'worldToImage'
sp = obj.stroParams;
cpEpiFld = ['CameraParameters' num2str(iViewEpi)];
Expand All @@ -765,6 +820,10 @@ function rperrPlot(rperrcam1,rperrcam2)
else
assert(false);
end
% AL 20220428: there was a reason we use imPointsUD here to crop;
% maybe due to a rig with v high distortions. Probably a special
% case though and better to just crop using imPoints (or in
% caller, to share crop code with other methods)
Xc1OOB = imPointsUD(:,1)<roiEpi(1) | imPointsUD(:,1)>roiEpi(2) |...
imPointsUD(:,2)<roiEpi(3) | imPointsUD(:,2)>roiEpi(4);
imPoints(Xc1OOB,:) = nan;
Expand Down Expand Up @@ -917,6 +976,9 @@ function rperrPlot(rperrcam1,rperrcam2)
end
function [fc,cc,kc,alpha_c] = camParams2Intrinsics(camParams)
% convert ML-style intrinsics to Bouget-style
%
% Note: cc is still 1-based not 0-based!
% Note: alpha_c has a slightly different defn compared to .Skew!

fc = camParams.FocalLength(:);
assert(numel(fc)==2);
Expand All @@ -934,7 +996,7 @@ function rperrPlot(rperrcam1,rperrcam2)
tandistort = camParams.TangentialDistortion;
kc([3 4]) = tandistort;

alpha_c = camParams.Skew;
alpha_c = camParams.Skew/fc(1);
assert(isscalar(alpha_c));
end
function cs = rigYaml2CalSess(s)
Expand Down

0 comments on commit 4f4e374

Please sign in to comment.