-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.m
67 lines (53 loc) · 1.49 KB
/
test.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
clear all;
close all;
folder = 'data';
%get the K camera calibration matrix
K = [568.996140852, 0, 643.21055941;
0, 568.988362396, 477.982801038;
0, 0, 1];
%parse the data
[Mu, Mv, V, RGB] = ParseData(folder);
%get the correspondences between two images
img1Num = 1;
img2Num = 2;
[img1Pts, img2Pts, V, RGB] = getCorrespondences(Mu, Mv, V, RGB,img1Num, img2Num);
%get the inliers of the data between the corresponding points
[y1, y2, idx] = GetInliersRANSAC(img1Pts, img2Pts);
%get the fundamental matrix
F = EstimateFundamentalMatrix(y1, y2);
%get the essential matrix
E = EssentialMatrixFromFundamentalMatrix(F, K);
%get the camera pose
[Cset, Rset] = ExtractCameraPose(E);
%find the Xset
Xset = cell(4,1);
%Camera 1 is the origin
C1 = zeros(3,1);
R1 = eye(3);
%find the Xset
for i = 1:4
%get the ith C and R
C2 = Cset{i};
R2 = Rset{i};
%do linear triangulation
x = LinearTriangulation(K, C1, R1, C2, R2, y1, y2);
Xset{i} = x;
end
%disamniguate the camera pose and get the best camera for camera 2
[C, R, X0,inFront] = DisambiguateCameraPose(Cset, Rset, Xset);
X0 = X0(inFront,:);
y1 = y1(inFront,:);
y2 = y2(inFront,:);
%plot the point cloud
figure;
RGBIdx = RGB(idx,:);
RGBIdx = RGB(inFront,:);
PC3Dshow(X0, {C1,C},{R1,R},RGBIdx);
%plot cameras and points
scale = 5;
figure;
PlotCamerasAndPoints({C1,C},{R1,R}, X0, scale);
%plot the camera projection
firstImg = imread('data/image0000002.bmp');
figure;
plot_reprojection(firstImg, R, C, K, X0, y2);