Main Page | Report this Page
 
Computers Forum Index  »  Computer - Graphics (Algorithms)  »  2D Transformation Problem (I think?)
Page 1 of 1    

2D Transformation Problem (I think?)

Author Message
kcamhi
Posted: Sat Jun 04, 2005 5:03 pm
Guest
I have what I thought was a simple geometry problem but I'm stumped on
it. After some research it seems to be in the class of problems called
2D transformations. Would you mind pointing me in the right direction
on this? Thanks!

I have a camera pointed at a rectangular 2D area. The camera is off
center (say high and to the right) so that the rectangle appears
distorted to the camera.

I detect a point within the rectangle with the camera.

How do I translate the coordinates I'm seeing in the camera to the
"real" coordinates that the point represents on the rectangle?

I can get calibration data points for the 4 corners of the rectangle in
the camera (or any other points on the rectangle if the math is
easier):

For Example
Here's some actual test data from the camera:
The camera "sees" the four corners of my rectangle as:
261,54 540,60

280,258 534,319

It then read the center point as 386,176

The 4 points that are halfway from the middle of the rectangle to the
corners were:
322,113 456,124

329,220 456,245

To map this back to the "real" rectangle that is, say, 400x300 I would
want to transform these sample data points to, roughly:
center: 200,150
halfway to corners: 100,75 300,75 100,225 300,225

What I'm hoping to get is a simple algorithm or formula(s) for taking
calibration readings I get for the corner points (which I can control)
and transforming any future reading I take in the space into it's
"real" coordinates on the rectangle.

Any help would be much appreciated.

To the extent this involves any libraries, I'm using the .net
environment.

Thanks!
 
Guest
Posted: Sat Jun 04, 2005 5:03 pm
Yes, that's a perspective 2D-2D transform. You'll need only
four points in the image area x,y and the respective points
in the object area u,v .
These four pairs of coordinates define the mapping law.
It's found by solving eight linear equations. Then any
coordinates can be mutually converted between x,y and u,v.

The 'center' is the intersection of the diagonals of the
quadriliterals.

Illustrated doc, about 250kBytes:
http://www.fho-emden.de/~hoffmann/persprect13052005.pdf

Please note: in my example for the rectification of a house
facade the object coordinates of the corners are not known.
They are estimated.
In your application the corners are known.

Best regards --Gernot Hoffmann
 
Horst Kraemer
Posted: Sat Jun 04, 2005 7:03 pm
Guest
"kcamhi" <kcamhi@msn.com> wrote:

Quote:
I have what I thought was a simple geometry problem but I'm stumped on
it. After some research it seems to be in the class of problems called
2D transformations. Would you mind pointing me in the right direction
on this? Thanks!

I have a camera pointed at a rectangular 2D area. The camera is off
center (say high and to the right) so that the rectangle appears
distorted to the camera.

I detect a point within the rectangle with the camera.

How do I translate the coordinates I'm seeing in the camera to the
"real" coordinates that the point represents on the rectangle?

I can get calibration data points for the 4 corners of the rectangle in
the camera (or any other points on the rectangle if the math is
easier):

For Example
Here's some actual test data from the camera:
The camera "sees" the four corners of my rectangle as:
261,54 540,60

280,258 534,319

It then read the center point as 386,176

The 4 points that are halfway from the middle of the rectangle to the
corners were:
322,113 456,124

329,220 456,245

To map this back to the "real" rectangle that is, say, 400x300 I would
want to transform these sample data points to, roughly:
center: 200,150
halfway to corners: 100,75 300,75 100,225 300,225

What I'm hoping to get is a simple algorithm or formula(s) for taking
calibration readings I get for the corner points (which I can control)
and transforming any future reading I take in the space into it's
"real" coordinates on the rectangle.

Any help would be much appreciated.

I'm including a C sample program which performs the reconstruction of
original coordinates (u,v) from picture coordinates (x,y) for a
projective mapping. The input are the four transformed vertices of a
rectangle. The transformed rectangle is remapped to a unit square.
You`ll have to scale the output (u,v) according to the aspect ratio of
the original rectangle (this ratio cannot be reconstructed from the
picture).

#include <stdio.h>

double p0[2]={10,10}; /* -> (0,0) */
double p1[2]={40, 1}; /* -> (1,0) */
double p2[2]={20,40}; /* -> (0,1) */
double p3[2]={50,50}; /* -> (1,1) */

double x=40, y=1; /* Picture coordinates of a sample point */

int main()
{
double c[3]; /* scaling factors */
double m[3][3]; /* matrix */
double t[3];
double u,v; /* original coordinates */

int i,j;


m[0][0]=p1[1]-p2[1];m[0][1]=p2[0]-p1[0];m[0][2]=p1[0]*p2[1]-p1[1]*p2[0];

m[1][0]=p2[1]-p0[1];m[1][1]=p0[0]-p2[0];m[1][2]=p2[0]*p0[1]-p2[1]*p0[0];

m[2][0]=p0[1]-p1[1];m[2][1]=p1[0]-p0[0];m[2][2]=p0[0]*p1[1]-p0[1]*p1[0];

c[0] = (p1[0]-p3[0])*(p2[1]-p3[1])-(p1[1]-p3[1])*(p2[0]-p3[0]);
c[1] = (p2[0]-p3[0])*(p0[1]-p3[1])-(p2[1]-p3[1])*(p0[0]-p3[0]);
c[2] = (p0[0]-p3[0])*(p1[1]-p3[1])-(p0[1]-p3[1])*(p1[0]-p3[0]);


/* Transformation from (x,y) nach (u,v) */

for (i=0;i<3;i++)
t[i]=(m[i][0]*x+m[i][1]*y+m[i][2])/c[i];

u = t[1]/(t[1]+t[2]-t[0]);
v = t[2]/(t[1]+t[2]-t[0]);

printf("%10.5f%10.5f\n",u,v);


return 0;
}

Hope it helps
Horst
 
kcamhi
Posted: Sun Jun 05, 2005 4:47 pm
Guest
Thank you so much for the quick and very helpful information!!!
 
kcamhi
Posted: Sun Jun 05, 2005 4:49 pm
Guest
Horst - thank you so much! I really appreciate the help!
 
Guest
Posted: Sun Jun 05, 2005 5:02 pm
Thanks for the feedback. The doc was updated and contains
now the calculation of the center (diagonal intersection).

Best regards --Gernot Hoffmann
 
Guest
Posted: Sun Jun 05, 2005 5:02 pm
Horst,

That's not generally true:
'You`ll have to scale the output (u,v) according to the aspect
ratio of the original rectangle (this ratio cannot be recon-
structed from the picture).'

The aspect ratio can be reconstructed if the camera view line is
rotated by TWO angles relative to the object-rectangle normal.
Maybe an academic question ...

http://www.fho-emden.de/~hoffmann/sans04012001.pdf

Best regards --Gernot Hoffmann
 
kcamhi
Posted: Mon Jun 06, 2005 9:07 pm
Guest
Horst - I have plugged this in and it works beautifully. Thank you
thank you!!!
 
 
Page 1 of 1    
All times are GMT
The time now is Sat Jul 04, 2009 10:01 pm