Create a projective homography matrix with pitch/roll/yaw
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
Matt J
2014-12-15
编辑:Matt J
2014-12-15
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.
采纳的回答
David Young
2014-12-15
编辑:David Young
2015-1-10
[ 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 个评论
David Young
2015-1-10
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.
更多回答(1 个)
Image Analyst
2014-12-15
Would the camera calibration capabilities of the Computer Vision System Toolbox help? http://www.mathworks.com/products/computer-vision/features.html#camera-calibration
3 个评论
Image Analyst
2014-12-21
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!