proportions of a perspective-deformed rectangle

后端 未结 10 1582
萌比男神i
萌比男神i 2020-11-29 17:31

Given a 2d picture of a rectangle distorted by perspective:

\"enter

I know tha

相关标签:
10条回答
  • 2020-11-29 18:05

    On the question of why the results give h/w rather then w/h: I'm wondering if the expression of Equation 20 above is correct. Posted is:

           whRatio = sqrt (
                (n2*A.transpose()^(-1) * A^(-1)*n2.transpose()) / 
                (n3*A.transpose()^(-1) * A^(-1)*n3.transpose())
               ) 
    

    When I try to execute that with OpenCV, I get an exception. But everything works correctly when I use the following equation which to me looks more like Equation 20: But based on Equation 20, it looks like it should be:

            whRatio = sqrt (
                (n2.transpose()*A.transpose()^(-1) * A^(-1)*n2) /
                (n3.transpose()*A.transpose()^(-1) * A^(-1)*n3)
               )
    
    0 讨论(0)
  • 2020-11-29 18:05

    You need more information, that transformed figure could come from any parallelogram given an arbitrary perspective.

    So I guess you need to do some kind of calibration first.

    Edit: for those who said that I was wrong, here goes the mathematical proof that there are infinite combinations of rectangles/cameras that yield to the same projection:

    In order to simplify the problem (as we only need the ratio of the sides) let's assume that our rectangle is defined by the following points: R=[(0,0),(1,0),(1,r),(0,r)] (this simplification is the same as transforming any problem to an equivalent one in an affine space).

    The transformed polygon is defined as: T=[(tx0,ty0),(tx1,ty1),(tx2,ty2),(tx3,ty3)]

    There exists a transformation matrix M = [[m00,m01,m02],[m10,m11,m12],[m20,m21,m22]] that satisfies (Rxi,Ryi,1)*M=wi(txi,tyi,1)'

    if we expand the equation above for the points,

    for R_0 we get: m02-tx0*w0 = m12-ty0*w0 = m22-w0 = 0

    for R_1 we get: m00-tx1*w1 = m10-ty1*w1 = m20+m22-w1 = 0

    for R_2 we get: m00+r*m01-tx2*w2 = m10+r*m11-ty2*w2 = m20+r*m21+m22-w2 = 0

    and for R_3 we get: m00+r*m01-tx3*w3 = m10+r*m11-ty3*w3 = m20 + r*m21 + m22 -w3 = 0

    So far we have 12 equations, 14 unknown variables (9 from the matrix, 4 from the wi, and 1 for the ratio r) and the rest are known values (txi and tyi are given).

    Even if the system weren't underspecified, some of the unknowns are multiplied among themselves (r and mi0 products) making the system non linear (you could transform it to a linear system assigning a new name to each product, but you'll end still with 13 unknowns, and 3 of them being expanded to infinite solutions).

    If you can find any flaw in the reasoning or the maths, please let me know.

    0 讨论(0)
  • 2020-11-29 18:07

    Update

    After reading your update, and looking at the first reference (Whiteboard scanning and image enhancement), I see where the missing point is.

    The input data of the problem is a quadruple (A,B,C,D), AND the center O of the projected image. In the article, it corresponds to the assumption u0=v0=0. Adding this point, the problem becomes constrained enough to get the aspect ratio of the rectangle.

    The problem is then restated as follows: Given a quadruple (A,B,C,D) in the Z=0 plane, find the eye position E(0,0,h), h>0 and a 3D plane P such that the projection of (A,B,C,D) on P is a rectangle.

    Note that P is determined by E: to get a parallelogram, P must contain parallels to (EU) and (EV), where U=(AB)x(CD) and V=(AD)x(BC).

    Experimentally, it seems that this problem has in general one unique solution, corresponding to a unique value of the w/h ratio of the rectangle.

    alt text alt text

    Previous Post

    No, you can't determine the rectangle ratio from the projection.

    In the general case, a quadruple (A,B,C,D) of four non collinear points of the Z=0 plane is the projection of infinitely many rectangles, with infinitely many width/height ratios.

    Consider the two vanishing points U, intersection of (AB) and (CD) and V, intersection of (AD) and (BC), and the point I, intersection of the two diagonals (AC) and (BD). To project as ABCD, a parallelogram of center I must lie on a plane containing the line parallel to (UV) through point I. On one such plane, you can find many rectangles projecting to ABCD, all with a different w/h ratio.

    See these two images done with Cabri 3D. In the two cases ABCD is unchanged (on the gray Z=0 plane), and the blue plane containing the rectangle is not changed either. The green line partially hidden is the (UV) line and the visible green line is parallel to it and contains I.

    alt text alt text

    0 讨论(0)
  • 2020-11-29 18:08

    it is impossible to know the width of this rectangle without knowing the distance of the 'camera'.

    a small rectangle viewed from 5 centimeters distance looks the same as a huge rectangle as seen from meters away

    0 讨论(0)
提交回复
热议问题