ViSP  2.10.0
vpMeLine.h
1 /****************************************************************************
2  *
3  * $Id: vpMeLine.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Moving edges.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
47 #ifndef vpMeLine_HH
48 #define vpMeLine_HH
49 
50 #include <visp/vpMatrix.h>
51 #include <visp/vpMath.h>
52 #include <visp/vpMeTracker.h>
53 
54 #include <math.h>
55 #include <iostream>
56 
102 /*
103  The code below shows how to use this class.
104 \code
105 #include <visp/vpConfig.h>
106 #include <visp/vpImage.h>
107 #include <visp/vpMeLine.h>
108 #include <visp/vpImagePoint.h>
109 
110 int main()
111 {
112  vpImage<unsigned char> I(240, 320);
113 
114  // Fill the image with a black rectangle
115  I = 0;
116  for (int i = 100; i < 180; i ++) {
117  for (int j = 120; j < 250; j ++) {
118  I[i][j] = 255;
119  }
120  }
121 
122  // Set the moving-edges tracker parameters
123  vpMe me;
124  me.setRange(25);
125  me.setThreshold(15000);
126  me.setSampleStep(10);
127 
128  // Initialize the moving-edges line tracker parameters
129  vpMeLine line;
130  line.setMe(&me);
131 
132  // Initialize the location of the vertical line to track
133  vpImagePoint ip1, ip2; // Two points belonging to the line to track
134  ip1.set_i( 120 );
135  ip1.set_j( 119 );
136  ip2.set_i( 170 );
137  ip2.set_j( 122 );
138 
139  line.initTracking(I, ip1, ip2);
140 
141  while ( 1 )
142  {
143  // ... Here the code to read or grab the next image.
144 
145  // Track the line.
146  line.track(I);
147  }
148  return 0;
149 }
150 \endcode
151 
152  \note It is possible to display the line as an overlay. For that you
153  must use the display function of the class vpMeLine.
154 */
155 
156 class VISP_EXPORT vpMeLine : public vpMeTracker
157 {
158 private:
159  static void update_indices(double theta,int incr,int i,int j,int& i1,int& i2,int& j1,int& j2);
160 
161 protected:
162  vpMeSite PExt[2] ;
163 
164  double rho, theta ;
165  double delta ,delta_1;
166  double angle, angle_1;
167  int sign;
168 
171 
172 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
173 public:
174 #else
175 protected:
176 #endif
177 
178  double a;
179  double b;
180  double c;
181 
182 public:
183  vpMeLine() ;
184  vpMeLine(const vpMeLine &meline);
185  virtual ~vpMeLine() ;
186 
187  void display(const vpImage<unsigned char>& I, vpColor col) ;
188 
189  void track(const vpImage<unsigned char>& Im);
190 
191  void sample(const vpImage<unsigned char>&image);
192  void reSample(const vpImage<unsigned char> &I) ;
193  void leastSquare() ;
194  void updateDelta();
195  void setExtremities() ;
196  void seekExtremities(const vpImage<unsigned char> &I) ;
197  void suppressPoints() ;
198 
199  void initTracking(const vpImage<unsigned char> &I) ;
200  void initTracking(const vpImage<unsigned char> &I,
201  const vpImagePoint &ip1,
202  const vpImagePoint &ip2) ;
203 
204  void computeRhoTheta(const vpImage<unsigned char> &I) ;
205  double getRho() const ;
206  double getTheta() const ;
207  void getExtremities(vpImagePoint &ip1, vpImagePoint &ip2) ;
208 
212  void getEquationParam(double &A, double &B, double &C) { A = a; B = b; C = c; }
213 
217  inline double getA() const {return a; }
218 
222  inline double getB() const {return b; }
223 
227  inline double getC() const {return c; }
228 
229  static bool intersection(const vpMeLine &line1, const vpMeLine &line2,
230  vpImagePoint &ip);
231 
241  inline void computeRhoSignFromIntensity(const bool useIntensityForRho){
242  _useIntensityForRho = useIntensityForRho;
243  }
244 
245 //Static Functions
246 public:
247  static void display(const vpImage<unsigned char>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
248  const double &A, const double &B, const double &C,
249  const vpColor &color = vpColor::green, unsigned int thickness=1);
250  static void display(const vpImage<vpRGBa>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
251  const double &A, const double &B, const double &C,
252  const vpColor &color = vpColor::green, unsigned int thickness=1);
253 
254  static void display(const vpImage<unsigned char>& 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  static void display(const vpImage<vpRGBa>& I,const vpMeSite &PExt1, const vpMeSite &PExt2,
259  const std::list<vpMeSite> &site_list,
260  const double &A, const double &B, const double &C,
261  const vpColor &color = vpColor::green, unsigned int thickness=1);
262 };
263 
264 #endif
void computeRhoSignFromIntensity(const bool useIntensityForRho)
Definition: vpMeLine.h:241
double c
Parameter c of the line equation a*i + b*j + c = 0.
Definition: vpMeLine.h:180
double getB() const
Definition: vpMeLine.h:222
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Definition: vpMeSite.h:76
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
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:170
virtual void sample(const vpImage< unsigned char > &image)=0
Sample pixels at a given interval.
static const vpColor green
Definition: vpColor.h:170
double theta
Definition: vpMeLine.h:164
Class that tracks in an image a line moving edges.
Definition: vpMeLine.h:156
double delta_1
Definition: vpMeLine.h:165
double getA() const
Definition: vpMeLine.h:217
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:71
double a
Parameter a of the line equation a*i + b*j + c = 0.
Definition: vpMeLine.h:178
double b
Parameter b of the line equation a*i + b*j + c = 0.
Definition: vpMeLine.h:179
int sign
Definition: vpMeLine.h:167
void initTracking(const vpImage< unsigned char > &I)
double angle_1
Definition: vpMeLine.h:166
void getEquationParam(double &A, double &B, double &C)
Definition: vpMeLine.h:212
double getC() const
Definition: vpMeLine.h:227
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0