Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMbtDistanceKltPoints.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Klt polygon, containing points of interest.
32  *
33  * Authors:
34  * Romain Tallonneau
35  * Aurelien Yol
36  *
37  *****************************************************************************/
38 
39 #ifndef vpMbtDistanceKltPoints_h
40 #define vpMbtDistanceKltPoints_h
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
45 
46 #include <map>
47 
48 #include <visp3/core/vpPolygon3D.h>
49 #include <visp3/klt/vpKltOpencv.h>
50 #include <visp3/core/vpPlane.h>
51 #include <visp3/core/vpDisplay.h>
52 #include <visp3/core/vpGEMM.h>
53 #include <visp3/vision/vpHomography.h>
54 #include <visp3/mbt/vpMbHiddenFaces.h>
55 
65 class VISP_EXPORT vpMbtDistanceKltPoints
66 {
67 private:
69  vpMatrix H;
71  vpColVector N;
73  vpColVector N_cur;
75  double invd0;
77  vpColVector cRc0_0n;
79  std::map<int, vpImagePoint> initPoints;
81  std::map<int, vpImagePoint> curPoints;
83  std::map<int, int> curPointsInd;
85  unsigned int nbPointsCur;
87  unsigned int nbPointsInit;
89  unsigned int minNbPoint;
91  bool enoughPoints;
93  double dt;
95  double d0;
99  bool isTrackedKltPoints;
100 
101 public:
108 
109 private:
110 
111  double compute_1_over_Z(const double x, const double y);
112  void computeP_mu_t(const double x_in, const double y_in, double& x_out, double& y_out, const vpMatrix& cHc0);
113  bool isTrackedFeature(const int id);
114 
115 //private:
116 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
117 // vpMbtDistanceKltPoints(const vpMbtDistanceKltPoints &)
118 // : H(), N(), N_cur(), invd0(1.), cRc0_0n(), initPoints(), curPoints(), curPointsInd(),
119 // nbPointsCur(0), nbPointsInit(0), minNbPoint(4), enoughPoints(false), dt(1.), d0(1.),
120 // cam(), isTrackedKltPoints(true), polygon(NULL), hiddenface(NULL), useScanLine(false)
121 // {
122 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
123 // }
124 // vpMbtDistanceKltPoints &operator=(const vpMbtDistanceKltPoints &){
125 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
126 // return *this;
127 // }
128 //#endif
129 
130 public:
132  virtual ~vpMbtDistanceKltPoints();
133 
134  unsigned int computeNbDetectedCurrent(const vpKltOpencv& _tracker);
135  void computeHomography(const vpHomogeneousMatrix& _cTc0, vpHomography& cHc0);
136  void computeInteractionMatrixAndResidu(vpColVector& _R, vpMatrix& _J);
137 
138  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);
139  void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor col, const unsigned int thickness = 1, const bool displayFullModel = false);
140 
141  void displayPrimitive(const vpImage<unsigned char>& _I);
142  void displayPrimitive(const vpImage<vpRGBa>& _I);
143 
149  inline vpCameraParameters& getCameraParameters(){ return cam; }
150 
151  inline vpColVector getCurrentNormal() const {return N_cur; }
152 
153  inline std::map<int, vpImagePoint>& getCurrentPoints() {return curPoints; }
154 
155  inline std::map<int, int>& getCurrentPointsInd() {return curPointsInd; }
156 
164  inline unsigned int getInitialNumberPoint() const { return nbPointsInit;}
175  inline unsigned int getCurrentNumberPoints() const {return nbPointsCur;}
176 
177  inline bool hasEnoughPoints() const {return enoughPoints;}
178 
179  void init(const vpKltOpencv& _tracker);
180 
186  inline bool isTracked() const {return isTrackedKltPoints;}
187 
188  void removeOutliers(const vpColVector& weight, const double &threshold_outlier);
189 
195  virtual inline void setCameraParameters(const vpCameraParameters& _cam){ cam = _cam; }
196 
202  inline void setTracked(const bool& track) {this->isTrackedKltPoints = track;}
203 
204 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
205  void updateMask(cv::Mat &mask, unsigned char _nb = 255, unsigned int _shiftBorder = 0);
206 #else
207  void updateMask(IplImage* mask, unsigned char _nb = 255, unsigned int _shiftBorder = 0);
208 #endif
209 };
210 
211 #endif
212 
213 #endif // VISP_HAVE_OPENCV
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
void setTracked(const bool &track)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
Implementation of a polygon of the model containing points of interest. It is used by the model-based...
std::map< int, int > & getCurrentPointsInd()
Implementation of an homography and operations on homographies.
Definition: vpHomography.h:179
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:64
Generic class defining intrinsic camera parameters.
unsigned int getInitialNumberPoint() const
std::map< int, vpImagePoint > & getCurrentPoints()
virtual void setCameraParameters(const vpCameraParameters &_cam)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
Definition: vpKltOpencv.h:76
vpMbtPolygon * polygon
Pointer to the polygon that define a face.
unsigned int getCurrentNumberPoints() const
vpColVector getCurrentNormal() const
vpCameraParameters & getCameraParameters()
bool useScanLine
Use scanline rendering.