4

I have an image captured using a standard camera, as shown in the setup below. I am fortunate enough to assume I know the focal length (in millimetres), the crop factor and the sensor size, and can assume the centre of projection is the centre of the image - so I know its position in pixels and in terms of the sensor.

I also know the angle of the camera with reference to the blue plane and its height above that plane. The camera only rotates in its x-axis, which we assume to be parallel to the world x-axis.

Setup of camera over plane

Now I need to get a metric rectification of the image such that I can measure an object on the blue plane in millimetres (in 2D).

I've been trying various things in Matlab to get this to work, but my results thus far have been disappointing. Clearly this is a plane-plane homography problem, and I think scale should be solvable based on the fact I know the sensor size and the number of pixels in it.

My searching led me to this similar question, but the methodology in the answers isn't working for me (explained further below): How to do perspective correction in Matlab from known Intrinsic and Extrinsic parameters?

I've tried calculating the intrinsic and extrinsic matrices, then getting a homography:

f = 4.9; % Focal length is given as 4.9mm
sensor_size = [6.17 4.55]; % Again in mm
cc = sensor_size ./ 2;

% Calculate intrinsic matrix
KK = [f 0 cc(1);0 f cc(2); 0 0 1];

theta = 21.8; % Angle of camera above plane, degrees
Rc = xrotate(theta) % xrotate fcn given below
Tc = [0 0 60]'; % Camera is 60mm above plane along camera z-axis

H = KK * [R(:,1) R(:,2) Tc];
figure;imshow(imtransform(I,maketform('projective',H), 'Size', image_size))

function R = xrotate( theta )
    R = [ 1 0 0; 
          0  cosd(theta) sind(theta);
          0 -sind(theta) cosd(theta) ];        
end

This unfortunately provides me with junk - given the full-sized original of this image:

Downscaled input image

I get this result from the above code:

Result of homography calculated using above

Given its only an x-axis rotation I would think we should get a trapezium shape as a result of the homography, but I don't seem to. Can anyone point to any obvious mistakes I've made here?

Community
  • 1
  • 1
n00dle
  • 5,949
  • 2
  • 35
  • 48

1 Answers1

0

You are mixing pixels and mm. Express matrix KK in pixel units, using the known image width and height as scaling factors.

Francesco Callari
  • 11,300
  • 2
  • 25
  • 40
  • Thanks, I was concerned that might be the case. Unfortunately, swapping these out for pixel values (scale calculated using the sensor size vs. image size) doesn't seem to vastly improve the result. – n00dle Jan 22 '16 at 10:20