Note that there are some explanatory texts on larger screens.

plurals
  1. POTransform Image using Roll-Pitch-Yaw angles (Image rectification)
    primarykey
    data
    text
    <p>I am working on an application where I need to rectify an image taken from a mobile camera platform. The platform measures roll, pitch and yaw angles, and I want to make it look like the image is taken from directly above, by some sort of transform from this information. </p> <p>In other words, I want a perfect square lying flat on the ground, photographed from afar with some camera orientation, to be transformed, so that the square is perfectly symmetrical afterwards. </p> <p>I have been trying to do this through OpenCV(C++) and Matlab, but I seem to be missing something fundamental about how this is done.</p> <p>In Matlab, I have tried the following:</p> <pre><code>%% Transform perspective img = imread('my_favourite_image.jpg'); R = R_z(yaw_angle)*R_y(pitch_angle)*R_x(roll_angle); tform = projective2d(R); outputImage = imwarp(img,tform); figure(1), imshow(outputImage); </code></pre> <p>Where R_z/y/x are the standard rotational matrices (implemented with degrees).</p> <p>For some yaw-rotation, it all works just fine:</p> <pre><code>R = R_z(10)*R_y(0)*R_x(0); </code></pre> <p>Which gives the result:</p> <p><img src="https://i.stack.imgur.com/pyiNq.jpg" alt="Image rotated 10 degrees about the Z-image axis"></p> <p>If I try to rotate the image by the same amount about the X- or Y- axes, I get results like this:</p> <pre><code>R = R_z(10)*R_y(0)*R_x(10); </code></pre> <p><img src="https://i.stack.imgur.com/cbZoE.jpg" alt="Image rotated 10 degrees about the X-image axis"></p> <p>However, if I rotate by 10 degrees, divided by some huge number, it starts to look OK. But then again, this is a result that has no research value what so ever:</p> <pre><code>R = R_z(10)*R_y(0)*R_x(10/1000); </code></pre> <p><img src="https://i.stack.imgur.com/kssGS.jpg" alt="Image rotated 10/1000 degrees about the X-image axis"></p> <p>Can someone please help me understand why rotating about the X- or Y-axes makes the transformation go wild? Is there any way of solving this without dividing by some random number and other magic tricks? Is this maybe something that can be solved using Euler parameters of some sort? Any help will be highly appreciated!</p> <p><strong>Update: Full setup and measurements</strong></p> <p>For completeness, the full test code and initial image has been added, as well as the platforms Euler angles: </p> <p>Code:</p> <pre><code>%% Transform perspective function [] = main() img = imread('some_image.jpg'); R = R_z(0)*R_y(0)*R_x(10); tform = projective2d(R); outputImage = imwarp(img,tform); figure(1), imshow(outputImage); end %% Matrix for Yaw-rotation about the Z-axis function [R] = R_z(psi) R = [cosd(psi) -sind(psi) 0; sind(psi) cosd(psi) 0; 0 0 1]; end %% Matrix for Pitch-rotation about the Y-axis function [R] = R_y(theta) R = [cosd(theta) 0 sind(theta); 0 1 0 ; -sind(theta) 0 cosd(theta) ]; end %% Matrix for Roll-rotation about the X-axis function [R] = R_x(phi) R = [1 0 0; 0 cosd(phi) -sind(phi); 0 sind(phi) cosd(phi)]; end </code></pre> <p>The initial image:</p> <p><img src="https://i.stack.imgur.com/m5e01.jpg" alt="enter image description here"></p> <p>Camera platform measurements in the BODY coordinate frame:</p> <pre><code>Roll: -10 Pitch: -30 Yaw: 166 (angular deviation from north) </code></pre> <p>From what I understand the Yaw-angle is not directly relevant to the transformation. I might, however, be wrong about this.</p> <p><strong>Additional info:</strong></p> <p>I would like specify that the environment in which the setup will be used contains no lines (oceanic photo) that can reliably used as a reference (the horizon will usually not be in the picture). Also the square in the initial image is merely used as a measure to see if the transformation is correct, and will not be there in a real scenario.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload