54 #include <visp/vpDebug.h>
55 #include <visp/vpConfig.h>
63 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
65 #include <visp/vpImage.h>
66 #include <visp/vpImageIo.h>
67 #include <visp/vpImagePoint.h>
68 #include <visp/vpDisplayX.h>
69 #include <visp/vpDisplayGTK.h>
70 #include <visp/vpDisplayGDI.h>
71 #include <visp/vpDisplayOpenCV.h>
72 #include <visp/vpColor.h>
74 #include <visp/vpMeEllipse.h>
75 #include <visp/vpParseArgv.h>
76 #include <visp/vpIoTools.h>
79 #define GETOPTARGS "cdi:h"
81 void usage(
const char *name,
const char *badparam, std::string ipath);
82 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
93 void usage(
const char *name,
const char *badparam, std::string ipath)
96 Test of ellipse tracking using vpMeEllipse.\n\
99 %s [-i <input image path>] [-c] [-h]\n", name);
103 -i <input image path> %s\n\
104 Set image input path.\n\
105 From this path read images \n\
106 \"ViSP-images/ellipse-1/image.%%04d.pgm\"\n\
107 Setting the VISP_INPUT_IMAGE_PATH environment\n\
108 variable produces the same behaviour than using\n\
112 Disable the mouse click. Useful to automaze the \n\
113 execution of this program without humain intervention.\n\
116 Turn off the display.\n\
123 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
138 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
145 case 'c': click_allowed =
false;
break;
146 case 'd': display =
false;
break;
147 case 'i': ipath = optarg_;
break;
148 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
151 usage(argv[0], optarg_, ipath);
156 if ((c == 1) || (c == -1)) {
158 usage(argv[0], NULL, ipath);
159 std::cerr <<
"ERROR: " << std::endl;
160 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
169 main(
int argc,
const char ** argv)
172 std::string env_ipath;
173 std::string opt_ipath;
176 std::string filename;
177 bool opt_click_allowed =
true;
178 bool opt_display =
true;
184 if (! env_ipath.empty())
188 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display) ==
false) {
193 if (!opt_ipath.empty())
198 if (!opt_ipath.empty() && !env_ipath.empty()) {
199 if (ipath != env_ipath) {
200 std::cout << std::endl
201 <<
"WARNING: " << std::endl;
202 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
203 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
204 <<
" we skip the environment variable." << std::endl;
209 if (opt_ipath.empty() && env_ipath.empty()){
210 usage(argv[0], NULL, ipath);
211 std::cerr << std::endl
212 <<
"ERROR:" << std::endl;
213 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
215 <<
" environment variable to specify the location of the " << std::endl
216 <<
" image path where test images are located." << std::endl << std::endl;
230 unsigned int iter = 1;
231 std::ostringstream s;
232 s.setf(std::ios::right, std::ios::adjustfield);
233 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
243 vpCTRACE <<
"Load: " << filename << std::endl;
253 std::cerr << std::endl
254 <<
"ERROR:" << std::endl;
255 std::cerr <<
" Cannot read " << filename << std::endl;
256 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
257 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
263 #if defined VISP_HAVE_X11
265 #elif defined VISP_HAVE_GTK
267 #elif defined VISP_HAVE_GDI
269 #elif defined VISP_HAVE_OPENCV
275 display.
init(I, 100, 100,
"Display...") ;
295 if (opt_click_allowed)
315 if (opt_display && opt_click_allowed) {
316 std::cout <<
"A click to continue..." << std::endl;
319 std::cout <<
"------------------------------------------------------------"<<std::endl;
322 for (iter = 1 ; iter < 51 ; iter++)
326 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
328 std::cout <<
"Tracking on image: " << filename << std::endl;
343 if (opt_display && opt_click_allowed) {
344 std::cout <<
"A click to exit..." << std::endl;
350 std::cout <<
"Catch an exception: " << e << std::endl;
358 vpERROR_TRACE(
"You do not have X11, GTK, GDI or OpenCV display functionalities...");
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void initTracking(const vpImage< unsigned char > &I)
void setPointsToTrack(const int &n)
Display for windows using GDI (available on any windows 32 platform).
void setSampleStep(const double &s)
Define the X11 console to display images.
error that can be emited by ViSP classes.
Class that tracks an ellipse moving edges.
Contains predetermined masks for sites and holds moving edges tracking parameters.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void set_i(const double ii)
void track(const vpImage< unsigned char > &Im)
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
void display(const vpImage< unsigned char > &I, vpColor col)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void set_j(const double jj)
void setThreshold(const double &t)
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setRange(const unsigned int &r)
static void read(vpImage< unsigned char > &I, const char *filename)
double getSampleStep() const