Visual Servoing Platform  version 3.1.0
vpMbEdgeKltMultiTracker.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 edge klt tracker with multiple cameras.
35  *
36  * Authors:
37  * Souriya Trinh
38  *
39  *****************************************************************************/
40 
46 #ifndef __vpMbEdgeKltMultiTracker_h__
47 #define __vpMbEdgeKltMultiTracker_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/vpMbEdgeMultiTracker.h>
57 #include <visp3/mbt/vpMbKltMultiTracker.h>
58 
76 {
77 protected:
79  double m_factorKLT;
81  double m_factorMBT;
83  double thresholdKLT;
85  double thresholdMBT;
86 
89  std::map<std::string, vpHomogeneousMatrix> m_mapOfCameraTransformationMatrix;
90 
92  std::string m_referenceCameraName;
94  unsigned int m_nbrow;
103 
104 public:
106  vpMbEdgeKltMultiTracker(const unsigned int nbCameras);
107  vpMbEdgeKltMultiTracker(const std::vector<std::string> &cameraNames);
108 
109  virtual ~vpMbEdgeKltMultiTracker();
110 
111  virtual void display(const vpImage<unsigned char> &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<vpRGBa> &I, const vpHomogeneousMatrix &cMo_, const vpCameraParameters &cam_,
115  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
116 
117  virtual void display(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
118  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1,
119  const vpCameraParameters &cam2, const vpColor &color, const unsigned int thickness = 1,
120  const bool displayFullModel = false);
121 
122  virtual void display(const vpImage<vpRGBa> &I1, const vpImage<vpRGBa> &I2, const vpHomogeneousMatrix &c1Mo,
123  const vpHomogeneousMatrix &c2Mo, const vpCameraParameters &cam1, const vpCameraParameters &cam2,
124  const vpColor &color, const unsigned int thickness = 1, const bool displayFullModel = false);
125 
126  virtual void display(const std::map<std::string, const vpImage<unsigned char> *> &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 void display(const std::map<std::string, const vpImage<vpRGBa> *> &mapOfImages,
132  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
133  const std::map<std::string, vpCameraParameters> &mapOfCameraParameters, const vpColor &col,
134  const unsigned int thickness = 1, const bool displayFullModel = false);
135 
136  virtual std::vector<std::string> getCameraNames() const;
137 
138  virtual void getCameraParameters(vpCameraParameters &camera) const;
139  virtual void getCameraParameters(vpCameraParameters &cam1, vpCameraParameters &cam2) const;
140  virtual void getCameraParameters(const std::string &cameraName, vpCameraParameters &camera) const;
141  virtual void getCameraParameters(std::map<std::string, vpCameraParameters> &mapOfCameraParameters) const;
142 
144  virtual unsigned int getClipping(const std::string &cameraName) const;
145 
147  vpMbHiddenFaces<vpMbtPolygon> &getEdgeFaces(const std::string &cameraName);
148  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getEdgeFaces() const;
149  vpMbHiddenFaces<vpMbtPolygon> &getKltFaces(const std::string &cameraName);
150  std::map<std::string, vpMbHiddenFaces<vpMbtPolygon> > getKltFaces() const;
151 
157  inline double getFactorKLT() const { return m_factorKLT; }
158 
164  inline double getFactorMBT() const { return m_factorMBT; }
165 
166  virtual unsigned int getNbPolygon() const;
167  virtual std::map<std::string, unsigned int> getEdgeMultiNbPolygon() const;
168  virtual std::map<std::string, unsigned int> getKltMultiNbPolygon() const;
169 
175  inline unsigned int getNumberOfCameras() const { return (unsigned int)m_mapOfKltTrackers.size(); }
176 
178  virtual void getPose(vpHomogeneousMatrix &c1Mo, vpHomogeneousMatrix &c2Mo) const;
179  virtual void getPose(const std::string &cameraName, vpHomogeneousMatrix &cMo_) const;
180  virtual void getPose(std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses) const;
181 
182  virtual inline vpColVector getError() const { return m_error_hybridMulti; }
183 
184  virtual inline vpColVector getRobustWeights() const { return m_w_hybridMulti; }
185 
186  virtual void init(const vpImage<unsigned char> &I);
187 
188 #ifdef VISP_HAVE_MODULE_GUI
189  virtual void initClick(const vpImage<unsigned char> &I, const std::vector<vpPoint> &points3D_list,
190  const std::string &displayFile = "");
191 
192  virtual void initClick(const vpImage<unsigned char> &I, const std::string &initFile, const bool displayHelp = false);
193 
194  virtual void initClick(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
195  const std::string &initFile1, const std::string &initFile2, const bool displayHelp = false,
196  const bool firstCameraIsReference = true);
197 
198  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
199  const std::string &initFile, const bool displayHelp = false);
200 
201  virtual void initClick(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
202  const std::map<std::string, std::string> &mapOfInitFiles, const bool displayHelp = false);
203 #endif
204 
205  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double, const int,
206  const std::string &name = "");
207  virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const int, const std::string &name = "");
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 initFaceFromCorners(vpMbtPolygon &polygon);
222  virtual void initFaceFromLines(vpMbtPolygon &polygon);
223 
224  virtual void loadConfigFile(const std::string &configFile);
225 
226  virtual void loadConfigFile(const std::string &configFile1, const std::string &configFile2,
227  const bool firstCameraIsReference = true);
228 
229  virtual void loadConfigFile(const std::map<std::string, std::string> &mapOfConfigFiles);
230 
231  virtual void loadModel(const std::string &modelFile, const bool verbose = false);
232 
233  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
234  const vpHomogeneousMatrix &cMo_, const bool verbose = false);
235  virtual void reInitModel(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
236  const std::string &cad_name, const vpHomogeneousMatrix &c1Mo,
237  const vpHomogeneousMatrix &c2Mo, const bool verbose = false,
238  const bool firstCameraIsReference = true);
239  virtual void reInitModel(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
240  const std::string &cad_name,
241  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses,
242  const bool verbose = false);
243 
244  virtual void resetTracker();
245 
246  virtual void setAngleAppear(const double &a);
247  virtual void setAngleDisappear(const double &a);
248 
249  virtual void setCameraParameters(const vpCameraParameters &camera);
250 
251  virtual void setCameraParameters(const vpCameraParameters &camera1, const vpCameraParameters &camera2,
252  const bool firstCameraIsReference = true);
253 
254  virtual void setCameraParameters(const std::string &cameraName, const vpCameraParameters &camera);
255 
256  virtual void setCameraParameters(const std::map<std::string, vpCameraParameters> &mapOfCameraParameters);
257 
258  virtual void setCameraTransformationMatrix(const std::string &cameraName,
259  const vpHomogeneousMatrix &cameraTransformationMatrix);
260 
261  virtual void
262  setCameraTransformationMatrix(const std::map<std::string, vpHomogeneousMatrix> &mapOfTransformationMatrix);
263 
264  virtual void setClipping(const unsigned int &flags);
265  virtual void setClipping(const std::string &cameraName, const unsigned int &flags);
266 
267  virtual void setCovarianceComputation(const bool &flag);
268 
269  virtual void setDisplayFeatures(const bool displayF);
270 
271  virtual void setFarClippingDistance(const double &dist);
272  virtual void setFarClippingDistance(const std::string &cameraName, const double &dist);
273 
279  inline void setFactorKLT(const double factor) { m_factorKLT = factor; }
280 
286  inline void setFactorMBT(const double factor) { m_factorMBT = factor; }
287 
288 #ifdef VISP_HAVE_OGRE
289 
298  void setGoodNbRayCastingAttemptsRatio(const double &ratio);
299 
309  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts);
310 #endif
311 
312  virtual void setLod(const bool useLod, const std::string &name = "");
313  virtual void setLod(const bool useLod, const std::string &cameraName, const std::string &name);
314 
315  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name = "");
316  virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &cameraName,
317  const std::string &name);
318 
319  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &name = "");
320  virtual void setMinPolygonAreaThresh(const double minPolygonAreaThresh, const std::string &cameraName,
321  const std::string &name);
322 
323  virtual void setNearClippingDistance(const double &dist);
324  virtual void setNearClippingDistance(const std::string &cameraName, const double &dist);
325 
326  virtual void setOgreShowConfigDialog(const bool showConfigDialog);
327 
328  virtual void setOgreVisibilityTest(const bool &v);
329 
330  virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt);
331 
332  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo);
333 
334  virtual void setPose(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2,
335  const vpHomogeneousMatrix &c1Mo, const vpHomogeneousMatrix &c2Mo,
336  const bool firstCameraIsReference = true);
337 
338  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
339  const vpHomogeneousMatrix &cMo_);
340 
341  virtual void setPose(const std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
342  const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
343 
344  virtual void setProjectionErrorComputation(const bool &flag);
345 
346  virtual void setReferenceCameraName(const std::string &referenceCameraName);
347 
348  virtual void setScanLineVisibilityTest(const bool &v);
349 
350  virtual void setThresholdAcceptation(const double th);
351 
352  virtual void testTracking();
353 
354  virtual void track(const vpImage<unsigned char> &I);
355  virtual void track(const vpImage<unsigned char> &I1, const vpImage<unsigned char> &I2);
356  virtual void track(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
357 
358 protected:
359  // Current computeVVS function hides the base computeVVS but it is intended.
360  // The two following lines should have been added to remove compiler
361  // warning.
364 
365  virtual void computeVVS(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
366  const unsigned int lvl = 0);
367  virtual void computeVVSInit();
371  virtual void computeVVSInteractionMatrixAndResidu(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
372  std::map<std::string, vpVelocityTwistMatrix> &mapOfVelocityTwist);
373  virtual void computeVVSWeights();
375 
376  virtual unsigned int initMbtTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
377  unsigned int lvl);
378 
379  // Same thing as computeVVS
381 
382  virtual void postTracking(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages, const unsigned int lvl);
383 
384  virtual void reinit(/*const vpImage<unsigned char>& I*/);
385 
386  virtual void trackMovingEdges(std::map<std::string, const vpImage<unsigned char> *> &mapOfImages);
387 };
388 
389 #endif // VISP_HAVE_OPENCV
390 #endif //__vpMbEdgeKltMultiTracker_h__
virtual unsigned int getClipping() const
Definition: vpMbTracker.h:223
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
virtual void loadModel(const std::string &modelFile, const bool verbose=false)
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setMinLineLengthThresh(const double minLineLengthThresh, const std::string &name="")
virtual void setFarClippingDistance(const double &dist)
virtual vpColVector getError() const
virtual void setLod(const bool useLod, const std::string &name="")
double thresholdMBT
The threshold used in the robust estimation of MBT.
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
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 vpColVector getRobustWeights() const
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 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 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 vpHomogeneousMatrix getPose() const
Definition: vpMbTracker.h:390
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 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 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 postTracking(std::map< std::string, const vpImage< unsigned char > *> &mapOfImages)
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="")
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 unsigned int getNbPolygon() const
virtual void setAngleDisappear(const double &a)
double m_factorKLT
Factor for KLT trackers.
virtual void getCameraParameters(vpCameraParameters &camera) const
Make the complete stereo (or more) tracking of an object by using its CAD model.
virtual void computeVVS(std::map< std::string, const vpImage< unsigned char > *> &mapOfImages, const unsigned int lvl)
vpColVector m_w_hybridMulti
Robust weights.
virtual void setOptimizationMethod(const vpMbtOptimizationMethod &opt)
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false)
Model based stereo (or more) tracker using only KLT.
virtual std::vector< std::string > getCameraNames() const
virtual void setAngleAppear(const double &a)