50 #include <visp3/core/vpDebug.h>
51 #include <visp3/core/vpConfig.h>
58 #if defined(VISP_HAVE_MODULE_ME) && (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
60 #include <visp3/core/vpImage.h>
61 #include <visp3/io/vpImageIo.h>
62 #include <visp3/core/vpImagePoint.h>
63 #include <visp3/gui/vpDisplayX.h>
64 #include <visp3/gui/vpDisplayGTK.h>
65 #include <visp3/gui/vpDisplayGDI.h>
66 #include <visp3/gui/vpDisplayOpenCV.h>
67 #include <visp3/core/vpColor.h>
69 #include <visp3/me/vpMeLine.h>
71 #include <visp3/visual_features/vpFeatureLine.h>
72 #include <visp3/visual_features/vpFeatureBuilder.h>
74 #include <visp3/io/vpParseArgv.h>
75 #include <visp3/core/vpIoTools.h>
78 #define GETOPTARGS "cdi:h"
80 void usage(
const char *name,
const char *badparam, std::string ipath);
81 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
92 void usage(
const char *name,
const char *badparam, std::string ipath)
95 Tracking of a line.\n\
98 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
102 -i <input image path> %s\n\
103 Set image input path.\n\
104 From this path read \"ViSP-images/line/image.%%04d.pgm\"\n\
106 Setting the VISP_INPUT_IMAGE_PATH environment\n\
107 variable produces the same behaviour than using\n\
111 Disable the mouse click. Useful to automaze the \n\
112 execution of this program without humain intervention.\n\
115 Turn off the display.\n\
122 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
137 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
144 case 'c': click_allowed =
false;
break;
145 case 'd': display =
false;
break;
146 case 'i': ipath = optarg_;
break;
147 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
150 usage(argv[0], optarg_, ipath);
155 if ((c == 1) || (c == -1)) {
157 usage(argv[0], NULL, ipath);
158 std::cerr <<
"ERROR: " << std::endl;
159 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
168 main(
int argc,
const char ** argv)
171 std::string env_ipath;
172 std::string opt_ipath;
175 std::string filename;
176 bool opt_click_allowed =
true;
177 bool opt_display =
true;
183 if (! env_ipath.empty())
188 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
189 opt_display) ==
false) {
194 if (!opt_ipath.empty())
199 if (!opt_ipath.empty() && !env_ipath.empty()) {
200 if (ipath != env_ipath) {
201 std::cout << std::endl
202 <<
"WARNING: " << std::endl;
203 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
204 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
205 <<
" we skip the environment variable." << std::endl;
210 if (opt_ipath.empty() && env_ipath.empty()){
211 usage(argv[0], NULL, ipath);
212 std::cerr << std::endl
213 <<
"ERROR:" << std::endl;
214 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
216 <<
" environment variable to specify the location of the " << std::endl
217 <<
" 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_display && opt_click_allowed)
310 if (opt_display && opt_click_allowed) {
311 std::cout <<
"A click to continue..." << std::endl;
314 std::cout <<
"----------------------------------------------------------"<<std::endl;
320 for (iter = 1 ; iter < 30 ; iter++)
322 std::cout <<
"----------------------------------------------------------"<<std::endl;
325 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
334 std::cout <<
"Tracking on image: " << filename << std::endl;
344 if (opt_click_allowed) {
345 std::cout <<
"A click to continue..." << std::endl;
350 if (opt_display && opt_click_allowed) {
351 std::cout <<
"A click to exit..." << std::endl;
357 std::cout <<
"Catch an exception: " << e << std::endl;
367 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display functionalities are required..." << std::endl;
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setPointsToTrack(const int &n)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
void track(const vpImage< unsigned char > &Im)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
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. Thus to enable this class OpenC...
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 3rd party library. Thus to enable this class G...
void initTracking(const vpImage< unsigned char > &I)
void set_j(const double jj)
static double deg(double rad)
static void read(vpImage< unsigned char > &I, const std::string &filename)
void setThreshold(const double &t)
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)