ViSP  2.8.0
tutorial-blob-auto-tracker.cpp
1 
2 #include <visp/vpDisplayGDI.h>
3 #include <visp/vpDisplayX.h>
4 #include <visp/vpDot2.h>
5 #include <visp/vpImageIo.h>
6 
7 int main()
8 {
9  bool learn = false;
10  vpImage<unsigned char> I; // Create a gray level image container
11 
12  vpImageIo::read(I, "./target.pgm");
13 
14 #if defined(VISP_HAVE_X11)
15  vpDisplayX d(I, 0, 0, "Camera view");
16 #elif defined(VISP_HAVE_GDI)
17  vpDisplayGDI d(I, 0, 0, "Camera view");
18 #else
19  std::cout << "No image viewer is available..." << std::endl;
20 #endif
23 
24  vpDot2 blob;
25  if (learn) {
26  // Learn the characteristics of the blob to auto detect
27  blob.setGraphics(true);
28  blob.setGraphicsThickness(1);
29  blob.initTracking(I);
30  blob.track(I);
31  std::cout << "Blob characteristics: " << std::endl;
32  std::cout << " width : " << blob.getWidth() << std::endl;
33  std::cout << " height: " << blob.getHeight() << std::endl;
34 #if VISP_VERSION_INT > VP_VERSION_INT(2,7,0)
35  std::cout << " area: " << blob.getArea() << std::endl;
36 #endif
37  std::cout << " gray level min: " << blob.getGrayLevelMin() << std::endl;
38  std::cout << " gray level max: " << blob.getGrayLevelMax() << std::endl;
39  std::cout << " grayLevelPrecision: " << blob.getGrayLevelPrecision() << std::endl;
40  std::cout << " sizePrecision: " << blob.getSizePrecision() << std::endl;
41  std::cout << " ellipsoidShapePrecision: " << blob.getEllipsoidShapePrecision() << std::endl;
42  }
43  else {
44  // Set blob characteristics for the auto detection
45  blob.setWidth(50);
46  blob.setHeight(50);
47 #if VISP_VERSION_INT > VP_VERSION_INT(2,7,0)
48  blob.setArea(1700);
49 #endif
50  blob.setGrayLevelMin(0);
51  blob.setGrayLevelMax(30);
52  blob.setGrayLevelPrecision(0.8);
53  blob.setSizePrecision(0.65);
54  blob.setEllipsoidShapePrecision(0.65);
55  }
56 
57  std::list<vpDot2> blob_list;
58  blob.searchDotsInArea(I, 0, 0, I.getWidth(), I.getHeight(), blob_list);
59 
60  if (learn) {
61  // The blob that is tracked by initTracking() is not in the list of auto detected blobs
62  // We add it:
63  blob_list.push_back(blob);
64  }
65  std::cout << "Number of auto detected blob: " << blob_list.size() << std::endl;
66  std::cout << "A click to exit..." << std::endl;
67 
68  while(1) {
70 
71  for(std::list<vpDot2>::iterator it=blob_list.begin(); it != blob_list.end(); ++it) {
72  (*it).setGraphics(true);
73  (*it).setGraphicsThickness(3);
74  (*it).track(I);
75  }
76 
78 
79  if (vpDisplay::getClick(I, false))
80  break;
81 
82  vpTime::wait(40);
83  }
84 }
double getWidth() const
Definition: vpDot2.cpp:627
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:347
void searchDotsInArea(const vpImage< unsigned char > &I, int area_u, int area_v, unsigned int area_w, unsigned int area_h, std::list< vpDot2 > &niceDots)
Definition: vpDot2.cpp:1619
unsigned int getWidth() const
Definition: vpImage.h:159
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:133
double getGrayLevelPrecision() const
Definition: vpDot2.cpp:671
Define the X11 console to display images.
Definition: vpDisplayX.h:152
double getHeight() const
Definition: vpDot2.cpp:637
double getArea() const
Definition: vpDot2.cpp:661
double getEllipsoidShapePrecision() const
Definition: vpDot2.cpp:693
static int wait(double t0, double t)
Definition: vpTime.cpp:149
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:131
void track(const vpImage< unsigned char > &I)
Definition: vpDot2.cpp:444
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1991
double getSizePrecision() const
Definition: vpDot2.cpp:681
void setGrayLevelPrecision(const double &grayLevelPrecision)
Definition: vpDot2.cpp:796
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:203
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:204
void setArea(const double &area)
Definition: vpDot2.cpp:775
void setGraphicsThickness(unsigned int thickness)
Definition: vpDot2.h:318
void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision)
Definition: vpDot2.cpp:871
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:331
void setWidth(const double &width)
Definition: vpDot2.cpp:731
void setSizePrecision(const double &sizePrecision)
Definition: vpDot2.cpp:826
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:245
void setHeight(const double &height)
Definition: vpDot2.cpp:746
unsigned int getHeight() const
Definition: vpImage.h:150
virtual bool getClick(bool blocking=true)=0
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:277
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:212
void setGraphics(const bool activate)
Definition: vpDot2.h:312