Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMbKltMultiTracker.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2016 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://www.irisa.fr/lagadic/visp/visp.html 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  * http://www.irisa.fr/lagadic
24  *
25  * If you have questions regarding the use of this file, please contact
26  * INRIA at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  *
32  * Description:
33  * Model-based klt tracker with multiple cameras.
34  *
35  * Authors:
36  * Souriya Trinh
37  *
38  *****************************************************************************/
39 
45 #ifndef __vpMbKltMultiTracker_h__
46 #define __vpMbKltMultiTracker_h__
47 
48 #include <iostream>
49 #include <vector>
50 
51 #include <visp3/core/vpConfig.h>
52 
53 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
54 
55 #include <visp3/mbt/vpMbKltTracker.h>
56 
57 
72 class VISP_EXPORT vpMbKltMultiTracker: public vpMbKltTracker
73 {
74 protected:
76  std::map<std::string, vpHomogeneousMatrix> m_mapOfCameraTransformationMatrix;
77 
79  std::map<std::string, vpMbKltTracker*> m_mapOfKltTrackers;
80 
82  std::string m_referenceCameraName;
83 
84 public:
86  vpMbKltMultiTracker(const unsigned int nbCameras);
87  vpMbKltMultiTracker(const std::vector<std::string> &cameraNames);
88 
89  virtual ~vpMbKltMultiTracker();
90 
93  virtual void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="");
94 
95  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
96  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel=false);
97 
98  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
99  const vpColor& col , const unsigned int thickness=1, const bool displayFullModel=false);
100 
101  virtual void display(const vpImage<unsigned char>& I1, const vpImage<unsigned char>& I2, const vpHomogeneousMatrix &c1Mo,
102  const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, const vpCameraParameters &cam2,
103  const vpColor& color, const unsigned int thickness=1, const bool displayFullModel = false);
104 
105  virtual void display(const vpImage<vpRGBa>& I1, const vpImage<vpRGBa>& I2, const vpHomogeneousMatrix &c1Mo,
106  const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, const vpCameraParameters &cam2,
107  const vpColor& color, const unsigned int thickness=1, const bool displayFullModel = false);
108 
109  virtual void display(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
110  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
111  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
112  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel=false);
113 
114  virtual void display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
115  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
116  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters,
117  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel=false);
118 
119  virtual std::vector<std::string> getCameraNames() const;
120 
121  virtual void getCameraParameters(vpCameraParameters &camera) const;
122  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
123  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
124  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
125 
127  virtual unsigned int getClipping(const std::string &cameraName) const;
128 
130  virtual vpMbHiddenFaces<vpMbtPolygon>& getFaces(const std::string &cameraName);
131  virtual std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getFaces() const;
132 
133  virtual std::list<vpMbtDistanceCircle*>& getFeaturesCircle();
134  virtual std::list<vpMbtDistanceCircle*>& getFeaturesCircle(const std::string &cameraName);
135 
136  virtual std::list<vpMbtDistanceKltPoints*>& getFeaturesKlt();
137  virtual std::list<vpMbtDistanceKltPoints*>& getFeaturesKlt(const std::string &cameraName);
138 
139  virtual std::list<vpMbtDistanceKltCylinder*>& getFeaturesKltCylinder();
140  virtual std::list<vpMbtDistanceKltCylinder*>& getFeaturesKltCylinder(const std::string &cameraName);
141 
142  virtual std::map<std::string, std::vector<vpImagePoint> > getKltImagePoints() const;
143 
144  virtual std::map<std::string, std::map<int, vpImagePoint> > getKltImagePointsWithId() const;
145 
146  virtual std::map<std::string, vpKltOpencv> getKltOpencv() const;
147 
148 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
149  virtual std::map<std::string, std::vector<cv::Point2f> > getKltPoints() const;
150 #else
151  virtual std::map<std::string, CvPoint2D32f*> getKltPoints();
152 #endif
153 
154  virtual std::map<std::string, int> getNbKltPoints() const;
155 
156  virtual unsigned int getNbPolygon() const;
157  virtual std::map<std::string, unsigned int> getMultiNbPolygon() const;
158 
164  inline unsigned int getNumberOfCameras() const {
165  return (unsigned int) m_mapOfKltTrackers.size();
166  }
167 
168  using vpMbTracker::getPose;
169  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
170  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const;
171  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
172 
173  virtual void init(const vpImage<unsigned char>& I);
174 
175 #ifdef VISP_HAVE_MODULE_GUI
176  virtual void initClick(const vpImage<unsigned char>& I, const std::vector<vpPoint> &points3D_list,
177  const std::string &displayFile="");
178 
179  virtual void initClick(const vpImage<unsigned char>& I, const std::string& initFile, const bool displayHelp=false);
180 
181  virtual void initClick(const vpImage<unsigned char>& I1, const vpImage<unsigned char> &I2,
182  const std::string& initFile1, const std::string& initFile2, const bool displayHelp=false,
183  const bool firstCameraIsReference=true);
184 
185  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
186  const std::string &initFile, const bool displayHelp=false);
187 
188  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
189  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp=false);
190 #endif
191 
192  virtual void initFromPose(const vpImage<unsigned char>& I, const std::string &initFile);
193  virtual void initFromPose(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo);
194  virtual void initFromPose(const vpImage<unsigned char>& I, const vpPoseVector &cPo);
195 
196  virtual void initFromPose(const vpImage<unsigned char>& I1, const vpImage<unsigned char>& I2,
197  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const bool firstCameraIsReference=true);
198  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
199  const vpHomogeneousMatrix &cMo_);
200  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
201  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
202 
203  virtual void loadConfigFile(const std::string &configFile);
204 
205  virtual void loadConfigFile(const std::string& configFile1, const std::string& configFile2,
206  const bool firstCameraIsReference=true);
207 
208  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
209 
210  virtual void loadModel(const std::string &modelFile, const bool verbose=false);
211 
212  virtual void reInitModel(const vpImage<unsigned char>& I, const std::string &cad_name, const vpHomogeneousMatrix& cMo_,
213  const bool verbose=false);
214  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
215  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
216  const bool verbose=false, const bool firstCameraIsReference=true);
217  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
218  const std::string &cad_name, const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
219  const bool verbose=false);
220 
221  virtual void resetTracker();
222 
223  virtual void setAngleAppear(const double &a);
224  virtual void setAngleDisappear(const double &a);
225 
226  virtual void setCameraParameters(const vpCameraParameters& camera);
227 
228  virtual void setCameraParameters(const vpCameraParameters& camera1, const vpCameraParameters& camera2,
229  const bool firstCameraIsReference=true);
230 
231  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters& camera);
232 
233  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
234 
235  virtual void setCameraTransformationMatrix(const std::string &cameraName,
236  const vpHomogeneousMatrix &cameraTransformationMatrix);
237 
238  virtual void setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
239 
240  virtual void setClipping(const unsigned int &flags);
241  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
242 
243  virtual void setCovarianceComputation(const bool& flag);
244 
245  virtual void setDisplayFeatures(const bool displayF);
246 
247  virtual void setFarClippingDistance(const double &dist);
248  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
249 
250 #ifdef VISP_HAVE_OGRE
251  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
252 
253  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
254 #endif
255 
256  virtual void setKltOpencv(const vpKltOpencv& t);
257  virtual void setKltOpencv(const std::map<std::string, vpKltOpencv> &mapOfOpenCVTrackers);
258 
259  virtual void setLod(const bool useLod, const std::string &name="");
260  virtual void setLod(const bool useLod, const std::string &cameraName, const std::string &name);
261 
262  virtual void setMaskBorder(const unsigned int &e);
263 
264  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="");
265 
266  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="");
267  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
268  const std::string &name);
269 
270  virtual void setNearClippingDistance(const double &dist);
271  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
272 
273  virtual void setOgreShowConfigDialog(const bool showConfigDialog);
274 
275  virtual void setOgreVisibilityTest(const bool &v);
276 
277  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
278 
279  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
280 
281  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2, const vpHomogeneousMatrix &c1Mo,
282  const vpHomogeneousMatrix c2Mo, const bool firstCameraIsReference=true);
283 
284  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
285  const vpHomogeneousMatrix &cMo_);
286 
287  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
288  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
289 
290  virtual void setReferenceCameraName(const std::string &referenceCameraName);
291 
292  virtual void setScanLineVisibilityTest(const bool &v);
293 
294  virtual void setThresholdAcceptation(const double th);
295 
296  virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking);
297 
298  virtual void track(const vpImage<unsigned char> &I);
299  virtual void track(const vpImage<unsigned char>& I1, const vpImage<unsigned char>& I2);
300  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
302 
303 protected:
306  virtual void computeVVS(std::map<std::string, unsigned int> &mapOfNbInfos, vpColVector &w);
307  virtual void computeVVSWeights(const unsigned int iter, const unsigned int nbInfos,
308  std::map<std::string, unsigned int> &mapOfNbInfos, vpColVector &R, vpColVector &w_true, vpColVector &w,
309  std::map<std::string, vpRobust> &mapOfRobusts, double threshold);
310 
311  virtual void preTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
312  std::map<std::string, unsigned int> &mapOfNbInfos,
313  std::map<std::string, unsigned int> &mapOfNbFaceUsed);
314 
315  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
316  std::map<std::string, unsigned int> &mapOfNbInfos, vpColVector &w_klt);
318  virtual void reinit(/* const vpImage<unsigned char>& I */);
320 };
321 
322 #endif // VISP_HAVE_OPENCV
323 #endif //__vpMbKltMultiTracker_h__
virtual void setKltOpencv(const vpKltOpencv &t)
void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="")
virtual void track(const vpImage< unsigned char > &I)
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
virtual void setDisplayFeatures(const bool displayF)
Definition: vpMbTracker.h:411
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
Definition: vpMbTracker.h:453
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:398
void setThresholdAcceptation(const double th)
virtual void setScanLineVisibilityTest(const bool &v)
friend class vpMbKltMultiTracker
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
void setUseKltTracking(const std::string &name, const bool &useKltTracking)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:208
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:382
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
Definition: vpMbTracker.h:430
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
void computeVVSWeights(const unsigned int iter, const unsigned int nbInfos, const vpColVector &R, vpColVector &w_true, vpColVector &w, vpRobust &robust)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void reinit(const vpImage< unsigned char > &I)
Class that defines what is a point.
Definition: vpPoint.h:59
virtual void loadConfigFile(const std::string &configFile)
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
Map of camera transformation matrix between the current camera frame to the reference camera frame (c...
void setOgreShowConfigDialog(const bool showConfigDialog)
Definition: vpMbTracker.h:479
std::vector< cv::Point2f > getKltPoints() const
std::vector< vpImagePoint > getKltImagePoints() const
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:342
virtual void getCameraParameters(vpCameraParameters &camera) const
Definition: vpMbTracker.h:201
Generic class defining intrinsic camera parameters.
std::map< int, vpImagePoint > getKltImagePointsWithId() const
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:371
Model based tracker using only KLT.
std::string m_referenceCameraName
Name of the reference camera.
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
Definition: vpMbTracker.h:464
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
std::map< std::string, vpMbKltTracker * > m_mapOfKltTrackers
Map of Model-based klt trackers.
void preTracking(const vpImage< unsigned char > &I, unsigned int &nbInfos, unsigned int &nbFaceUsed)
int getNbKltPoints() const
vpKltOpencv getKltOpencv() const
void setMaskBorder(const unsigned int &e)
virtual void loadModel(const char *modelFile, const bool verbose=false)
void setCameraParameters(const vpCameraParameters &cam)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
virtual void setOgreVisibilityTest(const bool &v)
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Definition: vpKltOpencv.h:76
virtual unsigned int getNbPolygon() const
Definition: vpMbTracker.h:286
virtual void setClipping(const unsigned int &flags)
virtual void init(const vpImage< unsigned char > &I)
virtual void setFarClippingDistance(const double &dist)
void computeVVS(const unsigned int &nbInfos, vpColVector &w)
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
Definition: vpMbTracker.h:248
Model based stereo (or more) tracker using only KLT.
unsigned int getNumberOfCameras() 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)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void setLod(const bool useLod, const std::string &name="")
virtual void setNearClippingDistance(const double &dist)