51 #include <visp3/core/vpConfig.h> 52 #include <visp3/core/vpDebug.h> 59 #if defined(VISP_HAVE_MODULE_ME) && \ 60 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) 62 #include <visp3/core/vpColor.h> 63 #include <visp3/core/vpImage.h> 64 #include <visp3/core/vpImagePoint.h> 65 #include <visp3/gui/vpDisplayGDI.h> 66 #include <visp3/gui/vpDisplayGTK.h> 67 #include <visp3/gui/vpDisplayOpenCV.h> 68 #include <visp3/gui/vpDisplayX.h> 69 #include <visp3/io/vpImageIo.h> 71 #include <visp3/core/vpIoTools.h> 72 #include <visp3/io/vpParseArgv.h> 73 #include <visp3/me/vpMeEllipse.h> 76 #define GETOPTARGS "cdi:h" 78 void usage(
const char *name,
const char *badparam, std::string ipath);
79 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
90 void usage(
const char *name,
const char *badparam, std::string ipath)
93 Test of ellipse tracking using vpMeEllipse.\n\ 96 %s [-i <input image path>] [-c] [-h]\n", name);
100 -i <input image path> %s\n\ 101 Set image input path.\n\ 102 From this path read images \n\ 103 \"ellipse-1/image.%%04d.pgm\"\n\ 104 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 105 variable produces the same behaviour than using\n\ 109 Disable the mouse click. Useful to automaze the \n\ 110 execution of this program without humain intervention.\n\ 113 Turn off the display.\n\ 116 Print the help.\n", ipath.c_str());
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)
142 click_allowed =
false;
151 usage(argv[0], NULL, ipath);
156 usage(argv[0], optarg_, ipath);
162 if ((c == 1) || (c == -1)) {
164 usage(argv[0], NULL, ipath);
165 std::cerr <<
"ERROR: " << std::endl;
166 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
173 int main(
int argc,
const char **argv)
176 std::string env_ipath;
177 std::string opt_ipath;
180 std::string filename;
181 bool opt_click_allowed =
true;
182 bool opt_display =
true;
189 if (!env_ipath.empty())
193 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, 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 <<
"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 <<
"ERROR:" << std::endl;
216 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
217 <<
" environment variable to specify the location of the " << std::endl
218 <<
" image path where test images are located." << std::endl
232 unsigned int iter = 1;
233 std::ostringstream s;
234 s.setf(std::ios::right, std::ios::adjustfield);
235 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
245 vpCTRACE <<
"Load: " << filename << std::endl;
253 std::cerr << std::endl <<
"ERROR:" << std::endl;
254 std::cerr <<
" Cannot read " << filename << std::endl;
255 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
256 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
261 #if defined VISP_HAVE_X11 263 #elif defined VISP_HAVE_GTK 265 #elif defined VISP_HAVE_GDI 267 #elif defined VISP_HAVE_OPENCV 273 display.
init(I, 100, 100,
"Display...");
293 if (opt_click_allowed)
297 std::vector<vpImagePoint> ip;
312 if (opt_display && opt_click_allowed) {
313 std::cout <<
"A click to continue..." << std::endl;
316 std::cout <<
"------------------------------------------------------------" << std::endl;
318 for (iter = 1; iter < 51; iter++)
322 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
324 std::cout <<
"Tracking on image: " << filename << std::endl;
339 if (opt_display && opt_click_allowed) {
340 std::cout <<
"A click to exit..." << std::endl;
345 std::cout <<
"Catch an exception: " << e << std::endl;
354 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display " 355 "functionalities are required..." void track(const vpImage< unsigned char > &I)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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)
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.
Class that tracks an ellipse moving edges.
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 setDisplay(vpMeSite::vpMeSiteDisplayType select)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void display(const vpImage< unsigned char > &I, vpColor col)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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 ...
void setRange(const unsigned int &r)
double getSampleStep() const