2015-01-13 05:10:49 +08:00
|
|
|
function pts2dTracksMono = points2DTrackMonocular(K, cameraPoses, imageSize, cylinders)
|
2015-01-12 12:20:50 +08:00
|
|
|
% Assess how accurately we can reconstruct points from a particular monocular camera setup.
|
|
|
|
% After creation of the factor graph for each track, linearize it around ground truth.
|
|
|
|
% There is no optimization
|
|
|
|
% @author: Zhaoyang Lv
|
|
|
|
|
|
|
|
import gtsam.*
|
|
|
|
|
|
|
|
%% create graph
|
|
|
|
graph = NonlinearFactorGraph;
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
pointNoiseSigma = 0.1;
|
2015-01-12 12:20:50 +08:00
|
|
|
poseNoiseSigmas = [0.001 0.001 0.001 0.1 0.1 0.1]';
|
2015-01-13 05:10:49 +08:00
|
|
|
|
|
|
|
%% add a constraint on the starting pose
|
2015-01-12 12:20:50 +08:00
|
|
|
posePriorNoise = noiseModel.Diagonal.Sigmas(poseNoiseSigmas);
|
|
|
|
firstPose = cameraPoses{1};
|
|
|
|
graph.add(PriorFactorPose3(symbol('x', l), firstPose, posePriorNoise));
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
cameraPosesNum = length(cameraPoses);
|
|
|
|
|
|
|
|
%% add measurements and initial camera & points values
|
|
|
|
pointsNum = 0;
|
|
|
|
cylinderNum = length(cylinders);
|
|
|
|
for i = 1:cylinderNum
|
|
|
|
pointsNum = pointsNum + length(cylinders{i}.Points);
|
|
|
|
end
|
2015-01-12 12:20:50 +08:00
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
measurementNoise = noiseModel.Isotropic.Sigma(2, measurementNoiseSigma);
|
|
|
|
|
|
|
|
pts3d = {};
|
2015-01-12 12:20:50 +08:00
|
|
|
initialEstimate = Values;
|
|
|
|
for i = 1:cameraPosesNum
|
2015-01-13 05:10:49 +08:00
|
|
|
camera = SimpleCamera(K, cameraPoses{i});
|
|
|
|
|
|
|
|
pts3d.pts{i} = cylinderSampleProjection(camera, imageSize, cylinders);
|
|
|
|
pts3d.camera{i} = camera;
|
|
|
|
|
|
|
|
for j = 1:length(pts3d.pts{i}.Z)
|
|
|
|
graph.add(GenericProjectionFactorCal3_S2(pts3d.pts{i}.Z{j}, ...
|
|
|
|
measurementNoise, symbol('x', i), symbol('p', j), camera.K) );
|
2015-01-12 12:20:50 +08:00
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
point_j = pts3d.pts{i}.data{j}.retract(0.1*randn(3,1));
|
|
|
|
initialEstimate.insert(symbol('p', j), point_j);
|
|
|
|
end
|
|
|
|
|
|
|
|
pose_i = camera.pose.retract(0.1*randn(6,1));
|
|
|
|
initialEstimate.insert(symbole('x', i), pose_i);
|
2015-01-12 12:20:50 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% Print the graph
|
|
|
|
graph.print(sprintf('\nFactor graph:\n'));
|
|
|
|
|
2015-01-12 12:20:50 +08:00
|
|
|
marginals = Marginals(graph, initialEstimate);
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% get all the 2d points track information
|
|
|
|
ptIdx = 0;
|
|
|
|
for i = 1:pointsNum
|
|
|
|
if isempty(pts3d.pts{i})
|
|
|
|
continue;
|
|
|
|
end
|
|
|
|
%pts2dTrackMono.pts2d = pts3d.pts{i}
|
|
|
|
pts2dTracksMono.cov{ptIdx} = marginals.marginalCovariance(symbol('p',i));
|
2015-01-12 12:20:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|