ViSP  2.9.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  try {
10  bool learn = false;
11  vpImage<unsigned char> I; // Create a gray level image container
12 
13  vpImageIo::read(I, "./target.pgm");
14 
15 #if defined(VISP_HAVE_X11)
16  vpDisplayX d(I, 0, 0, "Camera view");
17 #elif defined(VISP_HAVE_GDI)
18  vpDisplayGDI d(I, 0, 0, "Camera view");
19 #else
20  std::cout << "No image viewer is available..." << std::endl;
21 #endif
24 
25  vpDot2 blob;
26  if (learn) {
27  // Learn the characteristics of the blob to auto detect
28  blob.setGraphics(true);
29  blob.setGraphicsThickness(1);
30  blob.initTracking(I);
31  blob.track(I);
32  std::cout << "Blob characteristics: " << std::endl;
33  std::cout << " width : " << blob.getWidth() << std::endl;
34  std::cout << " height: " << blob.getHeight() << std::endl;
35 #if VISP_VERSION_INT > VP_VERSION_INT(2,7,0)
36  std::cout << " area: " << blob.getArea() << std::endl;
37 #endif
38  std::cout << " gray level min: " << blob.getGrayLevelMin() << std::endl;
39  std::cout << " gray level max: " << blob.getGrayLevelMax() << std::endl;
40  std::cout << " grayLevelPrecision: " << blob.getGrayLevelPrecision() << std::endl;
41  std::cout << " sizePrecision: " << blob.getSizePrecision() << std::endl;
42  std::cout << " ellipsoidShapePrecision: " << blob.getEllipsoidShapePrecision() << std::endl;
43  }
44  else {
45  // Set blob characteristics for the auto detection
46  blob.setWidth(50);
47  blob.setHeight(50);
48 #if VISP_VERSION_INT > VP_VERSION_INT(2,7,0)
49  blob.setArea(1700);
50 #endif
51  blob.setGrayLevelMin(0);
52  blob.setGrayLevelMax(30);
53  blob.setGrayLevelPrecision(0.8);
54  blob.setSizePrecision(0.65);
55  blob.setEllipsoidShapePrecision(0.65);
56  }
57 
58  std::list<vpDot2> blob_list;
59  blob.searchDotsInArea(I, 0, 0, I.getWidth(), I.getHeight(), blob_list);
60 
61  if (learn) {
62  // The blob that is tracked by initTracking() is not in the list of auto detected blobs
63  // We add it:
64  blob_list.push_back(blob);
65  }
66  std::cout << "Number of auto detected blob: " << blob_list.size() << std::endl;
67  std::cout << "A click to exit..." << std::endl;
68 
69  while(1) {
71 
72  for(std::list<vpDot2>::iterator it=blob_list.begin(); it != blob_list.end(); ++it) {
73  (*it).setGraphics(true);
74  (*it).setGraphicsThickness(3);
75  (*it).track(I);
76  }
77 
79 
80  if (vpDisplay::getClick(I, false))
81  break;
82 
83  vpTime::wait(40);
84  }
85  }
86  catch(vpException e) {
87  std::cout << "Catch an exception: " << e << std::endl;
88  }
89 }
double getWidth() const
Definition: vpDot2.cpp:648
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:1045
unsigned int getWidth() const
Definition: vpImage.h:159
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
double getGrayLevelPrecision() const
Definition: vpDot2.cpp:678
Define the X11 console to display images.
Definition: vpDisplayX.h:152
error that can be emited by ViSP classes.
Definition: vpException.h:76
double getHeight() const
Definition: vpDot2.cpp:658
double getArea() const
Definition: vpDot2.cpp:668
double getEllipsoidShapePrecision() const
Definition: vpDot2.cpp:700
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:127
void track(const vpImage< unsigned char > &I)
Definition: vpDot2.cpp:465
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1994
double getSizePrecision() const
Definition: vpDot2.cpp:688
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:318
void setGrayLevelPrecision(const double &grayLevelPrecision)
Definition: vpDot2.cpp:788
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:212
void setArea(const double &area)
Definition: vpDot2.cpp:767
void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision)
Definition: vpDot2.cpp:863
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:331
void setWidth(const double &width)
Definition: vpDot2.cpp:738
void setSizePrecision(const double &sizePrecision)
Definition: vpDot2.cpp:818
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:266
void setHeight(const double &height)
Definition: vpDot2.cpp:753
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:278
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:220
void setGraphics(const bool activate)
Definition: vpDot2.h:312