Visual Servoing Platform  version 3.2.0
tutorial-blob-auto-tracker.cpp
#include <visp3/blob/vpDot2.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageIo.h>
int main()
{
try {
bool learn = false;
vpImage<unsigned char> I; // Create a gray level image container
vpImageIo::read(I, "./target.pgm");
#if defined(VISP_HAVE_X11)
vpDisplayX d(I, 0, 0, "Camera view");
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(I, 0, 0, "Camera view");
#elif defined(VISP_HAVE_OPENCV)
vpDisplayOpenCV d(I, 0, 0, "Camera view");
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
vpDot2 blob;
if (learn) {
// Learn the characteristics of the blob to auto detect
blob.setGraphics(true);
blob.initTracking(I);
blob.track(I);
std::cout << "Blob characteristics: " << std::endl;
std::cout << " width : " << blob.getWidth() << std::endl;
std::cout << " height: " << blob.getHeight() << std::endl;
#if VISP_VERSION_INT > VP_VERSION_INT(2, 7, 0)
std::cout << " area: " << blob.getArea() << std::endl;
#endif
std::cout << " gray level min: " << blob.getGrayLevelMin() << std::endl;
std::cout << " gray level max: " << blob.getGrayLevelMax() << std::endl;
std::cout << " grayLevelPrecision: " << blob.getGrayLevelPrecision() << std::endl;
std::cout << " sizePrecision: " << blob.getSizePrecision() << std::endl;
std::cout << " ellipsoidShapePrecision: " << blob.getEllipsoidShapePrecision() << std::endl;
}
else {
// Set blob characteristics for the auto detection
blob.setWidth(50);
blob.setHeight(50);
#if VISP_VERSION_INT > VP_VERSION_INT(2, 7, 0)
blob.setArea(1700);
#endif
blob.setGrayLevelMin(0);
blob.setGrayLevelMax(30);
blob.setSizePrecision(0.65);
}
std::list<vpDot2> blob_list;
blob.searchDotsInArea(I, 0, 0, I.getWidth(), I.getHeight(), blob_list);
if (learn) {
// The blob that is tracked by initTracking() is not in the list of auto
// detected blobs We add it:
blob_list.push_back(blob);
}
std::cout << "Number of auto detected blob: " << blob_list.size() << std::endl;
std::cout << "A click to exit..." << std::endl;
while (1) {
for (std::list<vpDot2>::iterator it = blob_list.begin(); it != blob_list.end(); ++it) {
(*it).setGraphics(true);
(*it).setGraphicsThickness(3);
(*it).track(I);
}
if (vpDisplay::getClick(I, false))
break;
}
} catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
}
}
vpDisplayX
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:149
vpDot2::track
void track(const vpImage< unsigned char > &I)
Definition: vpDot2.cpp:435
vpDot2::setGraphicsThickness
void setGraphicsThickness(unsigned int t)
Definition: vpDot2.h:300
vpImageIo::read
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:206
vpDot2::getHeight
double getHeight() const
Definition: vpDot2.cpp:616
vpDot2::searchDotsInArea
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:965
vpDisplayGDI
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
vpDot2
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
vpDot2::getSizePrecision
double getSizePrecision() const
Definition: vpDot2.cpp:637
vpDot2::getArea
double getArea() const
Definition: vpDot2.cpp:623
vpDisplayOpenCV
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Definition: vpDisplayOpenCV.h:141
vpDisplay::display
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay_uchar.cpp:676
vpDot2::setSizePrecision
void setSizePrecision(const double &sizePrecision)
Definition: vpDot2.cpp:749
vpImage::getHeight
unsigned int getHeight() const
Definition: vpImage.h:177
vpDot2::setHeight
void setHeight(const double &height)
Definition: vpDot2.cpp:690
vpDot2::getWidth
double getWidth() const
Definition: vpDot2.cpp:609
vpDot2::setGrayLevelPrecision
void setGrayLevelPrecision(const double &grayLevelPrecision)
Definition: vpDot2.cpp:721
vpDot2::initTracking
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition: vpDot2.cpp:250
vpDot2::getEllipsoidShapePrecision
double getEllipsoidShapePrecision() const
Definition: vpDot2.cpp:646
vpDot2::getGrayLevelMin
unsigned int getGrayLevelMin() const
Definition: vpDot2.h:200
vpDot2::setGraphics
void setGraphics(const bool activate)
Definition: vpDot2.h:293
vpDot2::setArea
void setArea(const double &area)
Definition: vpDot2.cpp:702
vpDot2::setGrayLevelMax
void setGrayLevelMax(const unsigned int &max)
Definition: vpDot2.h:330
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay_uchar.cpp:652
vpDot2::setGrayLevelMin
void setGrayLevelMin(const unsigned int &min)
Definition: vpDot2.h:313
vpImage< unsigned char >
vpDot2::setEllipsoidShapePrecision
void setEllipsoidShapePrecision(const double &ellipsoidShapePrecision)
Definition: vpDot2.cpp:792
vpDot2::getGrayLevelPrecision
double getGrayLevelPrecision() const
Definition: vpDot2.cpp:630
vpDisplay::getClick
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Definition: vpDisplay_uchar.cpp:701
vpDot2::getGrayLevelMax
unsigned int getGrayLevelMax() const
Definition: vpDot2.h:206
vpDot2::setWidth
void setWidth(const double &width)
Definition: vpDot2.cpp:678
vpException
error that can be emited by ViSP classes.
Definition: vpException.h:70
vpImage::getWidth
unsigned int getWidth() const
Definition: vpImage.h:238