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  * Moving edges.
33  *
34  * Authors:
35  * Eric Marchand
36  * Andrew Comport
37  * Aurelien Yol
38  *
39  *****************************************************************************/
40 
41 /*!
42         \file vpMe.h
43         \brief Moving edges
44 */
45 
46 #ifndef vpMe_H
47 #define vpMe_H
48 
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpMath.h>
51 #include <visp3/core/vpMatrix.h>
52 
53 /*!
54   \class vpMe
55   \ingroup module_me
56 
57   This class defines predetermined masks for sites and holds moving edges
58   tracking parameters.
59  */
60 class VISP_EXPORT vpMe
61 {
62 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
63 public:
64 #else
65 private:
66 #endif
67   double threshold; //! Likelihood ratio threshold
68   double mu1;       //! Contrast continuity parameter (left boundary)
69   double mu2;       //! Contrast continuity parameter (right boundary)
70   double min_samplestep;
71   unsigned int anglestep;
72   int mask_sign;
73   unsigned int range; //! Seek range - on both sides of the reference pixel
74   double sample_step; //! Distance between sampled points (in pixels)
75   int ntotal_sample;
76   int points_to_track;
77   //! convolution masks' size in pixels (masks are square), \warning should
78   //! not be public, use setMaskSize() and getMaskSize() instead (kept public
79   //! for compatibility reasons).
80   unsigned int mask_size;
81   //! the number of convolution masks available for tracking ; defines
82   //! resolution. \warning Should not be public, use setMaskNumber() and
83   //! getMaskNumber() instead (kept public for compatibility reasons).
84   unsigned int n_mask;
85   // strip: defines a "security strip" such that Seek_Extremities()
86   // cannot return a new extremity which is too close to the
87   // frame borders which may cause Get_Sampling_Grid to refuse
88   // the that extremity
89   int strip;
90   // int graph ;
91   vpMatrix *mask; //! Array of matrices defining the different masks (one for
92                   //! every angle step).
93 
94 public:
95   vpMe();
96   vpMe(const vpMe &me);
97   virtual ~vpMe();
98 
99   vpMe &operator=(const vpMe &me);
100 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
101   vpMe &operator=(const vpMe &&me);
102 #endif
103 
checkSamplestep(double & a)104   void checkSamplestep(double &a)
105   {
106     if (a < min_samplestep)
107       a = min_samplestep;
108   }
109   /*!
110     Return the angle step.
111 
112     \return Value of anglestep.
113   */
getAngleStep()114   inline unsigned int getAngleStep() const { return anglestep; }
115   /*!
116     Get the matrix of the mask.
117 
118     \return the value of mask.
119   */
getMask()120   inline vpMatrix *getMask() const { return mask; }
121   /*!
122     Return the number of mask  applied to determine the object contour. The
123     number of mask determines the precision of the normal of the edge for
124     every sample. If precision is 2deg, then there are 360/2 = 180 masks.
125 
126     \return the current number of mask.
127   */
getMaskNumber()128   inline unsigned int getMaskNumber() const { return n_mask; }
129   /*!
130     Return the mask sign.
131 
132     \return Value of mask_sign.
133   */
getMaskSign()134   inline int getMaskSign() const { return mask_sign; }
135   /*!
136     Return the actual mask size (in pixel) used to compute the image gradient
137     and determine the object contour. The mask size defines the size of the
138     convolution mask used to detect an edge.
139 
140     \return the current mask size.
141   */
getMaskSize()142   inline unsigned int getMaskSize() const { return mask_size; }
143   /*!
144     Get the minimum allowed sample step. Useful to specify a lower bound when
145     the sample step is changed.
146 
147     \return Value of min_samplestep.
148   */
getMinSampleStep()149   inline double getMinSampleStep() const { return min_samplestep; }
150   /*!
151     Get the minimum image contrast allowed to detect a contour.
152 
153     \return Value of mu1.
154   */
getMu1()155   inline double getMu1() const { return mu1; }
156   /*!
157     Get the maximum image contrast allowed to detect a contour.
158 
159     \return Value of mu2.
160   */
getMu2()161   inline double getMu2() const { return mu2; }
162   /*!
163     Get how many discretizied points are used to track the feature.
164 
165     \return Value of ntotal_sample.
166   */
getNbTotalSample()167   inline int getNbTotalSample() const { return ntotal_sample; }
168   /*!
169     Return the number of points to track.
170 
171     \return Value of points_to_track.
172   */
getPointsToTrack()173   inline int getPointsToTrack() const { return points_to_track; }
174   /*!
175     Return the seek range on both sides of the reference pixel.
176 
177     \return Value of range.
178   */
getRange()179   inline unsigned int getRange() const { return range; }
180   /*!
181     Get the number of pixels that are ignored around the image borders.
182 
183     \return the value of strip.
184   */
getStrip()185   inline int getStrip() const { return strip; }
186 
187   /*!
188     Return the likelihood threshold used to determined if the moving edge is
189     valid or not.
190 
191     \return Value of threshold.
192   */
getThreshold()193   inline double getThreshold() const { return threshold; }
194 
195   void initMask(); // convolution masks - offset computation
196   void print();
197 
198   /*!
199     Set the angle step.
200 
201     \param a : new angle step.
202   */
setAngleStep(const unsigned int & a)203   void setAngleStep(const unsigned int &a) { anglestep = a; }
204   /*!
205     Set the number of mask applied to determine the object contour. The number
206     of mask determines the precision of the normal of the edge for every
207     sample. If precision is 2deg, then there are 360/2 = 180 masks.
208 
209     \param a : the number of mask.
210   */
211   void setMaskNumber(const unsigned int &a);
212 
213   /*!
214     Set the mask sign.
215 
216     \param a : new mask sign.
217   */
setMaskSign(const int & a)218   void setMaskSign(const int &a) { mask_sign = a; }
219 
220   /*!
221     Set the mask size (in pixel) used to compute the image gradient and
222     determine the object contour. The mask size defines the size of the
223     convolution mask used to detect an edge.
224 
225     \param a : new mask size.
226   */
227   void setMaskSize(const unsigned int &a);
228   /*!
229     Set the minimum allowed sample step. Useful to specify a lower bound when
230     the sample step is changed.
231 
232     \param min : new minimum sample step.
233   */
setMinSampleStep(const double & min)234   void setMinSampleStep(const double &min) { min_samplestep = min; }
235 
236   /*!
237     Set the minimum image contrast allowed to detect a contour.
238 
239     \param mu_1 : new mu1.
240   */
setMu1(const double & mu_1)241   void setMu1(const double &mu_1) { this->mu1 = mu_1; }
242 
243   /*!
244     Set the maximum image contrast allowed to detect a contour.
245 
246     \param mu_2 : new mu2.
247   */
setMu2(const double & mu_2)248   void setMu2(const double &mu_2) { this->mu2 = mu_2; }
249 
250   /*!
251     Set how many discretizied points are used to track the feature.
252 
253     \param nb : new total number of sample.
254   */
setNbTotalSample(const int & nb)255   void setNbTotalSample(const int &nb) { ntotal_sample = nb; }
256 
257   /*!
258     Set the number of points to track.
259 
260     \param n : new number of points to track.
261 
262     \warning This method is useful only for the vpMeNurbsTracker.
263   */
setPointsToTrack(const int & n)264   void setPointsToTrack(const int &n) { points_to_track = n; }
265 
266   /*!
267     Set the seek range on both sides of the reference pixel.
268 
269     \param r : new range.
270   */
setRange(const unsigned int & r)271   void setRange(const unsigned int &r) { range = r; }
272 
273   /*!
274     Set the minimum distance in pixel between two discretized points.
275 
276     \param s : new sample_step.
277   */
setSampleStep(const double & s)278   void setSampleStep(const double &s) { sample_step = s; }
279 
280   /*!
281     Get the minimum distance in pixel between two discretized points.
282 
283     \return Value of sample_step.
284   */
getSampleStep()285   inline double getSampleStep() const { return sample_step; }
286 
287   /*!
288     Set the number of pixels that are ignored around the image borders.
289 
290     \param a : new strip.
291   */
setStrip(const int & a)292   void setStrip(const int &a) { strip = a; }
293 
294   /*!
295     Set the likelihood threshold used to determined if the moving edge is
296     valid or not.
297 
298     \param t : new threshold.
299   */
setThreshold(const double & t)300   void setThreshold(const double &t) { threshold = t; }
301 };
302 
303 #endif
304