54 #include <visp/vpDebug.h>
55 #include <visp/vpConfig.h>
62 #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/vpMeLine.h>
75 #include <visp/vpFeatureLine.h>
76 #include <visp/vpFeatureBuilder.h>
78 #include <visp/vpParseArgv.h>
79 #include <visp/vpIoTools.h>
82 #define GETOPTARGS "cdi:h"
93 void usage(
const char *name,
const char *badparam, std::string ipath)
96 Tracking of a line.\n\
99 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
103 -i <input image path> %s\n\
104 Set image input path.\n\
105 From this path read \"ViSP-images/line/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,
139 bool &click_allowed,
bool &display)
146 case 'c': click_allowed =
false;
break;
147 case 'd': display =
false;
break;
148 case 'i': ipath = optarg;
break;
149 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
152 usage(argv[0], optarg, ipath);
157 if ((c == 1) || (c == -1)) {
159 usage(argv[0], NULL, ipath);
160 std::cerr <<
"ERROR: " << std::endl;
161 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
170 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;
181 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
186 if (! env_ipath.empty())
191 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
192 opt_display) ==
false) {
197 if (!opt_ipath.empty())
202 if (!opt_ipath.empty() && !env_ipath.empty()) {
203 if (ipath != env_ipath) {
204 std::cout << std::endl
205 <<
"WARNING: " << std::endl;
206 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
207 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
208 <<
" we skip the environment variable." << std::endl;
213 if (opt_ipath.empty() && env_ipath.empty()){
214 usage(argv[0], NULL, ipath);
215 std::cerr << std::endl
216 <<
"ERROR:" << std::endl;
217 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
219 <<
" environment variable to specify the location of the " << std::endl
220 <<
" image path where test images are located." << std::endl << std::endl;
234 std::ostringstream s;
235 s.setf(std::ios::right, std::ios::adjustfield);
236 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
237 filename = dirname + s.str();
246 vpCTRACE <<
"Load: " << filename << std::endl;
256 std::cerr << std::endl
257 <<
"ERROR:" << std::endl;
258 std::cerr <<
" Cannot read " << filename << std::endl;
259 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
260 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
266 #if defined VISP_HAVE_X11
268 #elif defined VISP_HAVE_GTK
270 #elif defined VISP_HAVE_GDI
277 display.
init(I, 100, 100,
"Display...") ;
305 if (opt_display && opt_click_allowed)
320 if (opt_display && opt_click_allowed) {
321 std::cout <<
"A click to continue..." << std::endl;
324 std::cout <<
"----------------------------------------------------------"<<std::endl;
330 for (
int iter = 1 ; iter < 30 ; iter++)
332 std::cout <<
"----------------------------------------------------------"<<std::endl;
335 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
336 filename = dirname + s.str();
346 std::cout <<
"Tracking on image: " << filename << std::endl;
362 if (opt_click_allowed) {
363 std::cout <<
"A click to continue..." << std::endl;
368 if (opt_display && opt_click_allowed) {
369 std::cout <<
"A click to exit..." << std::endl;
378 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");