camera.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00018  *
00019  */
00020 /************************************************************
00021  *      camera.h                                                                                                *
00022  *      Header file for the camera object used to store and             *
00023  *      manipulate camera data.                                                                 *
00024  *                                                                                                                      *
00025  *      Geoffrey Biggs, Toby Collet 2003                                                *
00026  ************************************************************/
00027 
00028 #ifndef __CAMERA_H
00029 #define __CAMERA_H
00030 
00031 #include <libthjc/geometry.h>
00032 #include <libthjc/vector3d.h>
00033 #include <libthjc/matrix.h>
00034 
00035 
00036 
00037 #include <list>
00038 using namespace std;
00039 
00040 //      Used to identify whether a camera is the left or right camera
00041 typedef enum { CAM_LEFT, CAM_RIGHT }    CAM_ID;
00042 
00043 //      Pair of coordinates for calibration
00044 class CalibrationPair
00045 {
00046 public:
00047         double x; // image coord
00048         double y;
00049         double X; // respective 3d coord
00050         double Y;
00051         double Z;
00052 };
00053 
00054 //      This class represents a camera.
00055 class Camera
00056 {
00057 public:
00058 
00059         Camera() : T(3,1), R(3,3), K(3,3) , P(3,4), RT(4,4), PFull(4,4), BPFull(4,4) {Pairs=NULL;WorkingPairs=NULL;};
00060 
00061 
00062         int width, height;                      // The width and height of the camera image in pixels
00063 
00064         double Ncx; // Number of sensor elements in row
00065         double Nfx; // number of pixels in row
00066         double dx; // distance between sensor elements (mm/pixel)
00067         double dy;
00068         double Cx; // location of center of frame in pixels
00069         double Cy;
00070 
00071 
00072         double sx; // scale
00073         double sy;
00074         Matrix T; // Translation Matrix
00075         Matrix R; // Rotation Matrix
00076         Matrix K;
00077         Matrix P;
00078         Matrix RT;
00079         double f; // Effective Focal length
00080         double kappa1; // Distortion Coefficient
00081         Matrix PFull;
00082         Matrix BPFull;
00083 
00084         unsigned int NumPairs;
00085         CalibrationPair * WorkingPairs;
00086         CalibrationPair * Pairs;
00087 
00088 
00089         Camera& operator= (const Camera &rhs)
00090         {
00091 /*              position = rhs.position;
00092                 direction = rhs.direction;
00093                 focalLength = rhs.focalLength;*/
00094                 width = rhs.width;
00095                 height = rhs.height;
00096                 return *this;
00097         }
00098 
00099         // Accessor Functions
00100         double GetTx() const;
00101         double GetTy() const;
00102         double GetTz() const;
00103         double GetRx() const;
00104         double GetRy() const;
00105         double GetRz() const;
00106 
00107         void SetTx(double Value);
00108         void SetTy(double Value);
00109         void SetTz(double Value);
00110         void SetRx(double Value);
00111         void SetRy(double Value);
00112         void SetRz(double Value);
00113         
00114         double GetFocalDistance() const;
00115         void SetFocalDistance(double Value);
00116 
00117         void UpdateRT();
00118 
00119         // Evaluation Functions
00120         list<Point2D> GetProjectedPoints() const;
00121         Matrix GetErrMatrix() const;
00122         Matrix Get3DErrMatrix() const;
00123 
00124         
00125         // 3d helpers
00126         Ray GetBPRay(Point2D Point) const;
00127         Point2D PixelToPoint(Point2D Pixel) const;
00128         Vector3D Point2DToPoint3D(Point2D Point) const;
00129         Vector3D CRFToWRF(Vector3D Point3D_CRF) const;
00130 
00131         Point2D ProjectPoint(Vector3D WorldPoint) const;
00132 
00133 public:
00134         void CalcApprox_f_Tz ();
00135         bool LoadIntrinsicParams (char *fileName);
00136         void Calibrate(list<CalibrationPair> &points);
00137         list<CalibrationPair> & LoadCalibPairs (list<Point2D> &points, list<CalibrationPair> &pairs, char * CalibFile);
00138         void Calibrate_SA();
00139 private:
00140 //      void CalcApprox_f_Tz(unsigned int NumPairs, CalibrationPair * WorkingPairs);
00141 };
00142 
00143 Matrix solve_RPY_transform (Matrix R);
00144 Matrix apply_RPY_transform ( double R, double P, double Y);
00145 
00146 
00147 #endif

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1