-
Notifications
You must be signed in to change notification settings - Fork 10
/
Stereo'.m
64 lines (54 loc) · 2.93 KB
/
Stereo'.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
% Auto-generated by stereoCalibrator app on 15-Jan-2017
%-------------------------------------------------------
% Define images to process
imageFileNames1 = {'I:\Robomaster\Left\WIN_20170115_11_02_36_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_02_45_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_02_49_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_02_52_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_02_56_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_02_59_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_01_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_03_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_05_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_07_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_10_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_13_Pro.jpg',...
'I:\Robomaster\Left\WIN_20170115_11_03_16_Pro.jpg',...
};
imageFileNames2 = {'I:\Robomaster\Right\WIN_20170115_11_02_36_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_02_45_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_02_49_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_02_52_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_02_56_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_02_59_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_01_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_03_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_05_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_07_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_10_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_13_Pro.jpg',...
'I:\Robomaster\Right\WIN_20170115_11_03_16_Pro.jpg',...
};
% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames1, imageFileNames2);
% Generate world coordinates of the checkerboard keypoints
squareSize = 20; % in units of 'mm'
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera
[stereoParams, pairsUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'mm', ...
'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', []);
% View reprojection errors
h1=figure; showReprojectionErrors(stereoParams, 'BarGraph');
% Visualize pattern locations
h2=figure; showExtrinsics(stereoParams, 'CameraCentric');
% Display parameter estimation errors
displayErrors(estimationErrors, stereoParams);
% You can use the calibration data to rectify stereo images.
I1 = imread(imageFileNames1{1});
I2 = imread(imageFileNames2{1});
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams);
% See additional examples of how to use the calibration data. At the prompt type:
% showdemo('StereoCalibrationAndSceneReconstructionExample')
% showdemo('DepthEstimationFromStereoVideoExample')