Hi, Tim. You have mentioned the method of calibration using Matlab and aniposelib. I would appreciate it if you could do me a favour to check if the steps are enough for using Matlab and aniposelib calibration. Many thanks.
Aniposelib calibration:
import numpy as np
from aniposelib.boards import CharucoBoard, Checkerboard
from aniposelib.cameras import Camera, CameraGroup
from aniposelib.utils import load_pose2d_fnames
2. Matlab programming calibration:
Question: should add InitialIntrinsicMatrix&InitialRadialDistortion generated by estimateCameraParameters(), and do calibration again to get the new InitialIntrinsic parameter?
%% 1. Read the images
numImages = 30;
files = cell(1, numImages);
for i = 1:numImages
files{i} = fullfile('calibration', sprintf('image%d.tif, i));
end
% Display one of the calibration images
magnification = 25;
I = imread(files{1});
figure; imshow(I, 'InitialMagnification', magnification);
title('One of the Calibration Images');
%% 2. Computer intrinsic matrix (K, R distortion and T distortion)
% Detect the checkerboard corners in the images.
[imagePoints, boardSize] = detectCheckerboardPoints(files);
% Generate the world coordinates of the checkerboard corners in the
% pattern-centric coordinate system, with the upper-left corner at (0,0).
squareSize = 25; % in millimeters
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
Hi, Tim. You have mentioned the method of calibration using Matlab and aniposelib. I would appreciate it if you could do me a favour to check if the steps are enough for using Matlab and aniposelib calibration. Many thanks.
vidnames = [['calib-charuco-camA-compressed.MOV'], ['calib-charuco-camB-compressed.MOV'], ['calib-charuco-camC-compressed.MOV']]
cam_names = ['A', 'B', 'C']
n_cams = len(vidnames)
board = CharucoBoard(7, 10, square_length=25, # here, in mm but any unit works marker_length=18.75, marker_bits=4, dict_size=50)
the videos provided are fisheye, so we need the fisheye option
cgroup = CameraGroup.from_names(cam_names, fisheye=False)
this will take a few minutes
it will detect the charuco board in the videos,
then calibrate the cameras based on the detections, using iterative bundle adjustment
cgroup.calibrate_videos(vidnames, board) cgroup.dump('calibration.toml') cgroup = CameraGroup.load('calibration.toml')
%% 1. Read the images numImages = 30; files = cell(1, numImages); for i = 1:numImages files{i} = fullfile('calibration', sprintf('image%d.tif, i)); end
% Display one of the calibration images magnification = 25; I = imread(files{1}); figure; imshow(I, 'InitialMagnification', magnification); title('One of the Calibration Images');
%% 2. Computer intrinsic matrix (K, R distortion and T distortion) % Detect the checkerboard corners in the images. [imagePoints, boardSize] = detectCheckerboardPoints(files);
% Generate the world coordinates of the checkerboard corners in the % pattern-centric coordinate system, with the upper-left corner at (0,0). squareSize = 25; % in millimeters worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera. imageSize = [size(I, 1), size(I, 2)]; [cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ... 'EstimateSkew', true, 'EstimateTangentialDistortion', true, ... 'NumRadialDistortionCoefficients', 3, 'WorldUnits', 'millimeters', ... 'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ... 'ImageSize', [mrows, ncols]);
% Evaluate calibration accuracy. figure; showReprojectionErrors(cameraParams); title('Reprojection Errors');
%% 3. Computer extrinsic parameters (R, t) imOrig = imread(fullfile('calibration', 'image20.tif')); figure; imshow(imOrig, 'InitialMagnification', magnification); title('Input Image');
[im, newOrigin] = undistortImage(imOrig, cameraParams, 'OutputView', 'full'); figure; imshow(im, 'InitialMagnification', magnification); title('Undistorted Image');
% Detect the checkerboard. [imagePoints, boardSize] = detectCheckerboardPoints(im); imagePoints = imagePoints + newOrigin; % adds newOrigin to every row of imagePoints
% Compute rotation and translation of the camera. [R, t] = extrinsics(imagePoints, worldPoints, cameraParams);