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
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
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.
Size isnt really needed, and neither are proportions. And knowing which side is up is kind of irrelevant considering he's using photos/scans of documents. I doubt hes going to scan the back sides of them.
"Corner intersection" is the method to correct perspective. This might be of help:
http://stackoverflow.com/questions/530396/how-to-draw-a-perspective-correct-grid-in-2d
Draw a right isosceles triangle with those two vanishing points and a third point below the horizon (that is, on the same side of the horizon as the rectangle is). That third point will be our origin and the two lines to the vanishing points will be our axes. Call the distance from the origin to a vanishing point pi/2. Now extend the sides of the rectangle from the vanishing points to the axes, and mark where they intersect the axes. Pick an axis, measure the distances from the two marks to the origin, transform those distances: x->tan(x), and the difference will be the "true" length of that side. Do the same for the other axis. Take the ratio of those two lengths and you're done.