41 #include <visp3/core/vpConfig.h>
43 #if defined(VISP_HAVE_MODULE_ME) && defined(VISP_HAVE_DISPLAY)
45 #include <visp3/core/vpColor.h>
46 #include <visp3/core/vpImage.h>
47 #include <visp3/core/vpImagePoint.h>
48 #include <visp3/core/vpIoTools.h>
49 #include <visp3/gui/vpDisplayFactory.h>
50 #include <visp3/io/vpVideoReader.h>
51 #include <visp3/io/vpParseArgv.h>
52 #include <visp3/me/vpMeLine.h>
53 #include <visp3/visual_features/vpFeatureBuilder.h>
54 #include <visp3/visual_features/vpFeatureLine.h>
57 #define GETOPTARGS "cdf:hi:l:p:s:"
59 #ifdef ENABLE_VISP_NAMESPACE
74 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
75 unsigned last,
unsigned step)
77 #if VISP_HAVE_DATASET_VERSION >= 0x030600
78 std::string ext(
"png");
80 std::string ext(
"pgm");
83 Tracking of a line.\n\
86 %s [-i <input image path>] [-p <personal image path>]\n\
87 [-f <first image>] [-l <last image>] [-s <step>]\n\
88 [-c] [-d] [-h]\n", name);
92 -i <input image path> %s\n\
93 Set image input path.\n\
94 From this path read \"line/image.%%04d.%s\"\n\
96 Setting the VISP_INPUT_IMAGE_PATH environment\n\
97 variable produces the same behaviour than using\n\
100 -p <personal image path> %s\n\
101 Specify a personal sequence containing images \n\
103 By image sequence, we mean one file per image.\n\
104 Example : \"C:/Temp/visp-images/line/image.%%04d.%s\"\n\
105 %%04d is for the image numbering.\n\
107 -f <first image> %u\n\
108 First image number of the sequence.\n\
110 -l <last image> %u\n\
111 Last image number of the sequence.\n\
114 Step between two images.\n\
117 Disable the mouse click. Useful to automate the \n\
118 execution of this program without human intervention.\n\
121 Turn off the display.\n\
125 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
128 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
148 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
149 unsigned &step,
bool &click_allowed,
bool &display)
157 click_allowed =
false;
169 first = (unsigned)atoi(optarg_);
172 last = (unsigned)atoi(optarg_);
175 step = (unsigned)atoi(optarg_);
178 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
183 usage(argv[0], optarg_, ipath, ppath, first, last, step);
189 if ((c == 1) || (c == -1)) {
191 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
192 std::cerr <<
"ERROR: " << std::endl;
193 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
200 int main(
int argc,
const char **argv)
202 #if defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)
203 std::string env_ipath;
204 std::string opt_ipath;
206 std::string opt_ppath;
207 std::string videoname;
208 unsigned int opt_first = 1;
209 unsigned int opt_last = 30;
210 unsigned int opt_step = 1;
211 bool opt_click_allowed =
true;
212 bool opt_display =
true;
213 unsigned int thickness = 1;
225 if (!env_ipath.empty())
229 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
230 opt_display) ==
false) {
235 if (!opt_ipath.empty()) {
241 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
242 if (ipath != env_ipath) {
243 std::cout << std::endl <<
"WARNING: " << std::endl;
244 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
245 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
246 <<
" we skip the environment variable." << std::endl;
251 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
252 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
253 std::cerr << std::endl <<
"ERROR:" << std::endl;
254 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
255 <<
" environment variable to specify the location of the " << std::endl
256 <<
" image path where test images are located." << std::endl
257 <<
" Use -p <personal image path> option if you want to " << std::endl
258 <<
" use personal images." << std::endl
265 if (opt_ppath.empty()) {
267 #if VISP_HAVE_DATASET_VERSION >= 0x030600
292 display->init(I, 10, 10,
"Current image");
313 const bool useIntensity =
true;
317 std::cout <<
"Video settings" << std::endl;
318 std::cout <<
" Name : " << g.
getFrameName() << std::endl;
321 std::cout <<
" Step : " << g.
getFrameStep() << std::endl;
322 std::cout <<
" Image size : " << I.
getWidth() <<
" x " << I.
getHeight() << std::endl;
324 std::cout <<
"Moving-edges settings" << std::endl;
326 std::cout <<
" Range : " << me_line.
getMe()->
getRange() << std::endl;
330 if (opt_display && opt_click_allowed)
346 if (opt_display && opt_click_allowed) {
347 std::cout <<
"A click to continue..." << std::endl;
350 std::cout <<
"----------------------------------------------------------" << std::endl;
357 while (!g.
end() && !quit) {
359 std::cout <<
"Process image " << g.
getFrameIndex() << std::endl;
363 if (opt_click_allowed) {
382 if (opt_click_allowed) {
393 if (opt_display && opt_click_allowed && !quit) {
402 std::cout <<
"Catch an exception: " << e << std::endl;
408 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
417 std::cout <<
"visp_me module or X11, GTK, GDI or OpenCV display functionalities are required..." << std::endl;
Generic class defining intrinsic camera parameters.
static const vpColor green
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 setRhoSignFromIntensity(bool useIntensityForRho)
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
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.