Visual Servoing Platform  version 3.0.0
vpMbKltTracker.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Model based tracker using only KLT
32  *
33  * Authors:
34  * Romain Tallonneau
35  * Aurelien Yol
36  *
37  *****************************************************************************/
43 #ifndef vpMbKltTracker_h
44 #define vpMbKltTracker_h
45 
46 #include <visp3/core/vpConfig.h>
47 
48 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
49 
50 #include <visp3/mbt/vpMbTracker.h>
51 #include <visp3/klt/vpKltOpencv.h>
52 #include <visp3/core/vpMeterPixelConversion.h>
53 #include <visp3/core/vpPixelMeterConversion.h>
54 #include <visp3/mbt/vpMbtKltXmlParser.h>
55 #include <visp3/vision/vpHomography.h>
56 #include <visp3/core/vpRobust.h>
57 #include <visp3/core/vpSubColVector.h>
58 #include <visp3/core/vpSubMatrix.h>
59 #include <visp3/core/vpExponentialMap.h>
60 #include <visp3/mbt/vpMbtDistanceKltPoints.h>
61 #include <visp3/mbt/vpMbtDistanceCircle.h>
62 #include <visp3/mbt/vpMbtDistanceKltCylinder.h>
63 
224 class VISP_EXPORT vpMbKltTracker: virtual public vpMbTracker
225 {
226 protected:
228 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
229  cv::Mat cur;
230 #else
231  IplImage *cur;
232 #endif
233  vpHomogeneousMatrix c0Mo;
240  unsigned int maskBorder;
242  double lambda;
244  unsigned int maxIter;
248  double percentGood;
254  std::list<vpMbtDistanceKltPoints*> kltPolygons;
256  std::list<vpMbtDistanceKltCylinder*> kltCylinders;
258  std::list<vpMbtDistanceCircle*> circles_disp;
259 
260 public:
261  vpMbKltTracker();
262  virtual ~vpMbKltTracker();
263 
264  void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="");
265  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo,
266  const vpCameraParameters &cam, const vpColor& col, const unsigned int thickness=1,
267  const bool displayFullModel = false);
268  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
269  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel = false);
270 
271 protected:
272  virtual void init(const vpImage<unsigned char>& I);
273  virtual void reinit(const vpImage<unsigned char>& I);
274 
275 public:
277  std::list<vpMbtDistanceCircle*> &getFeaturesCircle() { return circles_disp; }
279  std::list<vpMbtDistanceKltCylinder*> &getFeaturesKltCylinder() { return kltCylinders; }
281  std::list<vpMbtDistanceKltPoints*> &getFeaturesKlt() { return kltPolygons; }
282  virtual void loadConfigFile(const std::string& configFile);
283  void loadConfigFile(const char* configFile);
284 
290 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
291  inline std::vector<cv::Point2f> getKltPoints() {return tracker.getFeatures();}
292 #else
293  inline CvPoint2D32f* getKltPoints() {return tracker.getFeatures();}
294 #endif
295 
296  std::vector<vpImagePoint> getKltImagePoints() const;
297 
298  std::map<int, vpImagePoint> getKltImagePointsWithId() const;
299 
305  inline vpKltOpencv getKltOpencv() const { return tracker; }
306 
312  virtual inline double getLambda() const {return lambda;}
313 
319  inline unsigned int getMaskBorder() const { return maskBorder; }
320 
326  virtual inline unsigned int getMaxIter() const {return maxIter;}
327 
333  inline int getNbKltPoints() const {return tracker.getNbFeatures();}
334 
340  inline double getThresholdAcceptation() const { return threshold_outlier;}
341 
342  void reInitModel(const vpImage<unsigned char>& I, const std::string &cad_name, const vpHomogeneousMatrix& cMo_,
343  const bool verbose=false);
344  void reInitModel(const vpImage<unsigned char>& I, const char* cad_name, const vpHomogeneousMatrix& cMo,
345  const bool verbose=false);
346  void resetTracker();
347 
348  void setCameraParameters(const vpCameraParameters& cam);
349 
350  void setKltOpencv(const vpKltOpencv& t);
351 
357  virtual inline void setLambda(const double gain) {this->lambda = gain;}
358 
364  inline void setMaskBorder(const unsigned int &e)
365  {
366  maskBorder = e;
367  //if(useScanLine)
368  faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
369  }
370 
376  virtual inline void setMaxIter(const unsigned int max) {maxIter = max;}
377 
385  virtual void setOgreVisibilityTest(const bool &v){
387 #ifdef VISP_HAVE_OGRE
388  faces.getOgreContext()->setWindowName("MBT Klt");
389 #endif
390  }
391 
397  virtual void setScanLineVisibilityTest(const bool &v){
399 
400  for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it)
401  (*it)->useScanLine = v;
402  }
403 
404  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
405 
411  virtual void setProjectionErrorComputation(const bool &flag) {
412  if(flag)
413  vpCTRACE << "This option is not yet implemented in vpMbKltTracker, projection error computation set to false." << std::endl ; }
414 
420  inline void setThresholdAcceptation(const double th) {threshold_outlier = th;}
421 
422  void setUseKltTracking(const std::string &name, const bool &useKltTracking);
423 
424  virtual void testTracking();
425  virtual void track(const vpImage<unsigned char>& I);
426 
427 protected:
428  void computeVVS(const unsigned int &nbInfos, vpColVector &w);
429 
430  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
431  virtual void initFaceFromLines(vpMbtPolygon &polygon);
432  virtual void initCircle(const vpPoint&, const vpPoint &, const vpPoint &, const double, const int,
433  const std::string &name="");
434  virtual void initCylinder(const vpPoint&, const vpPoint &, const double, const int,
435  const std::string &name="");
436 
437  void preTracking(const vpImage<unsigned char>& I, unsigned int &nbInfos, unsigned int &nbFaceUsed);
438  bool postTracking(const vpImage<unsigned char>& I, vpColVector &w);
439 };
440 
441 #endif
442 #endif // VISP_HAVE_OPENCV
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
std::list< vpMbtDistanceKltPoints * > kltPolygons
void setThresholdAcceptation(const double th)
virtual void setScanLineVisibilityTest(const bool &v)
virtual void track(const vpImage< unsigned char > &I)=0
virtual void setLambda(const double gain)
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
Definition: vpKltOpencv.h:103
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void setProjectionErrorComputation(const bool &flag)
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
double percentGood
Percentage of good points, according to the initial number, that must have the tracker.
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")=0
virtual double getLambda() const
std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
bool firstInitialisation
Flag to specify whether the init method is called the first or not (specific calls to realize in this...
virtual void resetTracker()=0
std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
Class that defines what is a point.
Definition: vpPoint.h:59
std::vector< cv::Point2f > getKltPoints()
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
virtual void init(const vpImage< unsigned char > &I)=0
unsigned int getMaskBorder() const
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)=0
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:64
virtual void setCameraParameters(const vpCameraParameters &camera)
Definition: vpMbTracker.h:437
unsigned int maskBorder
Erosion of the mask.
virtual void initFaceFromCorners(vpMbtPolygon &polygon)=0
Generic class defining intrinsic camera parameters.
std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
Main methods for a model-based tracker.
Definition: vpMbTracker.h:103
Model based tracker using only KLT.
virtual void loadConfigFile(const std::string &configFile)=0
vpKltOpencv tracker
Points tracker.
std::list< vpMbtDistanceKltCylinder * > kltCylinders
double threshold_outlier
Threshold below which the weight associated to a point to consider this one as an outlier...
virtual void setMaxIter(const unsigned int max)
cv::Mat cur
Temporary OpenCV image for fast conversion.
double lambda
The gain of the virtual visual servoing stage.
int getNbKltPoints() const
vpKltOpencv getKltOpencv() const
std::list< vpMbtDistanceCircle * > circles_disp
Vector of the circles used here only to display the full model.
virtual void setOgreVisibilityTest(const bool &v)
void setMaskBorder(const unsigned int &e)
#define vpCTRACE
Definition: vpDebug.h:337
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
virtual void initFaceFromLines(vpMbtPolygon &polygon)=0
virtual void setOgreVisibilityTest(const bool &v)
virtual void testTracking()=0
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
Definition: vpKltOpencv.h:75
int getNbFeatures() const
Get the number of current features.
Definition: vpKltOpencv.h:117
double getThresholdAcceptation() const
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual void setScanLineVisibilityTest(const bool &v)
Definition: vpMbTracker.h:511
virtual unsigned int getMaxIter() const
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")=0