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 vpMeSite.h 43 \brief Moving edges 44 */ 45 46 #ifndef vpMeSite_H 47 #define vpMeSite_H 48 49 #include <visp3/core/vpDisplay.h> 50 #include <visp3/core/vpImage.h> 51 #include <visp3/core/vpMatrix.h> 52 #include <visp3/me/vpMe.h> 53 54 /*! 55 \class vpMeSite 56 \ingroup module_me 57 58 \brief Performs search in a given direction(normal) for a given 59 distance(pixels) for a given 'site'. Gives the most likely site 60 given the probablility from an ME mask 61 62 - Bug fix: rewrote application of masks to use the temporal 63 information instead of applying both temporal masks to the same 64 image. ie: spatial -> spatio/temporal 65 66 - Added new tracking function to choose the most similar edge 67 amongst all edges found. 68 69 - sample step. 70 */ 71 class VISP_EXPORT vpMeSite 72 { 73 public: 74 typedef enum { NONE, RANGE, RESULT, RANGE_RESULT } vpMeSiteDisplayType; 75 76 /// Moving-edge site state 77 typedef enum { 78 NO_SUPPRESSION = 0, ///< Point used by the tracker. 79 CONSTRAST = 1, ///< Point removed due to a contrast problem. 80 THRESHOLD = 2, ///< Point removed due to a threshold problem. 81 M_ESTIMATOR = 3, ///< Point removed during virtual visual-servoing because considered as an outlier. 82 TOO_NEAR = 4, ///< Point removed because too near image borders. 83 UNKNOW = 5 ///< Reserved. 84 } vpMeSiteState; 85 86 public: 87 int i, j; 88 int i_1, j_1; 89 double ifloat, jfloat; 90 unsigned char v; 91 int mask_sign; 92 // Angle of tangent at site 93 double alpha; 94 // Convolution of Site in previous image 95 double convlt; 96 // Convolution of Site in previous image 97 double normGradient; 98 // Uncertainty of point given as a probability between 0 and 1 99 double weight; 100 101 private: 102 vpMeSiteDisplayType selectDisplay; 103 vpMeSiteState state; 104 105 public: 106 void init(); 107 void init(double ip, double jp, double alphap); 108 void init(double ip, double jp, double alphap, double convltp); 109 void init(double ip, double jp, double alphap, double convltp, int sign); 110 111 vpMeSite(); 112 vpMeSite(double ip, double jp); 113 vpMeSite(const vpMeSite &mesite); ~vpMeSite()114 virtual ~vpMeSite(){}; 115 116 void display(const vpImage<unsigned char> &I); 117 void display(const vpImage<vpRGBa> &I); 118 119 double convolution(const vpImage<unsigned char> &ima, const vpMe *me); 120 121 vpMeSite *getQueryList(const vpImage<unsigned char> &I, const int range); 122 123 void track(const vpImage<unsigned char> &im, const vpMe *me, bool test_contraste = true); 124 125 /*! 126 Set the angle of tangent at site 127 128 \param a : new value of alpha 129 */ setAlpha(const double & a)130 void setAlpha(const double &a) { alpha = a; } 131 132 /*! 133 Get the angle of tangent at site 134 135 \return value of alpha 136 */ getAlpha()137 inline double getAlpha() const { return alpha; } 138 setDisplay(vpMeSiteDisplayType select)139 void setDisplay(vpMeSiteDisplayType select) { selectDisplay = select; } 140 141 /*! 142 Get the i coordinate (integer) 143 144 \return value of i 145 */ get_i()146 inline int get_i() const { return i; } 147 148 /*! 149 Get the j coordinate (f) 150 151 \return value of j 152 */ get_j()153 inline int get_j() const { return j; } 154 155 /*! 156 Get the i coordinate (double) 157 158 \return value of i 159 */ get_ifloat()160 inline double get_ifloat() const { return ifloat; } 161 162 /*! 163 Get the j coordinate (double) 164 165 \return value of j 166 */ get_jfloat()167 inline double get_jfloat() const { return jfloat; } 168 169 /*! 170 Set the state of the site 171 172 \param flag : flag corresponding to vpMeSiteState 173 174 \sa vpMeSiteState 175 */ setState(const vpMeSiteState & flag)176 void setState(const vpMeSiteState &flag) 177 { 178 state = flag; 179 180 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS 181 suppress = (int)flag; 182 #endif 183 } 184 185 /*! 186 Get the state of the site 187 188 \return flag corresponding to vpMeSiteState 189 */ getState()190 inline vpMeSiteState getState() const { return state; } 191 192 /*! 193 Set the weight of the site 194 195 \param w : new value of weight 196 */ setWeight(const double & w)197 void setWeight(const double &w) { weight = w; } 198 199 /*! 200 Get the weight of the site 201 202 \return value of weight 203 */ getWeight()204 inline double getWeight() const { return weight; } 205 206 // Operators 207 vpMeSite &operator=(const vpMeSite &m); 208 int operator!=(const vpMeSite &m); 209 210 friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpMeSite &vpMeS); 211 212 // Static functions 213 /*! 214 Compute the distance \f$ |S1 - S2| = \sqrt{(i_1-i_2)^2+(j_1-j_2)^2} \f$ 215 216 \param S1 : First site 217 \param S2 : Second site 218 219 \return the distance between the two sites. 220 */ distance(const vpMeSite & S1,const vpMeSite & S2)221 static double distance(const vpMeSite &S1, const vpMeSite &S2) 222 { 223 return (sqrt(vpMath::sqr(S1.ifloat - S2.ifloat) + vpMath::sqr(S1.jfloat - S2.jfloat))); 224 } 225 226 /*! 227 Compute the distance \f$ |S1 - S2| = (i_1-i_2)^2+(j_1-j_2)^2 \f$ 228 229 \param S1 : First site 230 \param S2 : Second site 231 232 \return the distance between the two sites. 233 */ sqrDistance(const vpMeSite & S1,const vpMeSite & S2)234 static double sqrDistance(const vpMeSite &S1, const vpMeSite &S2) 235 { 236 return (vpMath::sqr(S1.ifloat - S2.ifloat) + vpMath::sqr(S1.jfloat - S2.jfloat)); 237 } 238 239 static void display(const vpImage<unsigned char> &I, const double &i, const double &j, 240 const vpMeSiteState &state = NO_SUPPRESSION); 241 static void display(const vpImage<vpRGBa> &I, const double &i, const double &j, 242 const vpMeSiteState &state = NO_SUPPRESSION); 243 244 // Deprecated 245 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS 246 public: 247 //! Flag to indicate whether point is rejected or not 248 //! 1 = contrast, 2 = threshold, 3 = M-estimator, 0 = nosupp 249 int suppress; 250 251 vp_deprecated void getSign(const vpImage<unsigned char> &I, const int range); 252 #endif 253 }; 254 255 #endif 256