![]() ![]() This is now in the form of Ax=b and the solution can be obtained with x = A\b. Multiply both sides with the denominator: (c20*xi c21*yi c22) * ui = c00*xi c01*yi c02 You get the formulas for projection transformation: c00*xi c01*yi c02 Start with the equation for one point: | c00 c01 c02 | | xi | | w*ui |Ĭonvert this to a system of equations, solve ui and vi, and eliminate w. So how does it work? The linear system can be recreated by the following steps: This system of equations is smaller as it avoids solving for W and M33 (called c22 by OpenCV). * Coefficients are calculated by solving linear system: The source code for this function is available on github with this description: /* Calculates coefficients of perspective transformation OpenCV has a neat function that does this called getPerspectiveTransform. What I'm actually trying to achieve is some kind of vector graphics editing program where the user can drag the corners of a shape's bounding box to transform it, while internally the transformation matrix is calculated.Īnd actually I need this in JavaScript, but if I can't even solve this in MATLAB I'm completely stuck. Furthermore there might be inputs that have no solution for M at all, but let's not worry about this for now. Writing this as a system of linear equations one could simply fix one of the entries of M to get a single solution. And here I'm stuck.Īlso M*A=B*W does not have a single solution for M, because every multiple of M is the same transformation. Until it hit me that encapsulating (M*W) would not be possible, since one is a 3x3 matrix and the other a 4x4 matrix. ![]() However despite trying every possible rearrangement I didn't managed to do so. If I could rearrange the equation into the form x*A=B or A*x=B where x would be something like M*W I could solve it and knowing the solution for M*W would maybe be enough already. So A and B are now completely known and I have to solve this equation for M and W. Where W is a diagonal matrix with the factors w1.w4 for every point in B on the diagonal. To take account of these unknown factors I write the equation as M*A=B*W Cause in homogeneous coordinates every multiple of a vector is the same point and I don't know which multiple I'll get. ![]() I know the coordinates of the points after transformation, but I don't know the exact B, because there is the factor w and it's not necessary 1 after a homogeneous transformation. So the equation is M*A=B and this can be solved for M in MATLAB by M = B/A or M = (A'\B')'.īut it's not that easy. ![]() To calculate all points simultaneously I write them together in one matrix A and analogously for the transformed points in a matrix B: | P1.x P2.x P3.x P4.x | The calculation for one point would be: | M11 M12 M13 | | P1.x | | w*P1'.x | If the matrix is not known, how can I calculate it from the given points? The perspective transformation is calculated in homogeneous coordinates and defined by a 3x3 matrix M. I've got coordinates of 4 points in 2D that form a rectangle and their coordinates after a perspective transformation has been applied. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |