46 #include <visp3/core/vpConfig.h>
47 #include <visp3/core/vpDebug.h>
54 #if defined(VISP_HAVE_MODULE_ME) && \
55 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
57 #include <visp3/core/vpColor.h>
58 #include <visp3/core/vpImage.h>
59 #include <visp3/core/vpImagePoint.h>
60 #include <visp3/core/vpIoTools.h>
61 #include <visp3/gui/vpDisplayGDI.h>
62 #include <visp3/gui/vpDisplayGTK.h>
63 #include <visp3/gui/vpDisplayOpenCV.h>
64 #include <visp3/gui/vpDisplayX.h>
65 #include <visp3/io/vpImageIo.h>
66 #include <visp3/io/vpVideoReader.h>
67 #include <visp3/io/vpParseArgv.h>
68 #include <visp3/me/vpMeLine.h>
69 #include <visp3/visual_features/vpFeatureBuilder.h>
70 #include <visp3/visual_features/vpFeatureLine.h>
73 #define GETOPTARGS "cdf:hi:l:p:s:"
75 #ifdef ENABLE_VISP_NAMESPACE
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)
221 std::string env_ipath;
222 std::string opt_ipath;
224 std::string opt_ppath;
225 std::string videoname;
226 unsigned int opt_first = 1;
227 unsigned int opt_last = 30;
228 unsigned int opt_step = 1;
229 bool opt_click_allowed =
true;
230 bool opt_display =
true;
231 unsigned int thickness = 1;
243 if (!env_ipath.empty())
247 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
248 opt_display) ==
false) {
253 if (!opt_ipath.empty()) {
259 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
260 if (ipath != env_ipath) {
261 std::cout << std::endl <<
"WARNING: " << std::endl;
262 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
263 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
264 <<
" we skip the environment variable." << std::endl;
269 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
270 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
271 std::cerr << std::endl <<
"ERROR:" << std::endl;
272 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
273 <<
" environment variable to specify the location of the " << std::endl
274 <<
" image path where test images are located." << std::endl
275 <<
" Use -p <personal image path> option if you want to " << std::endl
276 <<
" use personal images." << std::endl
283 if (opt_ppath.empty()) {
285 #if VISP_HAVE_DATASET_VERSION >= 0x030600
307 #if defined(VISP_HAVE_X11)
308 display =
new vpDisplayX;
309 #elif defined(VISP_HAVE_GTK)
311 #elif defined(VISP_HAVE_GDI)
313 #elif defined(HAVE_OPENCV_HIGHGUI)
317 display->init(I, 10, 10,
"Current image");
338 std::cout <<
"Video settings" << std::endl;
339 std::cout <<
" Name : " << g.
getFrameName() << std::endl;
342 std::cout <<
" Step : " << g.
getFrameStep() << std::endl;
343 std::cout <<
" Image size : " << I.
getWidth() <<
" x " << I.
getHeight() << std::endl;
345 std::cout <<
"Moving-edges settings" << std::endl;
347 std::cout <<
" Range : " << me_line.
getMe()->
getRange() << std::endl;
351 if (opt_display && opt_click_allowed)
367 if (opt_display && opt_click_allowed) {
368 std::cout <<
"A click to continue..." << std::endl;
371 std::cout <<
"----------------------------------------------------------" << std::endl;
378 while (!g.
end() && !quit) {
380 std::cout <<
"Process image " << g.
getFrameIndex() << std::endl;
384 if (opt_click_allowed) {
399 if (opt_display && opt_click_allowed) {
405 if (opt_display && opt_click_allowed && !quit) {
414 std::cout <<
"Catch an exception: " << e << std::endl;
420 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
429 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display "
430 "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...
Class that defines generic functionalities for display.
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)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
unsigned int getHeight() const
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)
vpLikelihoodThresholdType getLikelihoodThresholdType() const
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setThreshold(const double &threshold)
double getThreshold() const
double getSampleStep() const
unsigned int getRange() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void setLastFrameIndex(const long last_frame)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
long getFirstFrameIndex()
void setFrameStep(const long frame_step)
long getFrameStep() const
std::string getFrameName() const
long getFrameIndex() const