2015-01-07 22:56:18 +08:00
|
|
|
clear all;
|
|
|
|
clc;
|
2015-01-13 12:27:50 +08:00
|
|
|
clf;
|
2015-01-07 22:56:18 +08:00
|
|
|
import gtsam.*
|
|
|
|
|
2015-01-13 14:32:59 +08:00
|
|
|
%% define the options
|
|
|
|
options.fieldSize = Point2([100, 100]');
|
|
|
|
options.cylinderNum = 10;
|
|
|
|
options.poseNum = 20;
|
|
|
|
options.monoK = Cal3_S2(525,525,0,320,240);
|
|
|
|
options.stereoK = Cal3_S2Stereo(721,721,0.0,609,172,0.53715); % read from the VO calibration file
|
|
|
|
options.imageSize = Point2([640, 480]');
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% generate a set of cylinders and Samples
|
2015-01-13 14:32:59 +08:00
|
|
|
cylinderNum = options.cylinderNum;
|
2015-01-13 12:27:50 +08:00
|
|
|
cylinders = cell(cylinderNum, 1);
|
2015-01-07 22:56:18 +08:00
|
|
|
|
2015-01-13 14:32:59 +08:00
|
|
|
% It seems random generated cylinders doesn't work that well
|
|
|
|
% Now it set up a circle of cylinders
|
|
|
|
theta = 0;
|
2015-01-13 05:10:49 +08:00
|
|
|
for i = 1:cylinderNum
|
2015-01-13 14:32:59 +08:00
|
|
|
theta = theta + 2*pi / 10;
|
2015-01-14 05:33:47 +08:00
|
|
|
x = 10 * cos(theta) + options.fieldSize.x/2;
|
|
|
|
y = 10 * sin(theta) + options.fieldSize.y/2;
|
2015-01-13 14:32:59 +08:00
|
|
|
baseCentroid = Point2([x, y]');
|
2015-01-12 12:22:42 +08:00
|
|
|
cylinders{i,1} = cylinderSampling(baseCentroid, 1, 5, 1);
|
2015-01-07 22:56:18 +08:00
|
|
|
end
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% plot all the cylinders and sampled points
|
2015-01-09 23:33:53 +08:00
|
|
|
% now is plotting on a 100 * 100 field
|
2015-01-12 12:22:42 +08:00
|
|
|
figID = 1;
|
|
|
|
figure(figID);
|
2015-01-13 14:32:59 +08:00
|
|
|
plotCylinderSamples(cylinders, options.fieldSize, figID);
|
2015-01-09 23:33:53 +08:00
|
|
|
|
2015-01-14 05:33:47 +08:00
|
|
|
%% generate camera trajectories: a circle
|
|
|
|
KMono = Cal3_S2(525,525,0,320,240);
|
2015-01-12 12:22:42 +08:00
|
|
|
imageSize = Point2([640, 480]');
|
2015-01-14 05:33:47 +08:00
|
|
|
cameraPoses = cell(options.poseNum, 1);
|
2015-01-13 14:32:59 +08:00
|
|
|
% Generate ground truth trajectory r.w.t. the field center
|
|
|
|
theta = 0;
|
2015-01-14 05:33:47 +08:00
|
|
|
r = 40;
|
2015-01-13 14:32:59 +08:00
|
|
|
for i = 1:options.poseNum
|
|
|
|
theta = (i-1)*2*pi/options.poseNum;
|
2015-01-14 05:33:47 +08:00
|
|
|
t = Point3([r*cos(theta) + options.fieldSize.x/2, ...
|
|
|
|
r*sin(theta) + options.fieldSize.y/2, 10]');
|
|
|
|
camera = SimpleCamera.Lookat(t, ...
|
2015-01-13 14:32:59 +08:00
|
|
|
Point3(options.fieldSize.x/2, options.fieldSize.y/2, 0), ...
|
2015-01-14 05:33:47 +08:00
|
|
|
Point3([0,0,1]'), KMono);
|
|
|
|
cameraPoses{i} = camera.pose;
|
2015-01-12 12:22:42 +08:00
|
|
|
end
|
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% visibility validation
|
2015-01-13 12:27:50 +08:00
|
|
|
% for a simple test, it will be removed later
|
2015-01-14 05:33:47 +08:00
|
|
|
%visiblePoints3 = cylinderSampleProjection(cameras{1}, imageSize, cylinders);
|
2015-01-12 12:22:42 +08:00
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% plot all the projected points
|
|
|
|
%plotProjectedCylinderSamples(visiblePoints3, cameraPoses{1}, figID);
|
2015-01-12 12:22:42 +08:00
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% setp up monocular camera and get measurements
|
2015-01-14 05:33:47 +08:00
|
|
|
pts2dTracksMono = points2DTrackMonocular(KMono, cameraPoses, imageSize, cylinders);
|
2015-01-12 12:22:42 +08:00
|
|
|
|
2015-01-13 05:10:49 +08:00
|
|
|
%% set up stereo camera and get measurements
|
2015-01-13 12:27:50 +08:00
|
|
|
% load stereo calibration
|
|
|
|
calib = dlmread(findExampleDataFile('VO_calibration.txt'));
|
|
|
|
KStereo = Cal3_S2Stereo(calib(1), calib(2), calib(3), calib(4), calib(5), calib(6));
|
2015-01-13 14:32:59 +08:00
|
|
|
camerasStereo = cell(options.poseNum, 1);
|
2015-01-14 05:33:47 +08:00
|
|
|
|
|
|
|
%pts2dTracksStereo = points2DTrackStereo(KStereo, cameraPoses, imageSize, cylinders);
|
2015-01-07 22:56:18 +08:00
|
|
|
|
2015-01-13 12:27:50 +08:00
|
|
|
% plot the 2D tracks
|
2015-01-09 23:33:53 +08:00
|
|
|
|
2015-01-12 12:22:42 +08:00
|
|
|
% ToDo: plot the trajectories
|
|
|
|
%plot3DTrajectory();
|
2015-01-09 23:33:53 +08:00
|
|
|
|
2015-01-07 22:56:18 +08:00
|
|
|
|
|
|
|
|
2015-01-09 23:33:53 +08:00
|
|
|
|
2015-01-07 22:56:18 +08:00
|
|
|
|
|
|
|
|