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"
84 void usage(
const char *name,
const char *badparam, std::string ipath);
85 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
96 void usage(
const char *name,
const char *badparam, std::string ipath)
99 Tracking of a line.\n\
102 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
106 -i <input image path> %s\n\
107 Set image input path.\n\
108 From this path read \"ViSP-images/line/image.%%04d.pgm\"\n\
110 Setting the VISP_INPUT_IMAGE_PATH environment\n\
111 variable produces the same behaviour than using\n\
115 Disable the mouse click. Useful to automaze the \n\
116 execution of this program without humain intervention.\n\
119 Turn off the display.\n\
126 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
141 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
148 case 'c': click_allowed =
false;
break;
149 case 'd': display =
false;
break;
150 case 'i': ipath = optarg_;
break;
151 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
154 usage(argv[0], optarg_, ipath);
159 if ((c == 1) || (c == -1)) {
161 usage(argv[0], NULL, ipath);
162 std::cerr <<
"ERROR: " << std::endl;
163 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
172 main(
int argc,
const char ** argv)
175 std::string env_ipath;
176 std::string opt_ipath;
179 std::string filename;
180 bool opt_click_allowed =
true;
181 bool opt_display =
true;
184 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
189 if (! env_ipath.empty())
194 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
195 opt_display) ==
false) {
200 if (!opt_ipath.empty())
205 if (!opt_ipath.empty() && !env_ipath.empty()) {
206 if (ipath != env_ipath) {
207 std::cout << std::endl
208 <<
"WARNING: " << std::endl;
209 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
210 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
211 <<
" we skip the environment variable." << std::endl;
216 if (opt_ipath.empty() && env_ipath.empty()){
217 usage(argv[0], NULL, ipath);
218 std::cerr << std::endl
219 <<
"ERROR:" << std::endl;
220 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
222 <<
" environment variable to specify the location of the " << std::endl
223 <<
" image path where test images are located." << std::endl << std::endl;
236 unsigned int iter = 1;
237 std::ostringstream s;
238 s.setf(std::ios::right, std::ios::adjustfield);
239 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
240 filename = dirname + s.str();
249 vpCTRACE <<
"Load: " << filename << std::endl;
259 std::cerr << std::endl
260 <<
"ERROR:" << std::endl;
261 std::cerr <<
" Cannot read " << filename << std::endl;
262 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
263 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
269 #if defined VISP_HAVE_X11
271 #elif defined VISP_HAVE_GTK
273 #elif defined VISP_HAVE_GDI
279 display.
init(I, 100, 100,
"Display...") ;
300 if (opt_display && opt_click_allowed)
315 if (opt_display && opt_click_allowed) {
316 std::cout <<
"A click to continue..." << std::endl;
319 std::cout <<
"----------------------------------------------------------"<<std::endl;
325 for (iter = 1 ; iter < 30 ; iter++)
327 std::cout <<
"----------------------------------------------------------"<<std::endl;
330 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
331 filename = dirname + s.str();
339 std::cout <<
"Tracking on image: " << filename << std::endl;
349 if (opt_click_allowed) {
350 std::cout <<
"A click to continue..." << std::endl;
355 if (opt_display && opt_click_allowed) {
356 std::cout <<
"A click to exit..." << std::endl;
362 std::cout <<
"Catch an exception: " << e << std::endl;
371 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
void setPointsToTrack(const int &n)
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
error that can be emited by ViSP classes.
void track(const vpImage< unsigned char > &Im)
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 display(const vpImage< unsigned char > &I, vpColor col)
void set_i(const double ii)
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
static void display(const vpImage< unsigned char > &I)
Class that tracks in an image a line moving edges.
Generic class defining intrinsic camera parameters.
Class that defines a 2D line visual feature which is composed by two parameters that are and ...
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
void initTracking(const vpImage< unsigned char > &I)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void set_j(const double jj)
static double deg(double rad)
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 ...
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setRange(const unsigned int &r)
static void read(vpImage< unsigned char > &I, const char *filename)