Camera.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00033 
00034 
00035 /* TODO:
00036  Camera par must maintain (loading form a configuration file):
00037   - a Pose for the mounting parameters
00038   - size of frame
00039   - fps
00040   
00041   - a matrix for the intrinsic parameters or the following parameters:
00042    - focal length
00043    - field of view
00044    - skew
00045    - principal point coordinates
00046    - pixel ratio
00047   
00048   - color-space
00049   
00050  Camera class must provide (also using CameraVar class):
00051   - access to image
00052   - retrieving of new frame
00053   - recording of video stream
00054   - access to image as IplImage (backward compatibility - to be removed asap)
00055   - access to cv::Mat used to store the image
00056   - a Pose for the current pose of the camera (if estimated)
00057   
00058  TODO: check if we need CVD camera
00059 */
00060 #ifndef __CAMERA_H_
00061 #define __CAMERA_H_
00062 
00063 #ifdef MIP_HOST_APPLE
00064 #include <applePatch.h>
00065 #endif
00066 
00067 
00068 #include <assert.h>
00069 
00070 #include "opencv2/imgproc/imgproc.hpp"
00071 #include "opencv2/highgui/highgui.hpp"
00072 
00073 #include <baselib.h>
00074 #include <Resource.h>
00075 #include <stdlib.h>
00076 
00077 using namespace std;
00078 
00079 namespace MipResources{
00080  
00084  
00086  /* @{ */
00087  
00092  
00093 
00097  class CameraOptions : public Options {
00098   public:
00099    DecimalOption  *fLength;  
00100    IntOption    *device;  
00101    IntOption    *frameH;  
00102    IntOption    *frameW;  
00103    BoolOption   *videoLoop; 
00104       StringOption  *codec;     
00105 
00106    CameraOptions();
00107 
00108    string getObjectName() const {
00109     return "CameraOptions";
00110    }
00111  };
00112 
00116  class CameraPar{
00117   //  Camera par must maintain (loading form a configuration file):
00118   //   - a Pose for the mounting parameters
00119   //   - size of frame
00120   //   - fps
00121   //   
00122   //   - a matrix for the intrinsic parameters or the following parameters:
00123   //    - focal length
00124   //    - field of view
00125   //    - skew
00126   //    - principal point coordinates
00127   //    - pixel ratio
00128   //   
00129   //   - color-space
00130   private:
00131    // Parameters for image
00132    Decimal width;     
00133    Decimal height;     
00134    Decimal fps;      
00135    
00136    // Intrinsic parameters, those should be collected in a matrix
00137    Pose3D  mountingPose;   
00138    Decimal focalLength;   
00139    Decimal skew;       
00140    Decimal fieldOfView;   
00141    Decimal principalPointX; 
00142    Decimal principalPointY; 
00143    Decimal pixelRatio;    
00144   public:
00147    CameraPar(Decimal f = 0, Decimal w = 0, Decimal h = 0,
00148         Decimal rate = 0, Pose3D mPose = Pose3D(), Decimal skew = 0,
00149         Decimal fov  = 0, Decimal pPX = 0, Decimal pPY = 0,
00150         Decimal pR = 0);
00151    
00153    void setFocLength(Decimal newF);
00154 
00156    void setFrameSize(Decimal W, Decimal H);
00157 
00159    Decimal focLength() const;
00160  };
00161 
00162 
00166  class CameraVar{
00167   //    Camera class must provide (also using CameraVar class):
00168   //   - access to image
00169   //   - retrieving of new frame
00170   //   - recording of video stream
00171   //   - access to image as IplImage (backward compatibility - to be removed asap)
00172   //   - access to cv::Mat used to store the image
00173   //   - a Pose for the current pose of the camera (if estimated)
00174   protected:
00175    MipBaselib::Time   *lastTime;   
00176    MipBaselib::Time   *initTime;   
00177    IplImage *_img;          
00179    Position3D  *_position;
00180    Orientation3D *_orientation;
00181   public:
00183    CameraVar();
00184 
00189    CameraVar(IplImage* i, Position3D initPos, Orientation3D initOri);
00190 
00193    IplImage* getImage();
00194    
00196    void setImage(IplImage* i);
00197 
00199    void setInitTime(MipBaselib::Time t);
00200 
00202    void setLastTime(MipBaselib::Time t);
00203 
00205    MipBaselib::Time getLastTime();
00206 
00208    MipBaselib::Time getInitTime();
00209    
00211    Position3D* position() {
00212     return _position;
00213    }
00214    
00216    Orientation3D* orientation() {
00217     return _orientation;
00218    }
00219    
00221    void setPosition(Position3D newPos) {
00222     _position = new Position3D(newPos);
00223    }
00224    
00226    void setOrientation(Orientation3D newOri) {
00227     _orientation = new Orientation3D(newOri);
00228    }
00229 
00230  };
00231 
00232 
00237  class Camera : public Resource{
00238   protected:
00239    CameraOptions _options;  
00241    CameraPar* _par;  
00242    CameraVar* _var;  
00243    CvCapture* _cap;  
00245    cv::VideoCapture _device; 
00246    cv::Mat _image;      
00248   public:
00251    Camera(){  cout << "Camera constructor." << endl;};
00252    
00254    ~Camera();
00255 
00258    Camera(int argc, const char* argv[]);
00259 
00262 //   Camera(int device, Decimal fLength);
00263 
00266    virtual CameraVar* getVar(void){
00267     return _var;
00268    }
00269 
00272    virtual CameraPar* getPar(void){
00273     return _par;
00274    }
00275 
00278    virtual ResourcePlate getPlate() const;
00279 
00284    virtual bool getFrame(IplImage*& s, MipBaselib::Time& t);
00285 
00290    virtual bool getFrame(cv::Mat& s, Time& t);
00291    
00294    virtual bool recordLastFrame();
00295 
00300    virtual bool setResolution(double w, double h);
00301 
00305       virtual bool setCodec(char *c);
00306 
00311    virtual bool setFrameRate(double fr){}
00312 
00317    virtual bool setBrightness(double b){}
00318 
00323    virtual bool setContrast(double c){}
00324 
00329    virtual bool setSaturation(double s){}
00330 
00335    virtual bool setHue(double h){}
00336 
00339    virtual void videoLoop(){}
00340 
00341                         // Luca Ricci mod. //
00342                         virtual timeval getTimeStamp(){};
00343                         // *************** //
00344  };
00345 }; // end of namespace
00346 
00347 
00348 #endif
00349 
00350 /* @} */
00351 
00352 
00353 
00354 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6