48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpDebug.h>
56 #if defined(VISP_HAVE_MODULE_ME) && \
57 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
59 #include <visp3/core/vpColor.h>
60 #include <visp3/core/vpImage.h>
61 #include <visp3/core/vpImagePoint.h>
62 #include <visp3/gui/vpDisplayGDI.h>
63 #include <visp3/gui/vpDisplayGTK.h>
64 #include <visp3/gui/vpDisplayOpenCV.h>
65 #include <visp3/gui/vpDisplayX.h>
66 #include <visp3/io/vpImageIo.h>
68 #include <visp3/me/vpMeLine.h>
70 #include <visp3/visual_features/vpFeatureBuilder.h>
71 #include <visp3/visual_features/vpFeatureLine.h>
73 #include <visp3/core/vpIoTools.h>
74 #include <visp3/io/vpParseArgv.h>
77 #define GETOPTARGS "cdf:hi:l:p:s:"
92 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
93 unsigned last,
unsigned step)
95 #if VISP_HAVE_DATASET_VERSION >= 0x030600
96 std::string ext(
"png");
98 std::string ext(
"pgm");
101 Tracking of a line.\n\
104 %s [-i <input image path>] [-p <personal image path>]\n\
105 [-f <first image>] [-l <last image>] [-s <step>]\n\
106 [-c] [-d] [-h]\n", name);
110 -i <input image path> %s\n\
111 Set image input path.\n\
112 From this path read \"line/image.%%04d.%s\"\n\
114 Setting the VISP_INPUT_IMAGE_PATH environment\n\
115 variable produces the same behaviour than using\n\
118 -p <personal image path> %s\n\
119 Specify a personal sequence containing images \n\
121 By image sequence, we mean one file per image.\n\
122 Example : \"C:/Temp/visp-images/line/image.%%04d.%s\"\n\
123 %%04d is for the image numbering.\n\
125 -f <first image> %u\n\
126 First image number of the sequence.\n\
128 -l <last image> %u\n\
129 Last image number of the sequence.\n\
132 Step between two images.\n\
135 Disable the mouse click. Useful to automate the \n\
136 execution of this program without human intervention.\n\
139 Turn off the display.\n\
143 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
146 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
166 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
167 unsigned &step,
bool &click_allowed,
bool &display)
175 click_allowed =
false;
187 first = (unsigned)atoi(optarg_);
190 last = (unsigned)atoi(optarg_);
193 step = (unsigned)atoi(optarg_);
196 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
201 usage(argv[0], optarg_, ipath, ppath, first, last, step);
207 if ((c == 1) || (c == -1)) {
209 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
210 std::cerr <<
"ERROR: " << std::endl;
211 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
218 int main(
int argc,
const char **argv)
220 #if defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)
222 std::string env_ipath;
223 std::string opt_ipath;
225 std::string opt_ppath;
227 std::string filename;
228 unsigned int opt_first = 1;
229 unsigned int opt_last = 30;
230 unsigned int opt_step = 1;
231 bool opt_click_allowed =
true;
232 bool opt_display =
true;
234 #if VISP_HAVE_DATASET_VERSION >= 0x030600
235 std::string ext(
"png");
237 std::string ext(
"pgm");
245 if (!env_ipath.empty())
249 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
250 opt_display) ==
false) {
255 if (!opt_ipath.empty())
260 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
261 if (ipath != env_ipath) {
262 std::cout << std::endl <<
"WARNING: " << std::endl;
263 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
264 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
265 <<
" we skip the environment variable." << std::endl;
270 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
271 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
272 std::cerr << std::endl <<
"ERROR:" << std::endl;
273 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
274 <<
" environment variable to specify the location of the " << std::endl
275 <<
" image path where test images are located." << std::endl
276 <<
" Use -p <personal image path> option if you want to " << std::endl
277 <<
" use personal images." << std::endl
288 unsigned iter = opt_first;
289 std::ostringstream s;
290 char cfilename[FILENAME_MAX];
292 if (opt_ppath.empty()) {
306 s.setf(std::ios::right, std::ios::adjustfield);
307 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
311 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
312 filename = cfilename;
321 vpCTRACE <<
"Load: " << filename << std::endl;
327 std::cerr << std::endl <<
"ERROR:" << std::endl;
328 std::cerr <<
" Cannot read " << filename << std::endl;
329 if (opt_ppath.empty()) {
330 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
331 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
334 std::cerr <<
" Check your -p " << opt_ppath <<
" option " << std::endl;
340 #if defined(VISP_HAVE_X11)
342 #elif defined(VISP_HAVE_GTK)
344 #elif defined(VISP_HAVE_GDI)
346 #elif defined(HAVE_OPENCV_HIGHGUI)
352 display.init(I, 100, 100,
"Display...");
373 if (opt_display && opt_click_allowed)
388 if (opt_display && opt_click_allowed) {
389 std::cout <<
"A click to continue..." << std::endl;
392 std::cout <<
"----------------------------------------------------------" << std::endl;
398 while (iter < opt_last) {
399 std::cout <<
"----------------------------------------------------------" << std::endl;
402 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
411 std::cout <<
"Tracking on image: " << filename << std::endl;
421 if (opt_click_allowed) {
422 std::cout <<
"A click to continue..." << std::endl;
429 if (opt_display && opt_click_allowed) {
430 std::cout <<
"A click to exit..." << std::endl;
436 std::cout <<
"Catch an exception: " << e << std::endl;
442 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
451 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
452 "functionalities are required..."
Generic class defining intrinsic camera parameters.
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double deg(double rad)
Class that tracks in an image a line moving edges.
void display(const vpImage< unsigned char > &I, const vpColor &color, unsigned int thickness=1)
void track(const vpImage< unsigned char > &I)
void initTracking(const vpImage< unsigned char > &I)
void setDisplay(vpMeSite::vpMeSiteDisplayType select)
void setPointsToTrack(const int &points_to_track)
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setThreshold(const double &threshold)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.