Camera Calibration/Parameters help - distance/pixel ratio?

11 views (last 30 days)
Hi,
I am trying to calculate a distance per pixel ratio for a single camera in matlab. The camera is to face a planar surface, perpendicular to the camera, however the distance between the camera and the surface is likely to change dependent on the setup.
I intent to use the standard Matlab checkerboard as a means of "calibrating" (calculating the distance/pixel ratio, and have thus far computed the camera extrinsics and located the checkerboard points. the distance/pixel is required so that I can estimate the speed of an object tracked through the frame at this planar distance. Is there an easy way of extracting this from the extrinsics or a way of getting matlab to give me the distance between each corner detected and its nearest neighbours so that I can calculate this by hand?
Thank you in advance!
if true
close all; clear all; clc
%
% load camera intrinsics (cameraParams)
load newCameraParams
%
% load image
imOrig = imread((fullfile('C:\Users\...\Documents\MATLAB\check0003.tif')));
%
% Undistort image, calc. new origin
[im, newOrigin] = undistortImage(imOrig, newCameraParams, 'OutputView', 'full');
%
% Compute Extrinsics for camera
% Detect the checkerboard (reference points) in image
[imagePoints, boardSize] = detectCheckerboardPoints(im);
undistortedPoints = undistortPoints(imagePoints, newCameraParams);
%
% Generate the world coordinates of the checkerboard corners in the
% pattern-centric coordinate system, with the upper-left corner at (0,0).
squareSize = 18.25; % in millimeters
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% Compute rotation and translation of the camera relative to checkerboard
[R, t] = extrinsics(imagePoints, worldPoints, newCameraParams);
%
% plot figure of corrected image & corner points
figure; imshow(im); title('Corrected lens distortion & detected corners');
hold on
plot(imagePoints(:,1), imagePoints(:,2), '+r');
axis('on')
hold off
end

Answers (1)

Dima Lisin
Dima Lisin on 5 Jun 2015
Hi Yale,
You can actually do better than a distance/pixel ratio. If you know the extrinsics between the camera and the plane, then you can map a point in the image to a point on that plane using the pointsToWorld method of cameraParameters. See this example.
This way the plane does not even have to be perpendicular to the camera's axis.
  2 Comments
Yale Brewer
Yale Brewer on 5 Jun 2015
Hi,
I had discovered this, but was slightly wary of the computation time required as I am looking to be tracking objects at around 90fps... I suppose I had better give this a go thanks!
Dima Lisin
Dima Lisin on 5 Jun 2015
Well, pointsToWorld boils down to matrix multiplication, which MATLAB is very good at. I would not expect that to be a bottleneck, and I would be more worried about the speed of detection and tracking.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!