-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRealsenseCalib.m
74 lines (63 loc) · 3.92 KB
/
RealsenseCalib.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
73
74
% Auto-generated by cameraCalibrator app on 19-Sep-2023
%-------------------------------------------------------
% Define images to process
imageFileNames = {'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/0.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/13.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/14.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/2.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/21.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/23.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/25.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/3.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/36.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/37.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/41.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/42.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/44.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/47.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/49.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/52.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/54.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/57.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/58.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/59.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/62.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/69.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/73.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/74.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/75.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/79.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/80.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/81.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/85.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/90.jpg',...
'/home/alexander/catkin_ws/src/ROS-Nursing-Robot-MQP-23-24/91.jpg',...
};
% Detect calibration pattern in images
detector = vision.calibration.monocular.CheckerboardDetector();
[imagePoints, imagesUsed] = detectPatternPoints(detector, imageFileNames);
imageFileNames = imageFileNames(imagesUsed);
% Read the first image to obtain image size
originalImage = imread(imageFileNames{1});
[mrows, ncols, ~] = size(originalImage);
% Generate world coordinates for the planar pattern keypoints
squareSize = 23; % in units of 'millimeters'
worldPoints = generateWorldPoints(detector, 'SquareSize', squareSize);
% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'millimeters', ...
'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ...
'ImageSize', [mrows, ncols]);
% View reprojection errors
h1=figure; showReprojectionErrors(cameraParams);
% Visualize pattern locations
h2=figure; showExtrinsics(cameraParams, 'CameraCentric');
% Display parameter estimation errors
displayErrors(estimationErrors, cameraParams);
% For example, you can use the calibration data to remove effects of lens distortion.
undistortedImage = undistortImage(originalImage, cameraParams);
% See additional examples of how to use the calibration data. At the prompt type:
% showdemo('MeasuringPlanarObjectsExample')
% showdemo('StructureFromMotionExample')
disp(cameraParams.Intrinsics.IntrinsicMatrix)