FeatExtrCam.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 
00027 
00028 #ifndef __FEAT_EXTRCAM_H_
00029 #define __FEAT_EXTRCAM_H_
00030 
00031 
00032 #ifdef MIP_HOST_APPLE
00033  #include <applePatch.h>
00034 #endif
00035 
00036 
00037 #include "HBstructs.h"
00038 #include <Time.h>
00039 #include <Camera.h>
00040 #include <VisualTracking.h>
00041 #include <Resource.h>
00042 #include <MobileRob.h>
00043 #include <MobileRob3D.h>
00044 #include <ReconKhCam.h>
00045 
00046 #include <Task.h>
00047 #include <SharedMem.h>
00048 #include <CommonOptions.h>
00049 #ifndef MIP_PLATFORM_ARM
00050 #include <DraWin.h>
00051 #endif
00052 #ifdef FOUND_VISP_LIBS
00053     #include <VisTrackVisp.h>
00054 #else
00055     #include <VisTrackCamshift.h>
00056 #endif
00057 
00058 using namespace MipResources;
00059 using namespace MipAlgorithms;
00060 
00061 namespace MipTasks{
00065 
00066 
00070 
00071 
00074  /* @{ */
00075 
00079  enum FeatExtrCamTypes{
00080   FEAT_EXTRCAM_CAMSHIFT,
00081   FEAT_EXTRCAM_TYPES_NUM
00082  };
00083 
00086  static const char * FeatExtrCamTypesNames[FEAT_EXTRCAM_TYPES_NUM] ={
00087   "Camshift"
00088  };
00089 
00093  enum FeatExtrCamStates{
00094   FEAT_EXTRCAM_FIRST_RUN,
00095   FEAT_EXTRCAM_NORMAL_RUN,
00096   FEAT_EXTRCAM_LAST_RUN,
00097   FEAT_EXTRCAM_STATES_NUM
00098  };
00099 
00102  static const char* FeatExtrCamStatesNames[FEAT_EXTRCAM_STATES_NUM] = {
00103   "FirstRun",
00104   "NormalRun",
00105   "LastRun"
00106  };
00107 
00108  class FeatExtrCamOptions : public Options {
00109   public:
00110    DecimalOption   *trimRoll;          
00111    DecimalOption   *trimPitch;         
00112    DecimalOption   *trimYaw;           
00113    IntOption       *algoType;          
00114    IntOption       *visDepth;          
00115    DecimalOption   *inKAngle;          
00116    DecimalOption   *inKfeatErr;        
00117    DecimalOption   *inKintegral;       
00118    IntOption       *heightCtrlType;    
00119                         StringOption    *log_path;          
00120                         StringOption    *log_name;          
00121                         BoolOption      *make_log;          
00122                         BoolOption      *offLine;
00123                         
00125    FeatExtrCamOptions();
00126    
00127    string getObjectName() const{
00128      return "FeatExtrCamOptions";
00129    }
00130  };
00131 
00132 
00133  class FeatExtrCamVar{
00134   public:
00135    CvMat *cv_Jv, *cv_Jomega;                   
00136    CvMat *cv_U, *cv_V, *cv_W,  *cv_JvInv;      
00137    CvMat *cv_Error, *cv_velContribute, *cv_omegaContribute, *cv_totalContribute; 
00138    CvMat *cv_desAngles;                        
00139    Decimal ControlAngles[2];                   
00140                         short ctrlEnable;
00141                         ofstream    _logFile;
00142                         int         _numrow;
00143  };
00144 
00148  class FeatExtrCamSharedMem : public SharedMem{
00149   public:
00152    void initSharedMem();
00153 
00157    void setMyProtrusions(PosiFeatures &protrusions, MotionModuleTState &protrusionsTState);
00158 
00162    void setMyCorners(PosiFeatures &corners, MotionModuleTState &cornersTState);
00163 
00166    bool printFeat();
00167 
00170    void setMyObervations(vector<Angle> &observ, MotionModuleTState &camObsTState);
00171  };
00182  class FeatExtrCam : public Task {
00183   private:
00184    static const TaskPlate _plate = FEC_TASK;  
00185 
00186    // Mandatory variables: timing for the scheduler
00187    static const long int  _maxDurSec    = 0, _maxDurUsec    = 100000;
00188    static const long int  _maxSamplPeriodSec = 0, _maxSamplPeriodUsec  = 50000;
00189    static const long int  _minSamplPeriodSec = 0, _minSamplPeriodUsec  = 20000;
00190 
00191    // Reources
00192    //Uav  *_uav;   ///< Uav performing the task.
00193                         MobileRob*  _mobileRob;
00194    Camera *_cam;   
00195                         FeatExtrCamSharedMem* _sharedMem;
00196 
00197                         #ifdef FOUND_VISP_LIBS
00198                             VisTrackVisp* _visTrack;  
00199                         #else
00200                             VisTrackCamshift* _visTrack;  
00201                         #endif
00202    // Algorithms
00203                         ReconKhCam* _visRecon;
00204 
00205 
00206    IplImage*   _frame;   
00207    ImageFeature  imgFeat;  
00208    Time t;        
00209 
00210    FeatExtrCamOptions _options; 
00211    FeatExtrCamVar*  _var;  
00212    FeatExtrCamStates  _state;  
00213    FeatExtrCamTypes  _types;  
00214 
00215                         stringstream s;
00216                         fstream _saveMeasures;
00217                         fstream _saveIds;
00218                         fstream _saveCamObsTState;
00219                         /*
00220                         #ifndef MIP_PLATFORM_ARM
00221    DraWin*      _draWin;
00222    unsigned int _drawList;
00223    bool         dwOn;
00224                         #endif
00225    */
00227    void _firstRun();
00228 
00230    void _normalRun();
00231 
00233    void _lastRun();
00234 
00235   public:
00237    FeatExtrCam(ResourcePointers resources, int argc, const char* argv[]);
00238 
00240    ~FeatExtrCam();
00241 
00243    TaskPlate getPlate() const {
00244     return _plate;
00245    }
00246 
00249    Time getMaxDuration(){
00250     return Time(_maxDurSec,_maxDurUsec);
00251    }
00253    Time getMaxSamplPeriod(){
00254     return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00255    }
00257    Time getMinSamplPeriod(){
00258     return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00259    }
00260 
00262    TaskOutputs run();
00263  };
00264 }; // end namespace MipTasks
00265 
00266 
00267 
00268 
00269 
00270 
00271 #endif
00272 
00273 
00274 /* @} */

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