问题
I have the same rectangle in an untransformed form and in a perspective form. Both, the coordinates from the untransformed form as well as from the perspective form are in the untransformed coordinate system.
Is there a way to reconstruct the transformation matrix which leads to this transformation?
I think it should be possible to do that by solving the 4 equations given by the 4 corners but I am not sure where to start.
// Edit: It looks like I am victim of a xy problem here. All answers are based in a 3d environment. But I have a rectangle on an image + I know the real dimensions of this rectangle. What I need to know is how to transform other known points onto the perspective image
回答1:
Note that you have 8 pairs of corresponding parameters (x and y for every point), and need to calculate 8 parameters of matrix using 8 equations
//four pairs of such equaions:
x' = (A * x + B * y + C) / (G * x + H * y + 1.0)
y' = (D * x + E * y + F) / (G * x + H * y + 1.0)
Theory of finding perspective transformation matrix is described in Paul Heckbert article.
C++ implementation could be found in antigrain library (file agg_trans_perspective.h
)
回答2:
One way is to plug in the values given in the transformation matrix. That has the merit of being easy and working, but it won't help you to understand it.
To understand the transform, draw a diagram with the screen vertical and looking top-down. Draw the eye. The line from the eye to the screen should be perpendicular. Then draw a point, somewhere off the screen. Then draw a line from the eye to the point, going through the screen.
It's then an exercise in highschool-level trigonometry to work out the projection of the point onto the screen.
来源:https://stackoverflow.com/questions/44759238/calculate-transformation-which-is-needed-to-transform-a-rectangle-into-its-persp