-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable construction/init of CalRigMLStro from "Rig Specification" (official name tbd) YAML file. This empowers users with calibration parameters from 3rd party sources. Note that CalRigMLStro relies on MATLAB/Vision routines for vision, triangulation, etc.
- Loading branch information
1 parent
488e82e
commit 54f8bf5
Showing
3 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
classdef CalibratedCamera < handle | ||
properties | ||
ImageSize % [nr nc] | ||
FocalLengths % [fx fy] | ||
PrincipalPoint % [px py] | ||
Skew % scalar | ||
RadialDistortions % [k2 k4] | ||
Rotation % [rx ry rz] rodrigues vec | ||
Translation % [tx ty tz] | ||
end | ||
methods | ||
function obj = CalibratedCamera(s) | ||
for fn = fieldnames(s)', f=fn{1}; | ||
try | ||
obj.(f) = s.(f); | ||
catch | ||
warning('Ignoring unrecognized field: %s', f); | ||
end | ||
end | ||
end | ||
|
||
function camInts = getMatlabCameraIntrinsics(obj) | ||
camInts = cameraIntrinsics(... | ||
obj.FocalLengths,obj.PrincipalPoint,obj.ImageSize,... | ||
'Skew',obj.Skew,... | ||
'RadialDistortion',obj.RadialDistortions... | ||
); | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
classdef CameraSet < handle | ||
properties | ||
NumCameras | ||
CameraNames | ||
Cameras | ||
end | ||
|
||
methods | ||
function obj = CameraSet(s) | ||
if ischar(s) | ||
s = ReadYaml(s); | ||
end | ||
obj.NumCameras = s.NumCameras; | ||
obj.CameraNames = s.CameraNames; | ||
|
||
for icam=1:s.NumCameras | ||
cam = s.CameraNames{icam}; | ||
camObjs(icam) = CalibratedCamera(s.(cam)); %#ok<AGROW> | ||
end | ||
fprintf(1,'Read information for %d cameras: %s.\n',s.NumCameras, ... | ||
String.cellstr2CommaSepList(s.CameraNames)); | ||
|
||
obj.Cameras = camObjs; | ||
end | ||
|
||
function [R,t] = getXformCams(obj,cam1,cam2) | ||
% Get/compute matrices R,T that convert from cam1 coordsys to | ||
% cam2coordsys; defined by | ||
% | ||
% [x2;y2;z2] = R*[x1;y1;z1] + t | ||
|
||
c1 = obj.Cameras(cam1); | ||
c2 = obj.Cameras(cam2); | ||
|
||
R1 = rodrigues(c1.Rotation); | ||
t1 = c1.Translation(:); | ||
R2 = rodrigues(c2.Rotation); | ||
t2 = c2.Translation(:); | ||
|
||
R = R2/R1; | ||
t = -R*t1 + t2; | ||
end | ||
|
||
function sp = getMatlabStereoParameters(obj) | ||
if obj.NumCameras~=2 | ||
error('stereoParameters conversion only avaiable when NumCameras==2.'); | ||
end | ||
|
||
cams = obj.Cameras; | ||
sp = struct(); | ||
sp.CameraParameters1 = cams(1).getMatlabCameraIntrinsics; | ||
sp.CameraParameters2 = cams(2).getMatlabCameraIntrinsics; | ||
|
||
[R,t] = obj.getXformCams(1,2); | ||
sp.RotationOfCamera2 = R; | ||
sp.TranslationOfCamera2 = t; | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters