/usr/include/visp/vpDot.h is in libvisp-dev 2.8.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | /****************************************************************************
*
* $Id: vpDot.h 4317 2013-07-17 09:40:17Z fspindle $
*
* This file is part of the ViSP software.
* Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact INRIA about acquiring a ViSP Professional
* Edition License.
*
* See http://www.irisa.fr/lagadic/visp/visp.html for more information.
*
* This software was developed at:
* INRIA Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
* http://www.irisa.fr/lagadic
*
* If you have questions regarding the use of this file, please contact
* INRIA at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*
* Description:
* Track a white dot.
*
* Authors:
* Eric Marchand
* Fabien Spindler
*
*****************************************************************************/
/*!
\file vpDot.h
\brief Track a white dot
*/
#ifndef vpDot_hh
#define vpDot_hh
#include <visp/vpImage.h>
#include <visp/vpDisplay.h>
#include <visp/vpTracker.h>
#include <visp/vpRect.h>
#include <visp/vpImagePoint.h>
#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
# include <visp/vpList.h>
#endif
#include <math.h>
#include <fstream>
#include <list>
#include <vector>
/*!
\class vpDot
\ingroup TrackingImageBasic
\brief This tracker is meant to track a dot (connected pixels with same
gray level) on a vpImage.
The underground algorithm is based on a binarization of the image
and a connex component segmentation to determine the dot
characteristics (location, moments, size...).
The following sample code shows how to grab images from a firewire camera,
track a blob and display the tracking results.
\code
#include <visp/vpConfig.h>
#include <visp/vp1394TwoGrabber.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDot.h>
#include <visp/vpImage.h>
int main()
{
#if defined(VISP_HAVE_DC1394_2)
vpImage<unsigned char> I; // Create a gray level image container
vp1394TwoGrabber g(false); // Create a grabber based on libdc1394-2.x third party lib
g.acquire(I); // Acquire an image
#if defined(VISP_HAVE_X11)
vpDisplayX d(I, 0, 0, "Camera view");
#endif
vpDisplay::display(I);
vpDisplay::flush(I);
vpDot blob;
blob.initTracking(I);
blob.setGraphics(true);
while(1) {
g.acquire(I); // Acquire an image
vpDisplay::display(I);
blob.track(I);
vpDisplay::flush(I);
}
#endif
}
\endcode
\sa vpDot2
*/
class VISP_EXPORT vpDot : public vpTracker
{
public :
/*! \enum vpConnexityType
Type of connexity 4, or 8.
*/
typedef enum {
CONNEXITY_4, /*!< For a given pixel 4 neighbors are considered (left,
right, up, down) */
CONNEXITY_8 /*!< For a given pixel 8 neighbors are considered (left,
right, up, down, and the 4 pixels located on the diagonal) */
} vpConnexityType;
static const unsigned int SPIRAL_SEARCH_SIZE; /*!< Spiral size for the dot
search. */
double m00; /*!< Considering the general distribution moments for \f$ N \f$
points defined by the relation \f$ m_{ij} = \sum_{h=0}^{N}
u_h^i v_h^j \f$, \f$ m_{00} \f$ is a zero order moment obtained
with \f$i = j = 0 \f$.
\sa setComputeMoments()
*/
double m01; /*!< Considering the general distribution moments for \f$ N \f$
points defined by the relation \f$ m_{ij} = \sum_{h=0}^{N}
u_h^i v_h^j \f$, \f$ m_{01} \f$ is a first order moment
obtained with \f$i = 0 \f$ and \f$ j = 1 \f$.
\sa setComputeMoments()
*/
double m10; /*!< Considering the general distribution moments for \f$ N \f$
points defined by the relation \f$ m_{ij} = \sum_{h=0}^{N}
u_h^i v_h^j \f$, \f$ m_{10} \f$ is a first order moment
obtained with \f$i = 1 \f$ and \f$ j = 0 \f$.
\sa setComputeMoments()
*/
double m11; /*!< Considering the general distribution moments for \f$ N \f$
points defined by the relation \f$ m_{ij} = \sum_{h=0}^{N}
u_h^i v_h^j \f$, \f$ m_{11} \f$ is a first order moment
obtained with \f$i = 1 \f$ and \f$ j = 1 \f$.
\warning This moment is not computed for the moment.
\sa setComputeMoments()
*/
double m20; /*!< Considering the general distribution moments for \f$ N \f$
points defined by the relation \f$ m_{ij} = \sum_{h=0}^{N}
u_h^i v_h^j \f$, \f$ m_{20} \f$ is a second order moment
obtained with \f$i = 2 \f$ and \f$ j = 0 \f$.
\warning This moment is not computed for the moment.
\sa setComputeMoments()
*/
double m02; /*!< Considering the general distribution moments for \f$ N \f$
points defined by the relation \f$ m_{ij} = \sum_{h=0}^{N}
u_h^i v_h^j \f$, \f$ m_{02} \f$ is a second order moment
obtained with \f$i = 0 \f$ and \f$ j = 2 \f$.
\warning This moment is not computed for the moment.
\sa setComputeMoments()
*/
double mu11;/*!< \f$ \mu_{11} \f$ is a second order central moments defined by:
\f$ \mu_{11} = m_{11} - \frac{m_{10}}{m_{00}}m_{01} \f$
\sa setComputeMoments()
*/
double mu20;/*!< \f$ \mu_{20} \f$ is a second order central moments defined by:
\f$ \mu_{20} = m_{20} - \frac{m_{10}}{m_{00}}m_{10} \f$
\sa setComputeMoments()
*/
double mu02;/*!< \f$ \mu_{02} \f$ is a second order central moments defined by:
\f$ \mu_{02} = m_{02} - \frac{m_{01}}{m_{00}}m_{01} \f$
\sa setComputeMoments()
*/
vpDot() ;
vpDot(const vpImagePoint &ip) ;
vpDot(const vpDot& d) ;
virtual ~vpDot() ;
void display(const vpImage<unsigned char>& I, vpColor color = vpColor::red,
unsigned int thickness=1);
/*!
Return the dot bounding box.
\sa getWidth(), getHeight()
*/
inline vpRect getBBox() {
vpRect bbox;
bbox.setRect(this->u_min,
this->v_min,
this->u_max - this->u_min + 1,
this->v_max - this->v_min + 1);
return (bbox);
};
/*!
Return the location of the dot center of gravity.
\return The coordinates of the center of gravity.
*/
inline vpImagePoint getCog() const {
return cog;
}
/*!
Return the list of all the image points on the border of the dot.
\warning Doesn't return the image points inside the dot anymore. To get those points see getConnexities().
*/
inline std::list<vpImagePoint> getEdges() {
return this->ip_edges_list;
};
/*!
Return the list of all the image points inside the dot.
\return The list of all the images points in the dot.
This list is updated after a call to track().
*/
inline std::list<vpImagePoint> getConnexities() {
return this->ip_connexities_list;
};
inline double getGamma() {return this->gamma;};
/*!
Return the precision of the gray level of the dot. It is a double
precision float witch value is in ]0,1]. 1 means full precision, whereas
values close to 0 show a very bad precision.
*/
double getGrayLevelPrecision() const {return grayLevelPrecision;}
double getMaxDotSize(){
return this->maxDotSizePercentage;
}
/*!
Return the mean gray level value of the dot.
*/
double getMeanGrayLevel() {
return (this->mean_gray_level);
};
/*!
Return the width of the dot.
\sa getHeight()
*/
inline unsigned int getWidth() const {
return (this->u_max - this->u_min + 1);
};
/*!
Return the width of the dot.
\sa getHeight()
*/
inline unsigned int getHeight() const {
return (this->v_max - this->v_min + 1);
};
void initTracking(const vpImage<unsigned char> &I) ;
void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip);
void initTracking(const vpImage<unsigned char> &I, const vpImagePoint &ip,
unsigned int gray_level_min, unsigned int gray_level_max);
vpDot& operator =(const vpDot& d) ;
bool operator ==(const vpDot& d);
bool operator !=(const vpDot& d);
/*!
Writes the dot center of gravity coordinates in the frame (i,j) (For more details
about the orientation of the frame see the vpImagePoint documentation) to the stream \e os,
and returns a reference to the stream.
*/
friend VISP_EXPORT std::ostream& operator<< (std::ostream& os, vpDot& d) {
return (os << "(" << d.getCog() << ")" ) ;
} ;
void print(std::ostream& os) { os << *this << std::endl ; }
/*!
Initialize the dot coordinates with \e cog.
*/
inline void setCog(const vpImagePoint &cog) {
this->cog = cog;
}
/*!
Activates the dot's moments computation.
\param activate true, if you want to compute the moments. If false, moments
are not computed.
Computed moment are vpDot::m00, vpDot::m10, vpDot::m01, vpDot::m11,
vpDot::m20, vpDot::m02.
The coordinates of the region's centroid (u, v) can be computed from the
moments by \f$u=\frac{m10}{m00}\f$ and \f$v=\frac{m01}{m00}\f$.
*/
void setComputeMoments(const bool activate) { compute_moment = activate; }
/*!
Set the type of connexity: 4 or 8.
*/
void setConnexity(vpConnexityType connexityType) {this->connexityType = connexityType; };
void setMaxDotSize(double percentage) ;
void setGrayLevelMin( const unsigned int &gray_level_min ) {
this->gray_level_min = gray_level_min;
};
void setGrayLevelMax( const unsigned int &gray_level_max ) {
this->gray_level_max = gray_level_max;
};
void setGrayLevelPrecision( const double & grayLevelPrecision );
/*!
Activates the display of all the pixels of the dot during the tracking.
The default thickness of the overlayed drawings can be modified using
setGraphicsThickness().
\warning To effectively display the dot graphics a call to
vpDisplay::flush() is needed.
\param activate true to activate the display of dot pixels, false to turn
off the display.
\sa setGraphicsThickness()
*/
void setGraphics(const bool activate) { graphics = activate ; }
/*!
Modify the default thickness that is set to 1 of the drawings in overlay when setGraphics() is enabled.
\sa setGraphics()
*/
void setGraphicsThickness(unsigned int thickness) {this->thickness = thickness;};
void track(const vpImage<unsigned char> & I) ;
void track(const vpImage<unsigned char> & I, vpImagePoint &ip) ;
private:
//! internal use only
std::list<vpImagePoint> ip_connexities_list;
//! List of border points
std::list<vpImagePoint> ip_edges_list;
/*! Type of connexity
\warning In previous version this variable was called connexity
*/
vpConnexityType connexityType;
//! coordinates of the point center of gravity
vpImagePoint cog;
// Bounding box
unsigned int u_min, u_max, v_min, v_max;
// Flag used to allow display
bool graphics ;
unsigned int thickness; // Graphics thickness
double maxDotSizePercentage;
unsigned char gray_level_out;
double mean_gray_level; // Mean gray level of the dot
unsigned int gray_level_min; // left threshold for binarisation
unsigned int gray_level_max; // right threshold for binarisation
double grayLevelPrecision; //precision of the gray level of the dot.
//It is a double precision float witch value is in ]0,1].
//1 means full precision, whereas values close to 0 show a very bad precision
double gamma ;
//! flag : true moment are computed
bool compute_moment ;
double nbMaxPoint;
void init() ;
void setGrayLevelOut();
bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
double &mean_value, double &u_cog, double &v_cog, double &n);
bool connexe(const vpImage<unsigned char>& I,unsigned int u,unsigned int v,
double &mean_value, double &u_cog, double &v_cog, double &n,std::vector<bool> &checkTab);
void COG(const vpImage<unsigned char> &I,double& u, double& v) ;
//Static Functions
public:
static void display(const vpImage<unsigned char>& I,const vpImagePoint &cog,
const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
unsigned int thickness=1);
static void display(const vpImage<vpRGBa>& I,const vpImagePoint &cog,
const std::list<vpImagePoint> &edges_list, vpColor color = vpColor::red,
unsigned int thickness=1);
#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
/*!
@name Deprecated functions
*/
/*!
\deprecated This method is deprecated since the naming is not representative regarding to its functionality. \n
Previously it returned all the points inside the dot. To get the equivalent, use getConnexities(). \n \n
If you rather want to get the points on the dot border use getEdges().
\param edges_list : The list of all the images points on the dot
border. This list is update after a call to track().
*/
vp_deprecated void getEdges(std::list<vpImagePoint> &edges_list) {
edges_list = this->ip_edges_list;
};
/*!
\deprecated This method is deprecated. You should use
getEdges(std::list<vpImagePoint> &) instead.\n \n
Return the list of all the image points on the dot
border.
\param connexities_list : The list of all the images points on the dot
border. This list is update after a call to track().
*/
vp_deprecated void getConnexities(vpList<vpImagePoint> &connexities_list) {
// convert a vpList in a std::list
connexities_list.kill();
std::list<vpImagePoint>::const_iterator it;
for (it = ip_connexities_list.begin(); it != ip_connexities_list.end(); ++it) {
connexities_list += *it;
}
};
#endif
} ;
#endif
|