ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
vpMbKltTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbKltTracker.h 4338 2013-07-23 14:29:30Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Model based tracker using only KLT
35  *
36  * Authors:
37  * Romain Tallonneau
38  * Aurelien Yol
39  *
40  *****************************************************************************/
46 #ifndef vpMbKltTracker_h
47 #define vpMbKltTracker_h
48 
49 #include <visp/vpConfig.h>
50 
51 #ifdef VISP_HAVE_OPENCV
52 
53 #include <visp/vpMbTracker.h>
54 #include <visp/vpKltOpencv.h>
55 #include <visp/vpMbtKltPolygon.h>
56 #include <visp/vpMeterPixelConversion.h>
57 #include <visp/vpPixelMeterConversion.h>
58 #include <visp/vpDisplayX.h>
59 #include <visp/vpMbtKltXmlParser.h>
60 #include <visp/vpHomography.h>
61 #include <visp/vpRobust.h>
62 #include <visp/vpSubColVector.h>
63 #include <visp/vpSubMatrix.h>
64 #include <visp/vpExponentialMap.h>
65 #include <visp/vpMbtKltPolygon.h>
66 
227 class VISP_EXPORT vpMbKltTracker: virtual public vpMbTracker
228 {
229 protected:
231  IplImage* cur;
235  double angleAppears;
243  unsigned int maskBorder;
245  double lambda;
247  unsigned int maxIter;
251  double percentGood;
253  bool useOgre;
263  double distNearClip;
265  double distFarClip;
267  unsigned int clippingFlag;
268 
269 public:
270 
271  vpMbKltTracker();
272  virtual ~vpMbKltTracker();
273 
274  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo,
275  const vpCameraParameters &cam, const vpColor& col, const unsigned int thickness=1,
276  const bool displayFullModel = false);
277  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
278  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel = false);
279 
280 protected:
281  virtual void init(const vpImage<unsigned char>& I);
282  virtual void reinit(const vpImage<unsigned char>& I);
283 
284 public:
285  virtual void loadConfigFile(const std::string& configFile);
286  void loadConfigFile(const char* configFile);
287 
289  virtual inline double getAngleAppear() const { return angleAppears; }
290 
292  virtual inline double getAngleDisappear() const { return angleDisappears; }
293 
301  virtual inline unsigned int getClipping() const { return clippingFlag; }
302 
304  inline vpMbHiddenFaces<vpMbtKltPolygon>& getFaces() { return faces;}
305 
311  virtual inline double getFarClippingDistance() const { return distFarClip; }
312 
318  inline CvPoint2D32f* getKltPoints() {return tracker.getFeatures();}
319 
320  std::vector<vpImagePoint> getKltImagePoints() const;
321 
322  std::map<int, vpImagePoint> getKltImagePointsWithId() const;
323 
329  inline vpKltOpencv getKltOpencv() const { return tracker; }
330 
336  virtual inline double getLambda() const {return lambda;}
337 
343  inline unsigned int getMaskBorder() const { return maskBorder; }
344 
350  virtual inline unsigned int getMaxIter() const {return maxIter;}
351 
357  inline int getNbKltPoints() const {return tracker.getNbFeatures();}
358 
364  virtual inline double getNearClippingDistance() const { return distNearClip; }
365 
371  inline double getThresholdAcceptation() const { return threshold_outlier;}
372 
373  void resetTracker();
374 
384  virtual inline void setAngleAppear(const double &a) { angleAppears = a; }
385 
395  virtual inline void setAngleDisappear(const double &a) { angleDisappears = a; }
396 
397  void setCameraParameters(const vpCameraParameters& cam);
398 
399  virtual void setClipping(const unsigned int &flags);
400 
401  virtual void setFarClippingDistance(const double &dist);
402 
403  void setKltOpencv(const vpKltOpencv& t);
404 
410  virtual inline void setLambda(const double lambda) {this->lambda = lambda;}
411 
417  inline void setMaskBorder(const unsigned int &e){ maskBorder = e; }
418 
424  virtual inline void setMaxIter(const unsigned int max) {maxIter = max;}
425 
426  virtual void setNearClippingDistance(const double &dist);
427 
428  virtual void setOgreVisibilityTest(const bool &v);
429 
430  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
431 
437  inline void setThresholdAcceptation(const double th) {threshold_outlier = th;}
438 
439  virtual void testTracking();
440  virtual void track(const vpImage<unsigned char>& I);
441 
442 protected:
443  void computeVVS(const unsigned int &nbInfos, vpColVector &w);
444 
445  virtual void initFaceFromCorners(const std::vector<vpPoint>& corners, const unsigned int indexFace = -1);
446  virtual void initCylinder(const vpPoint& , const vpPoint , const double , const unsigned int ){};
447 
448  void preTracking(const vpImage<unsigned char>& I, unsigned int &nbInfos, unsigned int &nbFaceUsed);
449  bool postTracking(const vpImage<unsigned char>& I, vpColVector &w);
450 };
451 
452 #endif
453 #endif // VISP_HAVE_OPENCV