Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
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(const 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, const 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, const unsigned int thickness = 1, const bool displayFullModel = false);
110 
111  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
112  const vpColor &col, const unsigned int thickness = 1, const 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, const unsigned int thickness = 1,
117  const 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, const unsigned int thickness = 1, const 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  const unsigned int thickness = 1, const 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  const unsigned int thickness = 1, const bool displayFullModel = false);
132 
133  virtual std::vector<std::string> getCameraNames() const;
134 
135  virtual void getCameraParameters(vpCameraParameters &camera) const;
136  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
137  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
138  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
139 
141  virtual unsigned int getClipping(const std::string &cameraName) const;
142 
144  virtual vpMbHiddenFaces<vpMbtPolygon> &getFaces(const std::string &cameraName);
145  virtual std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getFaces() const;
146 
147  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle();
148  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle(const std::string &cameraName);
149 
150  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt();
151  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt(const std::string &cameraName);
152 
153  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder();
154  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder(const std::string &cameraName);
155 
156  virtual std::map<std::string, std::vector<vpImagePoint> > getKltImagePoints() const;
157 
158  virtual std::map<std::string, std::map<int, vpImagePoint> > getKltImagePointsWithId() const;
159 
160  virtual std::map<std::string, vpKltOpencv> getKltOpencv() const;
161 
162 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
163  virtual std::map<std::string, std::vector<cv::Point2f> > getKltPoints() const;
164 #else
165  virtual std::map<std::string, CvPoint2D32f *> getKltPoints();
166 #endif
167 
168  virtual std::map<std::string, int> getKltNbPoints() const;
169 
170  virtual unsigned int getNbPolygon() const;
171  virtual std::map<std::string, unsigned int> getMultiNbPolygon() const;
172 
178  inline unsigned int getNumberOfCameras() const { return (unsigned int)m_mapOfKltTrackers.size(); }
179 
180  using vpMbTracker::getPose;
181  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
182  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const;
183  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
184 
185  virtual inline vpColVector getError() const { return m_error_kltMulti; }
186 
187  virtual inline vpColVector getRobustWeights() const { return m_w_kltMulti; }
188 
189  virtual void init(const vpImage<unsigned char> &I);
190 
191 #ifdef VISP_HAVE_MODULE_GUI
192  virtual void initClick(const vpImage<unsigned char> &I, const std::vector<vpPoint> &points3D_list,
193  const std::string &displayFile = "");
194 
195  virtual void initClick(const vpImage<unsigned char> &I, const std::string &initFile, const bool displayHelp = false,
197 
198  virtual void initClick(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
199  const std::string &initFile1, const std::string &initFile2, const bool displayHelp = false,
200  const bool firstCameraIsReference = true);
201 
202  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
203  const std::string &initFile, const bool displayHelp = false);
204 
205  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
206  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp = false);
207 #endif
208 
209  virtual void initFromPose(const vpImage<unsigned char> &I, const std::string &initFile);
210  virtual void initFromPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
211  virtual void initFromPose(const vpImage<unsigned char> &I, const vpPoseVector &cPo);
212 
213  virtual void initFromPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
214  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
215  const bool firstCameraIsReference = true);
216  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
217  const vpHomogeneousMatrix &cMo_);
218  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
219  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
220 
221  virtual void loadConfigFile(const std::string &configFile);
222 
223  virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2,
224  const bool firstCameraIsReference = true);
225 
226  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
227 
228  virtual void loadModel(const std::string &modelFile, const bool verbose = false,
230 
231  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
232  const vpHomogeneousMatrix &cMo_, const bool verbose = false,
234  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
235  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo,
236  const vpHomogeneousMatrix &c2Mo, const bool verbose = false,
237  const bool firstCameraIsReference = true);
238  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
239  const std::string &cad_name,
240  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
241  const bool verbose = false);
242 
243  virtual void resetTracker();
244 
245  virtual void setAngleAppear(const double &a);
246  virtual void setAngleDisappear(const double &a);
247 
248  virtual void setCameraParameters(const vpCameraParameters &camera);
249 
250  virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2,
251  const bool firstCameraIsReference = true);
252 
253  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters &camera);
254 
255  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
256 
257  virtual void setCameraTransformationMatrix(const std::string &cameraName,
258  const vpHomogeneousMatrix &cameraTransformationMatrix);
259 
260  virtual void
261  setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
262 
263  virtual void setClipping(const unsigned int &flags);
264  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
265 
266  virtual void setCovarianceComputation(const bool &flag);
267 
268  virtual void setDisplayFeatures(const bool displayF);
269 
270  virtual void setFarClippingDistance(const double &dist);
271  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
272 
273 #ifdef VISP_HAVE_OGRE
274  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
275 
276  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
277 #endif
278 
279  virtual void setKltMaskBorder(const unsigned int &e);
280 
281  virtual void setKltOpencv(const vpKltOpencv &t);
282  virtual void setKltOpencv(const std::map<std::string, vpKltOpencv> &mapOfOpenCVTrackers);
283 
284  virtual void setKltThresholdAcceptation(const double th);
285 
286  virtual void setLod(const bool useLod, const std::string &name = "");
287  virtual void setLod(const bool useLod, const std::string &cameraName, const std::string &name);
288 
289  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name = "");
290 
291  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name = "");
292  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
293  const std::string &name);
294 
295  virtual void setNearClippingDistance(const double &dist);
296  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
297 
298  virtual void setOgreShowConfigDialog(const bool showConfigDialog);
299 
300  virtual void setOgreVisibilityTest(const bool &v);
301 
302  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
303 
304  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
305 
306  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
307  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
308  const bool firstCameraIsReference = true);
309 
310  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
311  const vpHomogeneousMatrix &cMo_);
312 
313  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
314  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
315 
316  virtual void setReferenceCameraName(const std::string &referenceCameraName);
317 
318  virtual void setScanLineVisibilityTest(const bool &v);
319 
320  virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking);
321 
322  virtual void track(const vpImage<unsigned char> &I);
323  virtual void track(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2);
324  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
326 
331  /* vp_deprecated */ virtual std::map<std::string, int> getNbKltPoints() const;
332  /* vp_deprecated */ virtual void setMaskBorder(const unsigned int &e);
333  /* vp_deprecated */ virtual void setThresholdAcceptation(const double th);
335 
336 protected:
339  virtual void computeVVS();
340  virtual void computeVVSInit();
342  virtual void computeVVSInteractionMatrixAndResidu(std::map<std::string, vpVelocityTwistMatrix> &mapOfVelocityTwist);
343  virtual void computeVVSWeights();
345 
346  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
347 
348  virtual void preTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
349 
351  virtual void reinit(/* const vpImage<unsigned char>& I */);
353 };
354 
355 #endif // VISP_HAVE_OPENCV
356 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
357 #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 void setDisplayFeatures(const bool displayF)
Definition: vpMbTracker.h:503
virtual void setCovarianceComputation(const bool &flag)
Definition: vpMbTracker.h:485
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
Definition: vpMbTracker.h:629
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
void setUseKltTracking(const std::string &name, const bool &useKltTracking)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:256
virtual void setAngleDisappear(const double &a)
Definition: vpMbTracker.h:466
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
Definition: vpMbTracker.h:543
virtual void loadModel(const std::string &modelFile, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
virtual vpColVector getRobustWeights() 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()
Class that defines what is a point.
Definition: vpPoint.h:58
virtual void loadConfigFile(const std::string &configFile)
int getKltNbPoints() const
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
std::vector< cv::Point2f > getKltPoints() const
std::vector< vpImagePoint > getKltImagePoints() const
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
virtual void setGoodNbRayCastingAttemptsRatio(const double &ratio)
Definition: vpMbTracker.h:603
void setKltThresholdAcceptation(const double th)
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:423
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
vpColVector m_weightedError_kltMulti
Weighted error.
virtual void getCameraParameters(vpCameraParameters &camera) const
Definition: vpMbTracker.h:248
Generic class defining intrinsic camera parameters.
std::map< int, vpImagePoint > getKltImagePointsWithId() const
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
virtual void setAngleAppear(const double &a)
Definition: vpMbTracker.h:455
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:613
virtual vpColVector getError() const
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
vpColVector m_w_kltMulti
Robust weights.
int getNbKltPoints() const
vpKltOpencv getKltOpencv() const
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
void setMaskBorder(const unsigned int &e)
void setCameraParameters(const vpCameraParameters &cam)
void preTracking(const vpImage< unsigned char > &I)
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
virtual unsigned int getNbPolygon() const
Definition: vpMbTracker.h:368
virtual void computeVVSInit()
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
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 vpMbHiddenFaces< vpMbtPolygon > & getFaces()
Definition: vpMbTracker.h:332
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)