core/vpgl/algo/vpgl_camera_compute.h
Go to the documentation of this file.
00001 // This is core/vpgl/algo/vpgl_camera_compute.h
00002 #ifndef vpgl_camera_compute_h_
00003 #define vpgl_camera_compute_h_
00004 //:
00005 // \file
00006 // \brief Several routines for computing different kinds of cameras from world-point correspondences.
00007 // \author Thomas Pollard
00008 // \date July 18, 2005
00009 //
00010 // Should template this class.
00011 
00012 #include <vpgl/vpgl_perspective_camera.h>
00013 #include <vpgl/vpgl_proj_camera.h>
00014 #include <vpgl/vpgl_affine_camera.h>
00015 #include <vcl_vector.h>
00016 #include <vgl/vgl_fwd.h>
00017 #include <vnl/vnl_fwd.h>
00018 
00019 //: Basic least squares solution for a general projective camera given corresponding world and image points.
00020 class vpgl_proj_camera_compute
00021 {
00022  public:
00023   //: Compute from two sets of corresponding points.
00024   // Put the resulting camera into \p camera
00025   // \return true if successful.
00026   static bool compute( const vcl_vector< vgl_homg_point_2d<double> >& image_pts,
00027                        const vcl_vector< vgl_homg_point_3d<double> >& world_pts,
00028                        vpgl_proj_camera<double>& camera );
00029   //: Compute from two sets of corresponding points.
00030   // Put the resulting camera into \p camera
00031   // \return true if successful.
00032   static bool compute( const vcl_vector< vgl_point_2d<double> >& image_pts,
00033                        const vcl_vector< vgl_point_3d<double> >& world_pts,
00034                        vpgl_proj_camera<double>& camera );
00035  private:
00036   //:default constructor (is private)
00037   vpgl_proj_camera_compute();
00038 };
00039 
00040 
00041 //: Basic least squares solution for an affine camera given corresponding world and image points.
00042 class vpgl_affine_camera_compute
00043 {
00044  public:
00045   //: Compute from two sets of corresponding points.
00046   // Put the resulting camera into \p camera
00047   // \return true if successful.
00048   static bool compute( const vcl_vector< vgl_point_2d<double> >& image_pts,
00049                        const vcl_vector< vgl_point_3d<double> >& world_pts,
00050                        vpgl_affine_camera<double>& camera );
00051  private:
00052   vpgl_affine_camera_compute();
00053 };
00054 
00055 
00056 //:Various methods for computing a perspective camera
00057 class vpgl_perspective_camera_compute
00058 {
00059  public:
00060   //: Compute from two sets of corresponding points.
00061   // Put the resulting camera into \p camera
00062   // \return true if successful.
00063   static bool compute( const vcl_vector< vgl_point_2d<double> >& image_pts,
00064                        const vcl_vector< vgl_point_3d<double> >& world_pts,
00065                        const vpgl_calibration_matrix<double>& K,
00066                        vpgl_perspective_camera<double>& camera );
00067 
00068 
00069   //: Uses the direct linear transform algorithm described in "Multiple
00070   // View Geometry in Computer Vision" to find the projection matrix,
00071   // and extracts the parameters of the camera from this projection matrix.
00072   // Requires: \p image_pts and \p world_pts are correspondences.
00073   //  \p image_pts is the projected form, and \p world_pts is the unprojected form.
00074   //  There need to be at least 6 points.
00075   // \returns true if successful.
00076   // \p err is filled with the two-norm of the projection error vector.
00077   // \p camera is filled with the perspective decomposition of the projection matrix.
00078   static bool compute_dlt ( const vcl_vector< vgl_point_2d<double> >& image_pts,
00079                             const vcl_vector< vgl_point_3d<double> >& world_pts,
00080                             vpgl_perspective_camera<double> &camera,
00081                             double &err);
00082 
00083   //: Compute from two sets of corresponding 2D points (image and ground plane).
00084   // \param ground_pts are 2D points representing world points with Z=0
00085   // The calibration matrix of \p camera is enforced
00086   // This computation is simpler than the general case above and only requires 4 points
00087   // Put the resulting camera into \p camera
00088   // \return true if successful.
00089   static bool compute( const vcl_vector< vgl_point_2d<double> >& image_pts,
00090                        const vcl_vector< vgl_point_2d<double> >& ground_pts,
00091                        vpgl_perspective_camera<double>& camera );
00092 
00093  private:
00094   vpgl_perspective_camera_compute();
00095 };
00096 
00097 #endif // vpgl_camera_compute_h_