Question

I have 3 points in a 3D space of which I know the exact locations. Suppose they are: (x0,y0,z0), (x1,y1,z1) and (x2,y2,z2).

Also I have a camera that is looking at these 3 points and I know the 2D locations of those three points on camera view plane. So for example (x0,y0,z0) will be (x0',y0'), and (x1,y1,z1) will be (x1',y1') and (x2,y2,z2) will be (x2',y2') from the camera's point of view.

What is the easiest way to find the projection matrix that will project those 3D points into 2D points on camera view plane. We don't know anything about the camera location.

Was it helpful?

Solution

This gives you two sets, each of three equations in 3 variables:

a*x0+b*y0+c*z0 = x0'
a*x1+b*y1+c*z1 = x1'
a*x2+b*y2+c*z2 = x2'

d*x0+e*y0+f*z0 = y0'
d*x1+e*y1+f*z1 = y1'
d*x2+e*y2+f*z2 = y2'

Just use whatever method of solving simultaneous equations is easiest in your situation (it isn't even hard to solve these "by hand"). Then your transformation matrix is just ((a,b,c)(d,e,f)).

...

Actually, that is over-simplified and assumes a camera pointed at the origin of your 3D coordinate system and no perspective.

For perspective, the transformation matrix works more like:

               ( a, b, c, d )   ( xt )
( x, y, z, 1 ) ( e, f, g, h ) = ( yt )
               ( i, j, k, l )   ( zt )

( xv, yv ) = ( xc+s*xt/zt, yc+s*yt/zt ) if md < zt;

but the 4x3 matrix is more constrained than 12 degrees of freedom since we should have

a*a+b*b+c*c = e*e+f*f+g*g = i*i+j*j+k*k = 1
a*a+e*e+i*i = b*b+f*f+j*j = c*c+g*g+k*k = 1

So you should probably have 4 points to get 8 equations to cover the 6 variables for camera position and angle and 1 more for scaling of the 2-D view points since we'll be able to eliminate the "center" coordinates (xc,yc).

So if you have 4 points and transform your 2-D view points to be relative to the center of your display, then you can get 14 simultaneous equations in 13 variables and solve.

Unfortunately, six of the equations are not linear equations. Fortunately, all of the variables in those equations are restricted to the values between -1 and 1 so it is still probably feasible to solve the equations.

OTHER TIPS

Your camera has (at least) 7 degrees of freedom - 3 for position, 3 for orientation and 1 for FOV. I'm sure someone will correct me if I'm wrong, but it doesn't seem like 3 points are enough for a full solution.

For a generalised solution to this problem, look up 'View Correlation' in Graphics Gems II.

What you are looking for is called a Pose Estimation algorithm. Have a look at the POSIT implementation in OpenCV: http://opencv.willowgarage.com/documentation/c/calib3d_camera_calibration_and_3d_reconstruction.html#posit

You will need four or more points, and they may not lie in the same plane.

A tutorial for this implementation is here: http://opencv.willowgarage.com/wiki/Posit

Do take care though: in the tutorial a square viewport is used, so all view-coordinates are in the -1,-1 to 1,1 range. This leads one to assume that these should be in the camera coordinate system (before aspect-ratio correction). This is not the case, so if you use a viewport with e.g. a 4:3 aspect ratio then your input coordinates should be in the -1.3333,-1 to 1.3333,1 range.

By the way, if your points must lie in the same plane, then you can also look at the CameraCalibration algorithm from OpenCV, but this is more involved to set up and requires more points as input. However it will also yield you the distortion information and intrinsic parameters of your camera.

I don't think there is enough information to find a definitive solution. Without knowing your camera location and without knowing your view plane, there is an infinite number of matrices that can solve this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top