4 ms·
A word of warning about solutions to this problem. The "easy" version states it this way: the mapping you want takes (x,y) to ((ax+by+c)/(gx+hy+i),(dx+ey+f)/(gx
by gjm11 11y ago
A word of warning about solutions to this problem. The "easy" version states it this way: the mapping you want takes (x,y) to ((ax+by+c)/(gx+hy+i),(dx+ey+f)/(gx+hy+i)) for some a,b,c,d,e,f,g,h,i -- a general "projective transformation". If you decide ahead of time exactly what rectangle you want to map to, you have 8 constraints on a..i (two coordinates for each of four corners) and one irrelevant degree of freedom (if you multiply all of a..i by the same constant, nothing changes) so you have "exactly enough" information to find those parameters. So you solve the equations and you're done.
This works, provided your measured positions are perfectly accurate, but it isn't the best you can do. The reason is that a single projection actually has one degree of freedom less than a general projective transformation. (Three parameters to say where your camera is located. Three to say how it's rotated. One scaling factor. Total is 7 rather than 8.) This means that there's an extra (slightly hairy) constraint on the parameters a..i, which turns out to mean that the aspect ratio of the rectangle you're mapping to is determined for you.
Imposing that constraint will give you (1) more information -- you won't have to know ahead of time what aspect ratio you have -- and (2) a more accurately estimated transformation.
You can find more details of this stuff in, e.g., this PDF document: http://people.csail.mit.edu/bkph/articles/Harmful.pdf http://people.csail.mit.edu/bkph/articles/Harmful.pdf .