54 #include <visp/vpDebug.h>
55 #include <visp/vpConfig.h>
63 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
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/vpColor.h>
73 #include <visp/vpMeEllipse.h>
74 #include <visp/vpParseArgv.h>
75 #include <visp/vpIoTools.h>
78 #define GETOPTARGS "cdi:h"
89 void usage(
const char *name,
const char *badparam, std::string ipath)
92 Test of ellipse tracking using vpMeEllipse.\n\
95 %s [-i <input image path>] [-c] [-h]\n", name);
99 -i <input image path> %s\n\
100 Set image input path.\n\
101 From this path read images \n\
102 \"ViSP-images/ellipse-1/image.%%04d.pgm\"\n\
103 Setting the VISP_INPUT_IMAGE_PATH environment\n\
104 variable produces the same behaviour than using\n\
108 Disable the mouse click. Useful to automaze the \n\
109 execution of this program without humain intervention.\n\
112 Turn off the display.\n\
119 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
134 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
141 case 'c': click_allowed =
false;
break;
142 case 'd': display =
false;
break;
143 case 'i': ipath = optarg;
break;
144 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
147 usage(argv[0], optarg, ipath);
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0], NULL, ipath);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
165 main(
int argc,
const char ** argv)
167 std::string env_ipath;
168 std::string opt_ipath;
171 std::string filename;
172 bool opt_click_allowed =
true;
173 bool opt_display =
true;
176 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
181 if (! env_ipath.empty())
186 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display) ==
false) {
191 if (!opt_ipath.empty())
196 if (!opt_ipath.empty() && !env_ipath.empty()) {
197 if (ipath != env_ipath) {
198 std::cout << std::endl
199 <<
"WARNING: " << std::endl;
200 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
201 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
202 <<
" we skip the environment variable." << std::endl;
207 if (opt_ipath.empty() && env_ipath.empty()){
208 usage(argv[0], NULL, ipath);
209 std::cerr << std::endl
210 <<
"ERROR:" << std::endl;
211 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
213 <<
" environment variable to specify the location of the " << std::endl
214 <<
" image path where test images are located." << std::endl << std::endl;
229 std::ostringstream s;
230 s.setf(std::ios::right, std::ios::adjustfield);
231 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
232 filename = dirname + s.str();
241 vpCTRACE <<
"Load: " << filename << std::endl;
251 std::cerr << std::endl
252 <<
"ERROR:" << std::endl;
253 std::cerr <<
" Cannot read " << filename << std::endl;
254 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
255 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
261 #if defined VISP_HAVE_X11
263 #elif defined VISP_HAVE_GTK
265 #elif defined VISP_HAVE_GDI
272 display.
init(I, 100, 100,
"Display...") ;
298 if (opt_click_allowed)
318 if (opt_display && opt_click_allowed) {
319 std::cout <<
"A click to continue..." << std::endl;
322 std::cout <<
"------------------------------------------------------------"<<std::endl;
325 for (
int iter = 1 ; iter < 51 ; iter++)
329 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
330 filename = dirname + s.str();
331 std::cout <<
"Tracking on image: " << filename << std::endl;
353 if (opt_display && opt_click_allowed) {
354 std::cout <<
"A click to exit..." << std::endl;
362 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
void set_j(const double j)
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.
void set_i(const double i)
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 track(const vpImage< unsigned char > &Im)
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
static void display(const vpImage< unsigned char > &I)
void display(const vpImage< unsigned char > &I, vpColor col)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
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