-
Notifications
You must be signed in to change notification settings - Fork 1
/
createCameraParameters.m
73 lines (46 loc) · 1.71 KB
/
createCameraParameters.m
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
67
68
69
70
71
72
function [camParam] = createCameraParameters(imageSize, focalLength, camPositions, camRotations, varargin)
%CONSTRUCTCAMERAPARAMETERS Creates a cameraParameters object from inputs
% Detailed explanation goes here
p = inputParser;
p.addParameter('specifyTargetPoses', false, @islogical);
p.parse(varargin{:});
% Check which format rotations are given in
if size(camRotations, 3) == 1
% Given rotations are angles, convert to rotation matrices
for pInd = 1:size(camRotations, 2)
Rs(:, :, pInd) = rotationVectorToMatrix( deg2rad(camRotations(:, pInd)) ); %#ok<AGROW>
end
else
% Given rotations are already rotation matrices
Rs = camRotations;
end
camParam = cameraParameters;
camParam = camParam.toStruct;
% Ideal camera with centered principal point
cx = imageSize(1)/2+0.5;
cy = imageSize(2)/2+0.5;
camParam.ImageSize = imageSize([2 1]);
camParam.K = [focalLength 0 cx; 0 focalLength cy; 0 0 1];
% No distortions
camParam.RadialDistortion = [0 0 0];
camParam.TangentialDistortion = [0 0];
for pInd = 1:size(camPositions, 2)
R = Rs(:, :, pInd);
pos = camPositions(:, pInd);
if p.Results.specifyTargetPoses
% No need to do anything, poses were already given as extrinsics
extR = R;
extPos = pos;
else
% Convert camera positions to pattern poses
[extR, extPos] = cameraPoseToExtrinsics(R, pos);
end
extrinsics.ang(pInd, :) = rotationMatrixToVector(extR);
extrinsics.pos(pInd, :) = extPos;
%camRotations(:, :, pInd) = R;
end
camParam.RotationVectors = extrinsics.ang;
camParam.TranslationVectors = extrinsics.pos;
% Create cameraParameters object from inputs
camParam = cameraParameters(camParam);
end