Tracker.h
Go to the documentation of this file.
00001 
00009 #ifndef _TRACKER_H_
00010 #define _TRACKER_H_
00011 
00012 #include <opencv2/core/core.hpp>
00013 #include <blort/Tracker/headers.h>
00014 #include <blort/Tracker/Timer.h>
00015 #include <blort/Tracker/Resources.h>
00016 #include <blort/Tracker/Distribution.h>
00017 #include <blort/Tracker/Predictor.h>
00018 #include <blort/TomGine/tgMathlib.h>
00019 #include <blort/Tracker/CDataFile.h>
00020 #include <blort/Tracker/ModelEntry.h>
00021 #include <blort/TomGine/tgLighting.h>
00022 
00024 namespace Tracking{
00025 
00026   const float pi = 3.14159265358979323846f;
00027 
00028   typedef std::vector<ModelEntry*> ModelEntryList;
00029 
00031   class Tracker{
00032   public:
00033     struct Parameter{
00034       TomGine::tgCamera::Parameter camPar;
00035       int model_id_count;
00036       int hypotheses_id_count;
00037       int num_particles;                                        // number of particles to draw for each frame
00038       int num_recursions;                                       // number of recursions for each image
00039       unsigned hypotheses_trials;                       // number of trials a hypothesis gets for convergence, until comparisson to original
00040       int convergence;                                  // convergence factor
00041       float edge_tolerance;                             // maximal angular deviation of edges to match in degrees
00042       unsigned int num_spreadings;              // number of spreadings during image processing
00043       unsigned int m_spreadlvl;                 // Width of edges in pixels (automatically adjusted)
00044       Particle variation;                                       // standard deviation of particle distribution in meter
00045       float minTexGrabAngle;                            // Angular threshold between view vector and face normal for grabing texture
00046       unsigned int max_kernel_size;             // Max. edgel comparison kernel (distance of neighbouring pixels taken into account)
00047       int kernel_size;                                  // Edgel comparison kernel (distance of neighbouring pixels taken into account)
00048       std::string modelPath;                            // Path to model recources
00049       std::string texturePath;                  // Path to texture recources
00050       std::string shaderPath;                           // Path to shader recources
00051       float model_sobel_th;                             // Threshold for sobel edge detection for model
00052       float image_sobel_th;                             // Threshold for sobel edge detection for image
00053       float c_th_base;                                  // Base confidence threshold for tracking quality detection
00054       float c_th_min;                                           // Minimum confidence threshold for tracking quality detection
00055       float c_th_fair;                                  // Fair confidence threshold for tracking quality detection
00056       float c_mv_not;                                           // Threshold for no movement detection
00057       float c_mv_slow;                                  // Threshold for slow movement detection
00058       float c_th_lost;                                  // Threshold for tracking lost detection
00059       float pred_no_convergence;                        // Part of particles of distribution voting for no convergence
00060 
00061       // Constructor (assigning default values)
00062       Parameter();
00063     };
00064 
00065   public:
00066     Tracker();
00067     ~Tracker();
00068 
00069     // Main functions (init, image_processing, tracking, reset)
00071     bool init(const char* trackINIFile, const char* camCalFile, const char* poseCalFile);
00072     bool init(const Parameter& trackParam);
00073 
00075     void loadImage(unsigned char* image, GLenum format=GL_BGR);
00079     virtual void image_processing(unsigned char* image, GLenum format=GL_BGR)=0;
00085     virtual void image_processing(unsigned char* image, const TomGine::tgModel &model, const TomGine::tgPose &pose, GLenum format=GL_BGR)=0;
00091     virtual void image_processing(unsigned char* image, int model_id, const TomGine::tgPose &pose, GLenum format=GL_BGR)=0;
00092 
00094     virtual bool track()=0;
00097     virtual bool track(int id)=0;
00098 
00100     void reset();
00103     void reset(int id);
00104 
00106     void resetUnlockLock();
00107 
00108     // Model handling
00111     int addModel(TomGine::tgModel& m, TomGine::tgPose& pose,  std::string label, bool bfc=true);
00112 
00119     int addModelFromFile(const char* filename, TomGine::tgPose& pose, std::string label, bool bfc=true);
00120 
00122     void removeModel(int id);
00123 
00124     //BENCE: never called
00125     //  /** @brief Adds a pose hypothesis to model */
00126     //  void addPoseHypothesis(int id, TomGine::tgPose &p, std::string label, bool bfc);
00127 
00129     ModelEntry* getModelEntry(int id);
00130 
00132     void getModelPose(int id, TomGine::tgPose& p);
00133 
00135     void getModelPoseLPF(int id, TomGine::tgPose& p);
00136 
00138     void getModelPoseCamCoords(int id, TomGine::tgPose& p);
00139 
00141     void getModelVelocity(int id, float &translational, float &angular);
00142 
00144     void getModelMovementState(int id, movement_state &m);
00145 
00147     void getModelQualityState(int id, quality_state &q);
00148 
00150     void getModelConfidenceState(int id, confidence_state &q);
00151 
00153     void getModelInitialPose(int id, TomGine::tgPose& p);
00154 
00156     void getModelConfidence(int id, float& c);
00157 
00159     void getModelConfidenceEdge(int id, float& c);
00160 
00162     void getModelConfidenceColor(int id, float& c);
00163 
00165     bool getModelPoint3D(int id, int x_win, int y_win, double& x3, double& y3, double& z3);
00166 
00168     void getModelMask(int id, Texture &mask);
00169 
00171     void getModelEdgeMask(int id, Texture &mask);
00172 
00174     bool getModelMaskOwnEdges(int id);
00175 
00177     void setModelInitialPose(int id, TomGine::tgPose& p);
00178 
00180     void setModelPredictor(int id, Predictor* predictor);
00181 
00183     void setModelLock(int id, bool lock);
00184 
00186     void setModelRecursionsParticle(int id, int num_recursions, int num_particles);
00187 
00189     void setModelPredictorNoConvergence(int id, float no_conv);
00190 
00192     void setModelMask(int id, Texture *mask=0);
00193 
00195     void setModelMaskOwnEdges(int id, bool masked);
00196 
00198     void saveModel(int id, const char* pathname);
00200     void saveModels(const char* pathname);
00201 
00203     void saveScreenshot(const char* filename);
00204 
00206     cv::Mat getImage();
00207 
00209     virtual void textureFromImage(bool force=false){}
00210     virtual void textureFromImage(int id, const TomGine::tgPose &pose, bool use_num_pixels=true){}
00211 
00213     virtual void untextureModels(){}
00214 
00215     // Drawing to screen (result, ...)
00217     virtual void drawResult(float linewidth=1.0f)=0;
00218     void drawModel(TomGine::tgPose p);
00219     void drawModel(const TomGine::tgModel &m, const TomGine::tgPose &p);
00220     virtual void drawTrackerModel(int id, const TomGine::tgPose &p, float linewidth=1.0f){};
00221     void drawModelWireframe(const TomGine::tgModel &m, const TomGine::tgPose &p, float linewidth=1.0f);
00222     void drawCoordinateSystem(float linelength=0.5f, float linewidth=1.0f, TomGine::tgPose pose=TomGine::tgPose());
00223     void drawCoordinates(float linelength=1.0f);
00224     void drawImage(unsigned char* image);
00225     void drawPixel(float u, float v, vec3 color=vec3(1.0,1.0,1.0), float size=1.0f);
00226     void drawPoint(float x, float y, float z, float size=1.0);
00227     void drawCalibrationPattern(float point_size=1.0f);
00228     void loadCalibrationPattern(const char* mdl_file);
00229     void drawTest();
00230     void printStatistics();
00231 
00232     // set parameters for texture tracking
00233     virtual void setKernelSize(int val){ }
00234     virtual void setEdgeShader(){ }
00235     virtual void setColorShader(){ }
00236 
00237     // Set Parameters
00238     void setFrameTime(double dTime);
00239     bool setCameraParameters(TomGine::tgCamera::Parameter cam_par);
00240     void setSpreadLvl(unsigned int val){ params.m_spreadlvl = val; }
00241 
00242     // Get Parameters
00243     float getCamZNear(){ return m_cam_perspective.GetZNear(); }
00244     float getCamZFar(){ return m_cam_perspective.GetZFar(); }
00245     unsigned int getSpreadLvl(){ return params.m_spreadlvl; }
00246 
00247     // get Flags
00248     bool getLockFlag(){ return m_lock; }
00249     bool getEdgesImageFlag(){ return m_draw_edges; }
00250     bool getDrawParticlesFlag(){ return m_showparticles; }
00251     int  getModelModeFlag(){ return m_showmodel; }
00252 
00253     // set Flags
00254     void setLockFlag(bool val);
00255     void setEdgesImageFlag(bool val){ m_draw_edges = val; }
00256     void setDrawParticlesFlag(bool val){ m_showparticles = val; }
00257     void setModelModeFlag(int val){ m_showmodel = val; }
00258 
00259     // Functions for analysing PDF
00260     virtual void evaluatePDF( int id,
00261                               float x_min, float y_min,
00262                               float x_max, float y_max,
00263                               int res,
00264                               const char* meshfile, const char* xfile){}
00265 
00266     virtual std::vector<float> getPDFxy(        Particle pose,
00267                                           float x_min, float y_min,
00268                                           float x_max, float y_max,
00269                                           int res,
00270                                           const char* filename=NULL, const char* filename2=NULL){ std::vector<float> a; return a;}
00271 
00272     virtual void savePDF(       std::vector<float> vPDFMap,
00273                           float x_min, float y_min,
00274                           float x_max, float y_max,
00275                           int res,
00276                           const char* meshfile, const char* xfile){}
00277 
00278     const Parameter getParams(){ return params; }
00279 
00280   protected:
00281     Parameter params;
00282 
00283     // Resources
00284     Texture* m_tex_frame;
00285     std::vector<Texture*> m_tex_frame_ip;
00286 
00287     std::vector<vec3> m_calib_points;
00288 
00289     TomGine::tgLighting m_lighting;
00290     ImageProcessor* m_ip;
00291 
00292     float m_ftime;
00293     Timer m_timer;
00294 
00295     // ModelEntry
00296     ModelEntryList m_modellist;
00297     ModelEntryList m_hypotheses;
00298 
00299     TomGine::tgCamera m_cam_perspective;
00300     TomGine::tgCamera m_cam_default;
00301 
00302     // Flags
00303     bool m_lock;
00304     bool m_showparticles;
00305     int  m_showmodel;
00306     bool m_draw_edges;
00307     bool m_tracker_initialized;
00308     bool m_drawimage;
00309 
00310     // Functions
00312     bool loadTrackParsFromINI(const char* inifile);
00313     bool loadCamParsFromINI(const char* camCalFile, const char* poseCalFile);
00314 
00315     void getGlError();
00316 
00317     void computeModelEdgeMask(ModelEntry* modelEntry, Texture &mask);
00318 
00319     virtual bool initInternal()=0;
00320     bool init();
00321     bool initGL();
00322 
00323   };
00324 
00325 } // namespace Tracking
00326 
00327 #endif


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12