Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpMbKltMultiTracker.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://visp.inria.fr 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  *
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  * Description:
32  * Model-based klt tracker with multiple cameras.
33  *
34  * Authors:
35  * Souriya Trinh
36  *
37  *****************************************************************************/
38 
44 #ifndef _vpMbKltMultiTracker_h_
45 #define _vpMbKltMultiTracker_h_
46 
47 #include <iostream>
48 #include <vector>
49 
50 #include <visp3/core/vpConfig.h>
51 
52 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
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 
75 class VISP_EXPORT vp_deprecated vpMbKltMultiTracker : public vpMbKltTracker
76 {
77 protected:
80  std::map<std::string, vpHomogeneousMatrix> m_mapOfCameraTransformationMatrix;
81 
83  std::map<std::string, vpMbKltTracker *> m_mapOfKltTrackers;
84 
86  std::string m_referenceCameraName;
95 
96 public:
98  vpMbKltMultiTracker(unsigned int nbCameras);
99  vpMbKltMultiTracker(const std::vector<std::string> &cameraNames);
100 
101  virtual ~vpMbKltMultiTracker();
102 
105  virtual void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, double r,
106  const std::string &name = "");
107 
108  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
109  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false);
110 
111  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
112  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false);
113 
114  virtual void display(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
115  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
116  const vpCameraParameters &cam2, const vpColor &color, unsigned int thickness = 1,
117  bool displayFullModel = false);
118 
119  virtual void display(const vpImage<vpRGBa> &I1, const vpImage<vpRGBa> &I2, const vpHomogeneousMatrix &c1Mo,
120  const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, const vpCameraParameters &cam2,
121  const vpColor &color, unsigned int thickness = 1, bool displayFullModel = false);
122 
123  virtual void display(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
124  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
125  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters, const vpColor &col,
126  unsigned int thickness = 1, bool displayFullModel = false);
127 
128  virtual void display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
129  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
130  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters, const vpColor &col,
131  unsigned int thickness = 1, bool displayFullModel = false);
132 
133  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int, unsigned int,
134  const vpHomogeneousMatrix &,
135  const vpCameraParameters &,
136  bool =false)
137  {
138  std::cerr << "Not implemented. Deprecated class." << std::endl;
139  return std::vector<std::vector<double> >();
140  }
141 
142  virtual std::vector<std::string> getCameraNames() const;
143 
144  virtual void getCameraParameters(vpCameraParameters &camera) const;
145  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
146  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
147  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
148 
150  virtual unsigned int getClipping(const std::string &cameraName) const;
151 
153  virtual vpMbHiddenFaces<vpMbtPolygon> &getFaces(const std::string &cameraName);
154  virtual std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getFaces() const;
155 
156  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle();
157  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle(const std::string &cameraName);
158 
159  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt();
160  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt(const std::string &cameraName);
161 
162  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder();
163  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder(const std::string &cameraName);
164 
165  virtual std::map<std::string, std::vector<vpImagePoint> > getKltImagePoints() const;
166 
167  virtual std::map<std::string, std::map<int, vpImagePoint> > getKltImagePointsWithId() const;
168 
169  virtual std::map<std::string, vpKltOpencv> getKltOpencv() const;
170 
171 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
172  virtual std::map<std::string, std::vector<cv::Point2f> > getKltPoints() const;
173 #else
174  virtual std::map<std::string, CvPoint2D32f *> getKltPoints();
175 #endif
176 
177  virtual std::map<std::string, int> getKltNbPoints() const;
178 
179  virtual unsigned int getNbPolygon() const;
180  virtual std::map<std::string, unsigned int> getMultiNbPolygon() const;
181 
187  inline unsigned int getNumberOfCameras() const { return (unsigned int)m_mapOfKltTrackers.size(); }
188 
189  using vpMbTracker::getPose;
190  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
191  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo) const;
192  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
193 
194  virtual inline vpColVector getError() const { return m_error_kltMulti; }
195 
196  virtual inline vpColVector getRobustWeights() const { return m_w_kltMulti; }
197 
198  virtual void init(const vpImage<unsigned char> &I);
199 
200 #ifdef VISP_HAVE_MODULE_GUI
202  virtual void initClick(const vpImage<unsigned char> &I, const std::vector<vpPoint> &points3D_list,
203  const std::string &displayFile = "");
204 
205  virtual void initClick(const vpImage<unsigned char> &I, const std::string &initFile, bool displayHelp = false,
207 
208  virtual void initClick(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
209  const std::string &initFile1, const std::string &initFile2, bool displayHelp = false,
210  bool firstCameraIsReference = true);
211 
212  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
213  const std::string &initFile, bool displayHelp = false);
214 
215  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
216  const std::map<std::string, std::string> &mapOfInitFiles, bool displayHelp = false);
217 #endif
218 
220  virtual void initFromPose(const vpImage<unsigned char> &I, const std::string &initFile);
221  virtual void initFromPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
222  virtual void initFromPose(const vpImage<unsigned char> &I, const vpPoseVector &cPo);
223 
224  virtual void initFromPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
225  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
226  bool firstCameraIsReference = true);
227  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
228  const vpHomogeneousMatrix &cMo);
229  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
230  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
231 
232  virtual void loadConfigFile(const std::string &configFile);
233 
234  virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2,
235  bool firstCameraIsReference = true);
236 
237  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
238 
239  virtual void loadModel(const std::string &modelFile, bool verbose = false,
241 
242  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
243  const vpHomogeneousMatrix &cMo, bool verbose = false,
245  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
246  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo,
247  const vpHomogeneousMatrix &c2Mo, bool verbose = false,
248  bool firstCameraIsReference = true);
249  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
250  const std::string &cad_name,
251  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
252  bool verbose = false);
253 
254  virtual void resetTracker();
255 
256  virtual void setAngleAppear(const double &a);
257  virtual void setAngleDisappear(const double &a);
258 
259  virtual void setCameraParameters(const vpCameraParameters &camera);
260 
261  virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2,
262  bool firstCameraIsReference = true);
263 
264  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters &camera);
265 
266  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
267 
268  virtual void setCameraTransformationMatrix(const std::string &cameraName,
269  const vpHomogeneousMatrix &cameraTransformationMatrix);
270 
271  virtual void
272  setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
273 
274  virtual void setClipping(const unsigned int &flags);
275  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
276 
277  virtual void setCovarianceComputation(const bool &flag);
278 
279  virtual void setDisplayFeatures(bool displayF);
280 
281  virtual void setFarClippingDistance(const double &dist);
282  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
283 
284 #ifdef VISP_HAVE_OGRE
285  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
286 
287  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
288 #endif
289 
290  virtual void setKltMaskBorder(const unsigned int &e);
291 
292  virtual void setKltOpencv(const vpKltOpencv &t);
293  virtual void setKltOpencv(const std::map<std::string, vpKltOpencv> &mapOfOpenCVTrackers);
294 
295  virtual void setKltThresholdAcceptation(double th);
296 
297  virtual void setLod(bool useLod, const std::string &name = "");
298  virtual void setLod(bool useLod, const std::string &cameraName, const std::string &name);
299 
300  virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &name = "");
301 
302  virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &name = "");
303  virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &cameraName,
304  const std::string &name);
305 
306  virtual void setNearClippingDistance(const double &dist);
307  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
308 
309  virtual void setOgreShowConfigDialog(bool showConfigDialog);
310 
311  virtual void setOgreVisibilityTest(const bool &v);
312 
313  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
314 
316  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
317  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cMo);
318 
319  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
320  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
321  bool firstCameraIsReference = true);
322 
323  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
324  const vpHomogeneousMatrix &cMo);
325 
326  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
327  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
328 
329  virtual void setReferenceCameraName(const std::string &referenceCameraName);
330 
331  virtual void setScanLineVisibilityTest(const bool &v);
332 
333  virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking);
334 
335  virtual void track(const vpImage<unsigned char> &I);
336  virtual void track(const vpImage<vpRGBa> &I_color);
337  virtual void track(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2);
338  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
340 
345  /* vp_deprecated */ virtual std::map<std::string, int> getNbKltPoints() const;
346  /* vp_deprecated */ virtual void setMaskBorder(const unsigned int &e);
347  /* vp_deprecated */ virtual void setThresholdAcceptation(double th);
349 
350 protected:
353  virtual void computeVVS();
354  virtual void computeVVSInit();
356  virtual void computeVVSInteractionMatrixAndResidu(std::map<std::string, vpVelocityTwistMatrix> &mapOfVelocityTwist);
357  virtual void computeVVSWeights();
359 
360  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
361 
362  virtual void preTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
363 
365  virtual void reinit(/* const vpImage<unsigned char>& I */);
367 };
368 
369 #endif // VISP_HAVE_OPENCV
370 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
371 #endif //_vpMbKltMultiTracker_h_
virtual void setKltOpencv(const vpKltOpencv &t)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:252
virtual void track(const vpImage< unsigned char > &I)
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:495
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
vpMatrix m_L_kltMulti
Interaction matrix.
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
virtual void setScanLineVisibilityTest(const bool &v)
friend class vpMbKltMultiTracker
void setUseKltTracking(const std::string &name, const bool &useKltTracking)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
void setKltThresholdAcceptation(double th)
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:476
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:553
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
vpKltOpencv getKltOpencv() const
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setOgreShowConfigDialog(bool showConfigDialog)
Definition: vpMbTracker.h:639
void setThresholdAcceptation(double th)
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 setLod(bool useLod, const std::string &name="")
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:419
virtual void setGoodNbRayCastingAttemptsRatio(const double &ratio)
Definition: vpMbTracker.h:613
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
vpColVector m_weightedError_kltMulti
Weighted error.
Generic class defining intrinsic camera parameters.
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:465
Model based tracker using only KLT.
std::string m_referenceCameraName
Name of the reference camera.
virtual void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
Definition: vpMbTracker.h:623
virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &name="")
vpColVector m_w_kltMulti
Robust weights.
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
void setMaskBorder(const unsigned int &e)
virtual vpColVector getRobustWeights() const
void setCameraParameters(const vpCameraParameters &cam)
void preTracking(const vpImage< unsigned char > &I)
virtual unsigned int getNbPolygon() const
Definition: vpMbTracker.h:364
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
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:151
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()
void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, double r, const std::string &name="")
virtual void setClipping(const unsigned int &flags)
virtual void init(const vpImage< unsigned char > &I)
virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &name="")
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int, unsigned int, const vpHomogeneousMatrix &, const vpCameraParameters &, bool=false)
vpColVector m_error_kltMulti
(s - s*)
virtual void setFarClippingDistance(const double &dist)
virtual vpColVector getError() const
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
Definition: vpMbTracker.h:328
virtual void setDisplayFeatures(bool displayF)
Definition: vpMbTracker.h:513
Model based stereo (or more) tracker using only KLT.
virtual void getCameraParameters(vpCameraParameters &cam) const
Definition: vpMbTracker.h:244
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void setNearClippingDistance(const double &dist)