54 #include <visp/vpDebug.h>
55 #include <visp/vpConfig.h>
62 #if (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
64 #include <visp/vpImage.h>
65 #include <visp/vpImageIo.h>
66 #include <visp/vpImagePoint.h>
67 #include <visp/vpDisplayX.h>
68 #include <visp/vpDisplayGTK.h>
69 #include <visp/vpDisplayGDI.h>
70 #include <visp/vpDisplayOpenCV.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;
187 if (! env_ipath.empty())
192 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
193 opt_display) ==
false) {
198 if (!opt_ipath.empty())
203 if (!opt_ipath.empty() && !env_ipath.empty()) {
204 if (ipath != env_ipath) {
205 std::cout << std::endl
206 <<
"WARNING: " << std::endl;
207 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
208 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
209 <<
" we skip the environment variable." << std::endl;
214 if (opt_ipath.empty() && env_ipath.empty()){
215 usage(argv[0], NULL, ipath);
216 std::cerr << std::endl
217 <<
"ERROR:" << std::endl;
218 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
220 <<
" environment variable to specify the location of the " << std::endl
221 <<
" image path where test images are located." << std::endl << std::endl;
234 unsigned int iter = 1;
235 std::ostringstream s;
236 s.setf(std::ios::right, std::ios::adjustfield);
237 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
247 vpCTRACE <<
"Load: " << filename << std::endl;
257 std::cerr << std::endl
258 <<
"ERROR:" << std::endl;
259 std::cerr <<
" Cannot read " << filename << std::endl;
260 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
261 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
267 #if defined VISP_HAVE_X11
269 #elif defined VISP_HAVE_GTK
271 #elif defined VISP_HAVE_GDI
273 #elif defined VISP_HAVE_OPENCV
279 display.
init(I, 100, 100,
"Display...") ;
299 if (opt_display && opt_click_allowed)
314 if (opt_display && opt_click_allowed) {
315 std::cout <<
"A click to continue..." << std::endl;
318 std::cout <<
"----------------------------------------------------------"<<std::endl;
324 for (iter = 1 ; iter < 30 ; iter++)
326 std::cout <<
"----------------------------------------------------------"<<std::endl;
329 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
338 std::cout <<
"Tracking on image: " << filename << std::endl;
348 if (opt_click_allowed) {
349 std::cout <<
"A click to continue..." << std::endl;
354 if (opt_display && opt_click_allowed) {
355 std::cout <<
"A click to exit..." << std::endl;
361 std::cout <<
"Catch an exception: " << e << std::endl;
370 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 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.
The vpDisplayOpenCV allows to display image using the opencv library.
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 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)