Create a projective homography matrix with pitch/roll/yaw

13 visualizaciones (últimos 30 días)
Patrick
Patrick el 13 de Dic. de 2014
Comentada: Patrick el 11 de En. de 2015
Hi,
I am working with the imwarp() function where I can put in a picture and a 3x3 projective homography matrix. I got this matrix from the GeometricTransformEstimator but now I want to create such a matrix myself by using a pitch/roll/yaw angle.
I tried the matlab function angle2dcm(yaw, pitch, roll) which gives me a rotation matrix but it looks like it is not the same as a homography matrix. Is it even possible to do what I want?
Best Regards
  4 comentarios
Matt J
Matt J el 15 de Dic. de 2014
Editada: Matt J el 15 de Dic. de 2014
I still don't think you've defined what you're trying to compute. You mean you have 2 cameras separated by a known 3D rotation about the world origin? And you're trying to compute the homography relating the images of points from those cameras? You would need the camera calibration matrix for that.
Patrick
Patrick el 15 de Dic. de 2014
Yes you are right. I think you could describe it like that. I have the camera calibration matrix of my camera but I am not sure where to put it. Can you tell me the name of the thing I am trying to do? Maybe then I can find out how it works.

Iniciar sesión para comentar.

Respuesta aceptada

David Young
David Young el 15 de Dic. de 2014
Editada: David Young el 10 de En. de 2015
[ Edited: example changed and transpose of matrix in call to projective2d() inserted. See comments.]
It might be worth experimenting with the code below, which uses various of my functions. These are attached.
Possible stumbling blocks are connected with the direction of view of the camera (along the z-axis in the code below), and the default behaviour of imwarp(), which crops the output to the new corner positions of the image. This code compares the result of doing that with the result of keeping the transformed image in the same coordinates as the original image (using imwarp_same()), which allows the effects of the rotation to be seen more clearly.
By fiddling with the values of yaw, pitch, roll and the camera position vector you should be able to get a fix on what is going on and get behaviour that you expect.
example image
img = imread('peppers.png');
% Set angles here. Start with two of them set to zero and third set quite
% small to see the effect.
yaw = 0;
pitch = 0;
roll = -0.2;
% Set camera position here. To understand the effect of angles, move it
% along the z-axis and y-axis so it is above the centre of the top edge of
% the picture. Note that as cammoves is true in call to homography_matrix,
% the z-axis movement needs to be negative.
% The camera is looking along the z-axis.
campos = [size(img,2)/2; 0; -200];
% Construct a rotation matrix. My sign convention is opposite to
% angle2dcm, but I don't have the aerospace toolbox. Computed rmat agrees
% with example in angle2dcm documentation.
yawmat = rotation_matrix([0 0 1], -yaw); % about z
pitchmat = rotation_matrix([0 1 0], -pitch); % about y
rollmat = rotation_matrix([1 0 0], -roll); % about x
rmat = rollmat * pitchmat * yawmat; % zyx order - default for angle2dcm
% construct homography matrix
F = 100; % focal length
hmat = homography_matrix([], rmat, campos, F, true);
% construct projective2d object
tform = projective2d(hmat.');
% display original image and results
subplot(1,3,1);
imshow(img);
% show image warped and cropped
imw_crop = imwarp(img, tform);
subplot(1,3,2);
imshow(imw_crop);
% show image warped in same coordinate system as original
imw_same = imwarp_same(img, tform);
subplot(1,3,3);
imshow(imw_same); shg;
  7 comentarios
David Young
David Young el 10 de En. de 2015
Sorry about the delay - I missed your comment, and Answers doesn't have a notification mechanism. You are quite right, there was an error in my example. I'd forgotten that projective2d requires the matrix to be transposed. That is, it adopts the convention
[x y 1] = [u v 1] * T
where T is the transform matrix, but I always expect to use
[x y 1]' = T * [u v 1]'
When that is fixed, you do indeed get a result that matches what you expect. I'm editing the code to put in the transpose, and also to make the example demonstrate the perspective effect.
Patrick
Patrick el 11 de En. de 2015
Thanks a lot, this is exactly what I was looking for

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 15 de Dic. de 2014
Would the camera calibration capabilities of the Computer Vision System Toolbox help? http://www.mathworks.com/products/computer-vision/features.html#camera-calibration
  3 comentarios
Patrick
Patrick el 21 de Dic. de 2014
Hi,
thanks, I had a look at this but I have no idea how I can feed angles to this thing.
Image Analyst
Image Analyst el 21 de Dic. de 2014
Call them and ask for help. I have not used the camera calibration functionality of that toolbox so I'm not a good resource for that.

Iniciar sesión para comentar.

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by