Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
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;
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(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, unsigned int thickness = 1, bool displayFullModel = false);
115 
116  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
117  const vpColor &col, unsigned int thickness = 1, 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, unsigned int thickness = 1,
122  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, unsigned int thickness = 1, 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  unsigned int thickness = 1, 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  unsigned int thickness = 1, bool displayFullModel = false);
137 
138  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int, unsigned int,
139  const vpHomogeneousMatrix &,
140  const vpCameraParameters &,
141  bool =false)
142  {
143  std::cerr << "Not implemented. Deprecated class." << std::endl;
144  return std::vector<std::vector<double> >();
145  }
146 
147  virtual std::vector<std::string> getCameraNames() const;
148 
149  virtual void getCameraParameters(vpCameraParameters &camera) const;
150  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
151  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
152  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
153 
155  virtual unsigned int getClipping(const std::string &cameraName) const;
156 
158  vpMbHiddenFaces<vpMbtPolygon> &getEdgeFaces(const std::string &cameraName);
159  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getEdgeFaces() const;
160  vpMbHiddenFaces<vpMbtPolygon> &getKltFaces(const std::string &cameraName);
161  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getKltFaces() const;
162 
168  inline double getFactorKLT() const { return m_factorKLT; }
169 
175  inline double getFactorMBT() const { return m_factorMBT; }
176 
177  virtual unsigned int getNbPolygon() const;
178  virtual std::map<std::string, unsigned int> getEdgeMultiNbPolygon() const;
179  virtual std::map<std::string, unsigned int> getKltMultiNbPolygon() const;
180 
186  inline unsigned int getNumberOfCameras() const { return (unsigned int)m_mapOfKltTrackers.size(); }
187 
189  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
190  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo) const;
191  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
192 
193  virtual inline vpColVector getError() const { return m_error_hybridMulti; }
194 
195  virtual inline vpColVector getRobustWeights() const { return m_w_hybridMulti; }
196 
197  virtual void init(const vpImage<unsigned char> &I);
198 
199 #ifdef VISP_HAVE_MODULE_GUI
200  virtual void initClick(const vpImage<unsigned char> &I, const std::vector<vpPoint> &points3D_list,
201  const std::string &displayFile = "");
202 
203  virtual void initClick(const vpImage<unsigned char> &I, const std::string &initFile, bool displayHelp = false,
205 
206  virtual void initClick(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
207  const std::string &initFile1, const std::string &initFile2, bool displayHelp = false,
208  bool firstCameraIsReference = true);
209 
210  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
211  const std::string &initFile, bool displayHelp = false);
212 
213  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
214  const std::map<std::string, std::string> &mapOfInitFiles, bool displayHelp = false);
215 #endif
216 
217  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double, const int,
218  const std::string &name = "");
219  virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const int, const std::string &name = "");
220 
221  virtual void initFromPose(const vpImage<unsigned char> &I, const std::string &initFile);
222  virtual void initFromPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
223  virtual void initFromPose(const vpImage<unsigned char> &I, const vpPoseVector &cPo);
224 
225  virtual void initFromPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
226  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
227  bool firstCameraIsReference = true);
228  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
229  const vpHomogeneousMatrix &cMo);
230  virtual void initFromPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
231  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
232 
233  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
234  virtual void initFaceFromLines(vpMbtPolygon &polygon);
235 
236  virtual void loadConfigFile(const std::string &configFile);
237 
238  virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2,
239  bool firstCameraIsReference = true);
240 
241  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
242 
243  virtual void loadModel(const std::string &modelFile, bool verbose = false,
245 
246  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
247  const vpHomogeneousMatrix &cMo, bool verbose = false,
249  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
250  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo,
251  const vpHomogeneousMatrix &c2Mo, bool verbose = false,
252  bool firstCameraIsReference = true);
253  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
254  const std::string &cad_name,
255  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
256  bool verbose = false);
257 
258  virtual void resetTracker();
259 
260  virtual void setAngleAppear(const double &a);
261  virtual void setAngleDisappear(const double &a);
262 
263  virtual void setCameraParameters(const vpCameraParameters &camera);
264 
265  virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2,
266  bool firstCameraIsReference = true);
267 
268  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters &camera);
269 
270  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
271 
272  virtual void setCameraTransformationMatrix(const std::string &cameraName,
273  const vpHomogeneousMatrix &cameraTransformationMatrix);
274 
275  virtual void
276  setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
277 
278  virtual void setClipping(const unsigned int &flags);
279  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
280 
281  virtual void setCovarianceComputation(const bool &flag);
282 
283  virtual void setDisplayFeatures(bool displayF);
284 
285  virtual void setFarClippingDistance(const double &dist);
286  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
287 
293  inline void setFactorKLT(const double factor) { m_factorKLT = factor; }
294 
300  inline void setFactorMBT(const double factor) { m_factorMBT = factor; }
301 
302 #ifdef VISP_HAVE_OGRE
303 
312  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
313 
323  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
324 #endif
325 
326  virtual void setLod(bool useLod, const std::string &name = "");
327  virtual void setLod(bool useLod, const std::string &cameraName, const std::string &name);
328 
329  virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &name = "");
330  virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &cameraName,
331  const std::string &name);
332 
333  virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &name = "");
334  virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &cameraName,
335  const std::string &name);
336 
337  virtual void setNearClippingDistance(const double &dist);
338  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
339 
340  virtual void setOgreShowConfigDialog(bool showConfigDialog);
341 
342  virtual void setOgreVisibilityTest(const bool &v);
343 
344  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
345 
346  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
347  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cMo);
348 
349  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
350  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
351  bool firstCameraIsReference = true);
352 
353  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
354  const vpHomogeneousMatrix &cMo);
355 
356  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
357  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
358 
359  virtual void setProjectionErrorComputation(const bool &flag);
360 
361  virtual void setReferenceCameraName(const std::string &referenceCameraName);
362 
363  virtual void setScanLineVisibilityTest(const bool &v);
364 
365  virtual void setThresholdAcceptation(double th);
366 
367  virtual void testTracking();
368 
369  virtual void track(const vpImage<unsigned char> &I);
370  virtual void track(const vpImage<vpRGBa> &I_color);
371  virtual void track(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2);
372  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
373 
374 protected:
375  // Current computeVVS function hides the base computeVVS but it is intended.
376  // The two following lines should have been added to remove compiler
377  // warning.
380 
381  virtual void computeVVS(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
382  unsigned int lvl = 0);
383  virtual void computeVVSInit();
387  virtual void computeVVSInteractionMatrixAndResidu(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
388  std::map<std::string, vpVelocityTwistMatrix> &mapOfVelocityTwist);
389  virtual void computeVVSWeights();
391 
392  virtual unsigned int initMbtTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
393  unsigned int lvl);
394 
395  // Same thing as computeVVS
397 
398  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
399 
400  virtual void reinit(/*const vpImage<unsigned char>& I*/);
401 
402  virtual void trackMovingEdges(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
403 };
404 
405 #endif // VISP_HAVE_OPENCV
406 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
407 #endif //_vpMbEdgeKltMultiTracker_h_
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:252
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
virtual void setLod(bool useLod, const std::string &name="")
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setFarClippingDistance(const double &dist)
virtual vpColVector getError() const
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 initFaceFromCorners(vpMbtPolygon &polygon)
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
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 initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
friend class vpMbEdgeKltMultiTracker
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
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)
virtual void setMinPolygonAreaThresh(double minPolygonAreaThresh, const std::string &name="")
unsigned int m_nbrow
Number of features.
virtual vpColVector getRobustWeights() const
double m_thresholdMBT
The threshold used in the robust estimation of MBT.
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 initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="")
vpMatrix m_L_hybridMulti
Interaction matrix.
virtual void setReferenceCameraName(const std::string &referenceCameraName)
double m_thresholdKLT
The threshold used in the robust estimation of KLT.
virtual void setNearClippingDistance(const double &dist)
vpColVector m_weightedError_hybridMulti
Weighted error.
Class that defines what is a point.
Definition: vpPoint.h:58
virtual void setDisplayFeatures(bool displayF)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int, unsigned int, const vpHomogeneousMatrix &, const vpCameraParameters &, bool=false)
virtual vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:419
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 void setOgreShowConfigDialog(bool showConfigDialog)
virtual void setOgreVisibilityTest(const bool &v)
unsigned int getNumberOfCameras() const
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 testTracking()
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 loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void computeVVSWeights(vpRobust &robust, const vpColVector &error, vpColVector &w)
void setFactorMBT(const double factor)
void setFactorKLT(const double factor)
virtual void setCovarianceComputation(const bool &flag)
virtual void postTracking(std::map< std::string, const vpImage< unsigned char > *> &mapOfImages)
virtual void initFaceFromLines(vpMbtPolygon &polygon)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="")
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:151
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
std::string m_referenceCameraName
Name of the reference camera.
virtual unsigned int getNbPolygon() const
virtual void setAngleDisappear(const double &a)
virtual void setThresholdAcceptation(double th)
double m_factorKLT
Factor for KLT trackers.
virtual void setMinLineLengthThresh(double minLineLengthThresh, const std::string &name="")
virtual void getCameraParameters(vpCameraParameters &camera) const
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 std::vector< std::string > getCameraNames() const
virtual void setAngleAppear(const double &a)
virtual void computeVVS(std::map< std::string, const vpImage< unsigned char > *> &mapOfImages, unsigned int lvl)