Visual Servoing Platform  version 3.1.0
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 modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact INRIA about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr/download/ for more information.
18  *
19  * This software was developed at:
20  * INRIA Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  * http://www.irisa.fr/lagadic
25  *
26  * If you have questions regarding the use of this file, please contact
27  * INRIA at visp@inria.fr
28  *
29  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
30  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31  *
32  *
33  * Description:
34  * Model-based klt tracker with multiple cameras.
35  *
36  * Authors:
37  * Souriya Trinh
38  *
39  *****************************************************************************/
40 
46 #ifndef __vpMbKltMultiTracker_h__
47 #define __vpMbKltMultiTracker_h__
48 
49 #include <iostream>
50 #include <vector>
51 
52 #include <visp3/core/vpConfig.h>
53 
54 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
55 
56 #include <visp3/mbt/vpMbKltTracker.h>
57 
73 class VISP_EXPORT vpMbKltMultiTracker : public vpMbKltTracker
74 {
75 protected:
78  std::map<std::string, vpHomogeneousMatrix> m_mapOfCameraTransformationMatrix;
79 
81  std::map<std::string, vpMbKltTracker *> m_mapOfKltTrackers;
82 
84  std::string m_referenceCameraName;
93 
94 public:
96  vpMbKltMultiTracker(const unsigned int nbCameras);
97  vpMbKltMultiTracker(const std::vector<std::string> &cameraNames);
98 
99  virtual ~vpMbKltMultiTracker();
100 
103  virtual void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r,
104  const std::string &name = "");
105 
106  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
107  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
108 
109  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
110  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
111 
112  virtual void display(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
113  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
114  const vpCameraParameters &cam2, const vpColor &color, const unsigned int thickness = 1,
115  const bool displayFullModel = false);
116 
117  virtual void display(const vpImage<vpRGBa> &I1, const vpImage<vpRGBa> &I2, const vpHomogeneousMatrix &c1Mo,
118  const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, const vpCameraParameters &cam2,
119  const vpColor &color, const unsigned int thickness = 1, const bool displayFullModel = false);
120 
121  virtual void display(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
122  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
123  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters, const vpColor &col,
124  const unsigned int thickness = 1, const bool displayFullModel = false);
125 
126  virtual void display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
127  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
128  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters, const vpColor &col,
129  const unsigned int thickness = 1, const bool displayFullModel = false);
130 
131  virtual std::vector<std::string> getCameraNames() const;
132 
133  virtual void getCameraParameters(vpCameraParameters &camera) const;
134  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
135  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
136  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
137 
139  virtual unsigned int getClipping(const std::string &cameraName) const;
140 
142  virtual vpMbHiddenFaces<vpMbtPolygon> &getFaces(const std::string &cameraName);
143  virtual std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getFaces() const;
144 
145  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle();
146  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle(const std::string &cameraName);
147 
148  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt();
149  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt(const std::string &cameraName);
150 
151  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder();
152  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder(const std::string &cameraName);
153 
154  virtual std::map<std::string, std::vector<vpImagePoint> > getKltImagePoints() const;
155 
156  virtual std::map<std::string, std::map<int, vpImagePoint> > getKltImagePointsWithId() const;
157 
158  virtual std::map<std::string, vpKltOpencv> getKltOpencv() const;
159 
160 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
161  virtual std::map<std::string, std::vector<cv::Point2f> > getKltPoints() const;
162 #else
163  virtual std::map<std::string, CvPoint2D32f *> getKltPoints();
164 #endif
165 
166  virtual std::map<std::string, int> getKltNbPoints() const;
167 
168  virtual unsigned int getNbPolygon() const;
169  virtual std::map<std::string, unsigned int> getMultiNbPolygon() const;
170 
176  inline unsigned int getNumberOfCameras() const { return (unsigned int)m_mapOfKltTrackers.size(); }
177 
178  using vpMbTracker::getPose;
179  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
180  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const;
181  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
182 
183  virtual inline vpColVector getError() const { return m_error_kltMulti; }
184 
185  virtual inline vpColVector getRobustWeights() const { return m_w_kltMulti; }
186 
187  virtual void init(const vpImage<unsigned char> &I);
188 
189 #ifdef VISP_HAVE_MODULE_GUI
190  virtual void initClick(const vpImage<unsigned char> &I, const std::vector<vpPoint> &points3D_list,
191  const std::string &displayFile = "");
192 
193  virtual void initClick(const vpImage<unsigned char> &I, const std::string &initFile, const bool displayHelp = false);
194 
195  virtual void initClick(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
196  const std::string &initFile1, const std::string &initFile2, const bool displayHelp = false,
197  const bool firstCameraIsReference = true);
198 
199  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
200  const std::string &initFile, const bool displayHelp = false);
201 
202  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
203  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp = false);
204 #endif
205 
206  virtual void initFromPose(const vpImage<unsigned char> &I, const std::string &initFile);
207  virtual void initFromPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
208  virtual void initFromPose(const vpImage<unsigned char> &I, const vpPoseVector &cPo);
209 
210  virtual void initFromPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
211  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
212  const bool firstCameraIsReference = true);
213  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
214  const vpHomogeneousMatrix &cMo_);
215  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
216  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
217 
218  virtual void loadConfigFile(const std::string &configFile);
219 
220  virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2,
221  const bool firstCameraIsReference = true);
222 
223  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
224 
225  virtual void loadModel(const std::string &modelFile, const bool verbose = false);
226 
227  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
228  const vpHomogeneousMatrix &cMo_, const bool verbose = false);
229  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
230  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo,
231  const vpHomogeneousMatrix &c2Mo, const bool verbose = false,
232  const bool firstCameraIsReference = true);
233  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
234  const std::string &cad_name,
235  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
236  const bool verbose = false);
237 
238  virtual void resetTracker();
239 
240  virtual void setAngleAppear(const double &a);
241  virtual void setAngleDisappear(const double &a);
242 
243  virtual void setCameraParameters(const vpCameraParameters &camera);
244 
245  virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2,
246  const bool firstCameraIsReference = true);
247 
248  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters &camera);
249 
250  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
251 
252  virtual void setCameraTransformationMatrix(const std::string &cameraName,
253  const vpHomogeneousMatrix &cameraTransformationMatrix);
254 
255  virtual void
256  setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
257 
258  virtual void setClipping(const unsigned int &flags);
259  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
260 
261  virtual void setCovarianceComputation(const bool &flag);
262 
263  virtual void setDisplayFeatures(const bool displayF);
264 
265  virtual void setFarClippingDistance(const double &dist);
266  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
267 
268 #ifdef VISP_HAVE_OGRE
269  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
270 
271  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
272 #endif
273 
274  virtual void setKltMaskBorder(const unsigned int &e);
275 
276  virtual void setKltOpencv(const vpKltOpencv &t);
277  virtual void setKltOpencv(const std::map<std::string, vpKltOpencv> &mapOfOpenCVTrackers);
278 
279  virtual void setKltThresholdAcceptation(const double th);
280 
281  virtual void setLod(const bool useLod, const std::string &name = "");
282  virtual void setLod(const bool useLod, const std::string &cameraName, const std::string &name);
283 
284  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name = "");
285 
286  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name = "");
287  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
288  const std::string &name);
289 
290  virtual void setNearClippingDistance(const double &dist);
291  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
292 
293  virtual void setOgreShowConfigDialog(const bool showConfigDialog);
294 
295  virtual void setOgreVisibilityTest(const bool &v);
296 
297  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
298 
299  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
300 
301  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
302  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
303  const bool firstCameraIsReference = true);
304 
305  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
306  const vpHomogeneousMatrix &cMo_);
307 
308  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
309  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
310 
311  virtual void setReferenceCameraName(const std::string &referenceCameraName);
312 
313  virtual void setScanLineVisibilityTest(const bool &v);
314 
315  virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking);
316 
317  virtual void track(const vpImage<unsigned char> &I);
318  virtual void track(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2);
319  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
321 
326  /* vp_deprecated */ virtual std::map<std::string, int> getNbKltPoints() const;
327  /* vp_deprecated */ virtual void setMaskBorder(const unsigned int &e);
328  /* vp_deprecated */ virtual void setThresholdAcceptation(const double th);
330 
331 protected:
334  virtual void computeVVS();
335  virtual void computeVVSInit();
337  virtual void computeVVSInteractionMatrixAndResidu(std::map<std::string, vpVelocityTwistMatrix> &mapOfVelocityTwist);
338  virtual void computeVVSWeights();
340 
341  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
342 
343  virtual void preTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
344 
346  virtual void reinit(/* const vpImage<unsigned char>& I */);
348 };
349 
350 #endif // VISP_HAVE_OPENCV
351 #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 unsigned int getClipping() const
Definition: vpMbTracker.h:223
virtual void track(const vpImage< unsigned char > &I)
virtual void setDisplayFeatures(const bool displayF)
Definition: vpMbTracker.h:470
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:452
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
Definition: vpMbTracker.h:575
void setThresholdAcceptation(const double th)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
vpMatrix m_L_kltMulti
Interaction matrix.
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 void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:433
std::vector< vpImagePoint > getKltImagePoints() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
int getKltNbPoints() const
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
Definition: vpMbTracker.h:510
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
vpKltOpencv getKltOpencv() const
std::vector< cv::Point2f > getKltPoints() const
void setKltMaskBorder(const unsigned int &e)
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void reinit(const vpImage< unsigned char > &I)
virtual void computeVVSInteractionMatrixAndResidu()
unsigned int getNumberOfCameras() const
Class that defines what is a point.
Definition: vpPoint.h:58
virtual void loadConfigFile(const std::string &configFile)
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:390
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
virtual void setGoodNbRayCastingAttemptsRatio(const double &ratio)
Definition: vpMbTracker.h:549
void setKltThresholdAcceptation(const double th)
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
vpColVector m_weightedError_kltMulti
Weighted error.
Generic class defining intrinsic camera parameters.
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:422
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 void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
Definition: vpMbTracker.h:559
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
vpColVector m_w_kltMulti
Robust weights.
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
void setMaskBorder(const unsigned int &e)
virtual void loadModel(const char *modelFile, const bool verbose=false)
virtual vpColVector getRobustWeights() const
void setCameraParameters(const vpCameraParameters &cam)
virtual void getCameraParameters(vpCameraParameters &camera) const
Definition: vpMbTracker.h:215
void preTracking(const vpImage< unsigned char > &I)
virtual unsigned int getNbPolygon() const
Definition: vpMbTracker.h:335
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
std::map< std::string, vpMbKltTracker * > m_mapOfKltTrackers
Map of Model-based klt trackers.
virtual void setOgreVisibilityTest(const bool &v)
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:92
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Definition: vpKltOpencv.h:78
std::map< int, vpImagePoint > getKltImagePointsWithId() const
int getNbKltPoints() const
virtual void computeVVSInit()
virtual void setClipping(const unsigned int &flags)
virtual void init(const vpImage< unsigned char > &I)
vpColVector m_error_kltMulti
(s - s*)
virtual void setFarClippingDistance(const double &dist)
virtual vpColVector getError() const
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
Definition: vpMbTracker.h:299
Model based stereo (or more) tracker using only KLT.
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)