Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpMeLine.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  * Moving edges.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
43 #ifndef vpMeLine_HH
44 #define vpMeLine_HH
45 
46 #include <visp3/core/vpMatrix.h>
47 #include <visp3/core/vpMath.h>
48 #include <visp3/me/vpMeTracker.h>
49 
50 #include <math.h>
51 #include <iostream>
52 
98 /*
99  The code below shows how to use this class.
100 \code
101 #include <visp3/core/vpConfig.h>
102 #include <visp3/core/vpImage.h>
103 #include <visp3/me/vpMeLine.h>
104 #include <visp3/core/vpImagePoint.h>
105 
106 int main()
107 {
108  vpImage<unsigned char> I(240, 320);
109 
110  // Fill the image with a black rectangle
111  I = 0;
112  for (int i = 100; i < 180; i ++) {
113  for (int j = 120; j < 250; j ++) {
114  I[i][j] = 255;
115  }
116  }
117 
118  // Set the moving-edges tracker parameters
119  vpMe me;
120  me.setRange(25);
121  me.setThreshold(15000);
122  me.setSampleStep(10);
123 
124  // Initialize the moving-edges line tracker parameters
125  vpMeLine line;
126  line.setMe(&me);
127 
128  // Initialize the location of the vertical line to track
129  vpImagePoint ip1, ip2; // Two points belonging to the line to track
130  ip1.set_i( 120 );
131  ip1.set_j( 119 );
132  ip2.set_i( 170 );
133  ip2.set_j( 122 );
134 
135  line.initTracking(I, ip1, ip2);
136 
137  while ( 1 )
138  {
139  // ... Here the code to read or grab the next image.
140 
141  // Track the line.
142  line.track(I);
143  }
144  return 0;
145 }
146 \endcode
147 
148  \note It is possible to display the line as an overlay. For that you
149  must use the display function of the class vpMeLine.
150 */
151 
152 class VISP_EXPORT vpMeLine : public vpMeTracker
153 {
154 private:
155  static void update_indices(double theta,int incr,int i,int j,int& i1,int& i2,int& j1,int& j2);
156 
157 protected:
158  vpMeSite PExt[2] ;
159 
160  double rho, theta ;
161  double delta ,delta_1;
162  double angle, angle_1;
163  int sign;
164 
167 
168 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
169 public:
170 #else
171 protected:
172 #endif
173 
174  double a;
175  double b;
176  double c;
177 
178 public:
179  vpMeLine() ;
180  vpMeLine(const vpMeLine &meline);
181  virtual ~vpMeLine() ;
182 
183  void display(const vpImage<unsigned char>& I, vpColor col) ;
184 
185  void track(const vpImage<unsigned char>& Im);
186 
187  void sample(const vpImage<unsigned char>&image);
188  void reSample(const vpImage<unsigned char> &I) ;
189  void leastSquare() ;
190  void updateDelta();
191  void setExtremities() ;
192  void seekExtremities(const vpImage<unsigned char> &I) ;
193  void suppressPoints() ;
194 
195  void initTracking(const vpImage<unsigned char> &I) ;
196  void initTracking(const vpImage<unsigned char> &I,
197  const vpImagePoint &ip1,
198  const vpImagePoint &ip2) ;
199 
200  void computeRhoTheta(const vpImage<unsigned char> &I) ;
201  double getRho() const ;
202  double getTheta() const ;
203  void getExtremities(vpImagePoint &ip1, vpImagePoint &ip2) ;
204 
208  void getEquationParam(double &A, double &B, double &C) { A = a; B = b; C = c; }
209 
213  inline double getA() const {return a; }
214 
218  inline double getB() const {return b; }
219 
223  inline double getC() const {return c; }
224 
225  static bool intersection(const vpMeLine &line1, const vpMeLine &line2,
226  vpImagePoint &ip);
227 
237  inline void computeRhoSignFromIntensity(const bool useIntensityForRho){
238  _useIntensityForRho = useIntensityForRho;
239  }
240 
241 //Static Functions
242 public:
243  static void display(const vpImage<unsigned char>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
244  const double &A, const double &B, const double &C,
245  const vpColor &color = vpColor::green, unsigned int thickness=1);
246  static void display(const vpImage<vpRGBa>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
247  const double &A, const double &B, const double &C,
248  const vpColor &color = vpColor::green, unsigned int thickness=1);
249 
250  static void display(const vpImage<unsigned char>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
251  const std::list<vpMeSite> &site_list,
252  const double &A, const double &B, const double &C,
253  const vpColor &color = vpColor::green, unsigned int thickness=1);
254  static void display(const vpImage<vpRGBa>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
255  const std::list<vpMeSite> &site_list,
256  const double &A, const double &B, const double &C,
257  const vpColor &color = vpColor::green, unsigned int thickness=1);
258 };
259 
260 #endif
void computeRhoSignFromIntensity(const bool useIntensityForRho)
Definition: vpMeLine.h:237
double c
Parameter c of the line equation a*i + b*j + c = 0.
Definition: vpMeLine.h:176
double getB() const
Definition: vpMeLine.h:218
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Definition: vpMeSite.h:72
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
bool _useIntensityForRho
Flag to specify wether the intensity of the image at the middle point is used to compute the sign of ...
Definition: vpMeLine.h:166
virtual void sample(const vpImage< unsigned char > &image)=0
Sample pixels at a given interval.
static const vpColor green
Definition: vpColor.h:166
double theta
Definition: vpMeLine.h:160
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:152
double delta_1
Definition: vpMeLine.h:161
double getA() const
Definition: vpMeLine.h:213
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:64
double a
Parameter a of the line equation a*i + b*j + c = 0.
Definition: vpMeLine.h:174
double b
Parameter b of the line equation a*i + b*j + c = 0.
Definition: vpMeLine.h:175
int sign
Definition: vpMeLine.h:163
void initTracking(const vpImage< unsigned char > &I)
double angle_1
Definition: vpMeLine.h:162
void getEquationParam(double &A, double &B, double &C)
Definition: vpMeLine.h:208
double getC() const
Definition: vpMeLine.h:223
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0