Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpMbEdgeKltMultiTracker.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 edge klt tracker with multiple cameras.
33  *
34  * Authors:
35  * Souriya Trinh
36  *
37  *****************************************************************************/
38 
44 #ifndef _vpMbEdgeKltMultiTracker_h_
45 #define _vpMbEdgeKltMultiTracker_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/vpMbEdgeMultiTracker.h>
57 #include <visp3/mbt/vpMbKltMultiTracker.h>
58 
77 class VISP_EXPORT vp_deprecated vpMbEdgeKltMultiTracker : public vpMbEdgeMultiTracker, public vpMbKltMultiTracker
78 {
79 protected:
81  double m_factorKLT;
83  double m_factorMBT;
85  double thresholdKLT;
87  double thresholdMBT;
88 
91  std::map<std::string, vpHomogeneousMatrix> m_mapOfCameraTransformationMatrix;
92 
94  std::string m_referenceCameraName;
96  unsigned int m_nbrow;
105 
106 public:
108  vpMbEdgeKltMultiTracker(const unsigned int nbCameras);
109  vpMbEdgeKltMultiTracker(const std::vector<std::string> &cameraNames);
110 
111  virtual ~vpMbEdgeKltMultiTracker();
112 
113  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
114  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
115 
116  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
117  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
118 
119  virtual void display(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
120  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
121  const vpCameraParameters &cam2, const vpColor &color, const unsigned int thickness = 1,
122  const bool displayFullModel = false);
123 
124  virtual void display(const vpImage<vpRGBa> &I1, const vpImage<vpRGBa> &I2, const vpHomogeneousMatrix &c1Mo,
125  const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, const vpCameraParameters &cam2,
126  const vpColor &color, const unsigned int thickness = 1, const bool displayFullModel = false);
127 
128  virtual void display(const std::map<std::string, const vpImage<unsigned char> *> &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 void display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
134  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
135  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters, const vpColor &col,
136  const unsigned int thickness = 1, const bool displayFullModel = false);
137 
138  virtual std::vector<std::string> getCameraNames() const;
139 
140  virtual void getCameraParameters(vpCameraParameters &camera) const;
141  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
142  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
143  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
144 
146  virtual unsigned int getClipping(const std::string &cameraName) const;
147 
149  vpMbHiddenFaces<vpMbtPolygon> &getEdgeFaces(const std::string &cameraName);
150  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getEdgeFaces() const;
151  vpMbHiddenFaces<vpMbtPolygon> &getKltFaces(const std::string &cameraName);
152  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getKltFaces() const;
153 
159  inline double getFactorKLT() const { return m_factorKLT; }
160 
166  inline double getFactorMBT() const { return m_factorMBT; }
167 
168  virtual unsigned int getNbPolygon() const;
169  virtual std::map<std::string, unsigned int> getEdgeMultiNbPolygon() const;
170  virtual std::map<std::string, unsigned int> getKltMultiNbPolygon() const;
171 
177  inline unsigned int getNumberOfCameras() const { return (unsigned int)m_mapOfKltTrackers.size(); }
178 
180  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
181  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const;
182  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
183 
184  virtual inline vpColVector getError() const { return m_error_hybridMulti; }
185 
186  virtual inline vpColVector getRobustWeights() const { return m_w_hybridMulti; }
187 
188  virtual void init(const vpImage<unsigned char> &I);
189 
190 #ifdef VISP_HAVE_MODULE_GUI
191  virtual void initClick(const vpImage<unsigned char> &I, const std::vector<vpPoint> &points3D_list,
192  const std::string &displayFile = "");
193 
194  virtual void initClick(const vpImage<unsigned char> &I, const std::string &initFile, const bool displayHelp = false,
196 
197  virtual void initClick(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
198  const std::string &initFile1, const std::string &initFile2, const bool displayHelp = false,
199  const bool firstCameraIsReference = true);
200 
201  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
202  const std::string &initFile, const bool displayHelp = false);
203 
204  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
205  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp = false);
206 #endif
207 
208  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double, const int,
209  const std::string &name = "");
210  virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const int, const std::string &name = "");
211 
212  virtual void initFromPose(const vpImage<unsigned char> &I, const std::string &initFile);
213  virtual void initFromPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
214  virtual void initFromPose(const vpImage<unsigned char> &I, const vpPoseVector &cPo);
215 
216  virtual void initFromPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
217  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
218  const bool firstCameraIsReference = true);
219  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
220  const vpHomogeneousMatrix &cMo_);
221  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
222  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
223 
224  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
225  virtual void initFaceFromLines(vpMbtPolygon &polygon);
226 
227  virtual void loadConfigFile(const std::string &configFile);
228 
229  virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2,
230  const bool firstCameraIsReference = true);
231 
232  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
233 
234  virtual void loadModel(const std::string &modelFile, const bool verbose = false,
236 
237  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
238  const vpHomogeneousMatrix &cMo_, const bool verbose = false,
240  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
241  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo,
242  const vpHomogeneousMatrix &c2Mo, const bool verbose = false,
243  const bool firstCameraIsReference = true);
244  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
245  const std::string &cad_name,
246  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
247  const bool verbose = false);
248 
249  virtual void resetTracker();
250 
251  virtual void setAngleAppear(const double &a);
252  virtual void setAngleDisappear(const double &a);
253 
254  virtual void setCameraParameters(const vpCameraParameters &camera);
255 
256  virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2,
257  const bool firstCameraIsReference = true);
258 
259  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters &camera);
260 
261  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
262 
263  virtual void setCameraTransformationMatrix(const std::string &cameraName,
264  const vpHomogeneousMatrix &cameraTransformationMatrix);
265 
266  virtual void
267  setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
268 
269  virtual void setClipping(const unsigned int &flags);
270  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
271 
272  virtual void setCovarianceComputation(const bool &flag);
273 
274  virtual void setDisplayFeatures(const bool displayF);
275 
276  virtual void setFarClippingDistance(const double &dist);
277  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
278 
284  inline void setFactorKLT(const double factor) { m_factorKLT = factor; }
285 
291  inline void setFactorMBT(const double factor) { m_factorMBT = factor; }
292 
293 #ifdef VISP_HAVE_OGRE
294 
303  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
304 
314  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
315 #endif
316 
317  virtual void setLod(const bool useLod, const std::string &name = "");
318  virtual void setLod(const bool useLod, const std::string &cameraName, const std::string &name);
319 
320  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name = "");
321  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &cameraName,
322  const std::string &name);
323 
324  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name = "");
325  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
326  const std::string &name);
327 
328  virtual void setNearClippingDistance(const double &dist);
329  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
330 
331  virtual void setOgreShowConfigDialog(const bool showConfigDialog);
332 
333  virtual void setOgreVisibilityTest(const bool &v);
334 
335  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
336 
337  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
338 
339  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
340  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
341  const bool firstCameraIsReference = true);
342 
343  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
344  const vpHomogeneousMatrix &cMo_);
345 
346  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
347  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
348 
349  virtual void setProjectionErrorComputation(const bool &flag);
350 
351  virtual void setReferenceCameraName(const std::string &referenceCameraName);
352 
353  virtual void setScanLineVisibilityTest(const bool &v);
354 
355  virtual void setThresholdAcceptation(const double th);
356 
357  virtual void testTracking();
358 
359  virtual void track(const vpImage<unsigned char> &I);
360  virtual void track(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2);
361  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
362 
363 protected:
364  // Current computeVVS function hides the base computeVVS but it is intended.
365  // The two following lines should have been added to remove compiler
366  // warning.
369 
370  virtual void computeVVS(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
371  const unsigned int lvl = 0);
372  virtual void computeVVSInit();
376  virtual void computeVVSInteractionMatrixAndResidu(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
377  std::map<std::string, vpVelocityTwistMatrix> &mapOfVelocityTwist);
378  virtual void computeVVSWeights();
380 
381  virtual unsigned int initMbtTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
382  unsigned int lvl);
383 
384  // Same thing as computeVVS
386 
387  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages, const unsigned int lvl);
388 
389  virtual void reinit(/*const vpImage<unsigned char>& I*/);
390 
391  virtual void trackMovingEdges(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
392 };
393 
394 #endif // VISP_HAVE_OPENCV
395 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
396 #endif //_vpMbEdgeKltMultiTracker_h_
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
virtual void setFarClippingDistance(const double &dist)
virtual vpColVector getRobustWeights() const
virtual void setLod(const bool useLod, const std::string &name="")
double thresholdMBT
The threshold used in the robust estimation of MBT.
virtual void loadModel(const std::string &modelFile, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:256
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
virtual void setDisplayFeatures(const bool displayF)
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
friend class vpMbEdgeKltMultiTracker
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
virtual void track(const vpImage< unsigned char > &I)
virtual void setProjectionErrorComputation(const bool &flag)
double m_factorMBT
Factor for edge trackers.
virtual void loadConfigFile(const std::string &configFile)
unsigned int m_nbrow
Number of features.
virtual void setThresholdAcceptation(const double th)
Hybrid stereo (or more) tracker based on moving-edges and keypoints tracked using KLT tracker...
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setClipping(const unsigned int &flags)
virtual void setOgreShowConfigDialog(const bool showConfigDialog)
vpMatrix m_L_hybridMulti
Interaction matrix.
virtual unsigned int getNbPolygon() const
virtual void setReferenceCameraName(const std::string &referenceCameraName)
virtual void setNearClippingDistance(const double &dist)
vpColVector m_weightedError_hybridMulti
Weighted error.
Class that defines what is a point.
Definition: vpPoint.h:58
double thresholdKLT
The threshold used in the robust estimation of KLT.
virtual vpColVector getError() 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)
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
virtual void initClick(const vpImage< unsigned char > &I, const std::vector< vpPoint > &points3D_list, const std::string &displayFile="")
void init(const vpImage< unsigned char > &I)
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:66
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:423
virtual void setOgreVisibilityTest(const bool &v)
virtual void computeVVS(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, const unsigned int lvl)
vpColVector m_error_hybridMulti
(s - s*)
virtual void setScanLineVisibilityTest(const bool &v)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
virtual void setCameraParameters(const vpCameraParameters &camera)
Generic class defining intrinsic camera parameters.
unsigned int initMbtTracking(unsigned int &nberrors_lines, unsigned int &nberrors_cylinders, unsigned int &nberrors_circles)
virtual void setCameraTransformationMatrix(const std::string &cameraName, const vpHomogeneousMatrix &cameraTransformationMatrix)
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name="")
void setFactorMBT(const double factor)
void setFactorKLT(const double factor)
virtual void setCovarianceComputation(const bool &flag)
virtual void initFaceFromLines(vpMbtPolygon &polygon)
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")
virtual void getCameraParameters(vpCameraParameters &camera) const
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:92
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
std::string m_referenceCameraName
Name of the reference camera.
virtual std::vector< std::string > getCameraNames() const
virtual void postTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages)
unsigned int getNumberOfCameras() const
virtual void setAngleDisappear(const double &a)
double m_factorKLT
Factor for KLT trackers.
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
Make the complete stereo (or more) tracking of an object by using its CAD model.
vpColVector m_w_hybridMulti
Robust weights.
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
Model based stereo (or more) tracker using only KLT.
virtual void setAngleAppear(const double &a)