62 #include <visp3/core/vpConfig.h>
63 #include <visp3/core/vpDebug.h>
65 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) && \
66 (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
68 #include <visp3/core/vpImage.h>
69 #include <visp3/core/vpImagePoint.h>
70 #include <visp3/io/vpImageIo.h>
72 #include <visp3/gui/vpDisplayGDI.h>
73 #include <visp3/gui/vpDisplayGTK.h>
74 #include <visp3/gui/vpDisplayOpenCV.h>
75 #include <visp3/gui/vpDisplayX.h>
77 #include <visp3/blob/vpDot.h>
78 #include <visp3/core/vpIoTools.h>
79 #include <visp3/core/vpPixelMeterConversion.h>
80 #include <visp3/io/vpParseArgv.h>
81 #include <visp3/vision/vpPose.h>
84 #define GETOPTARGS "cdi:p:hf:l:s:"
99 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
100 unsigned last,
unsigned step)
102 #if VISP_HAVE_DATASET_VERSION >= 0x030600
103 std::string ext(
"png");
105 std::string ext(
"pgm");
108 Test dot tracking.\n\
111 %s [-i <input image path>] [-p <personal image path>]\n\
112 [-f <first image>] [-l <last image>] [-s <step>][-c] [-d] [-h]\n",
117 -i <input image path> %s\n\
118 Set image input path.\n\
119 From this path read images \n\
120 \"cube/image.%%04d.%s\"\n\
121 Setting the VISP_INPUT_IMAGE_PATH environment\n\
122 variable produces the same behaviour than using\n\
125 -p <personal image path> %s\n\
126 Specify a personal sequence containing images \n\
128 By image sequence, we mean one file per image.\n\
129 The format is selected by analysing the filename extension.\n\
130 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
131 %%04d is for the image numbering.\n\
133 -f <first image> %u\n\
134 First image number of the sequence.\n\
136 -l <last image> %u\n\
137 Last image number of the sequence.\n\
140 Step between two images.\n\
143 Disable the mouse click. Useful to automate the \n\
144 execution of this program without human intervention.\n\
147 Turn off the display.\n\
151 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
154 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
176 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
177 unsigned &step,
bool &click_allowed,
bool &display)
185 click_allowed =
false;
197 first = (unsigned)atoi(optarg_);
200 last = (unsigned)atoi(optarg_);
203 step = (unsigned)atoi(optarg_);
206 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
211 usage(argv[0], optarg_, ipath, ppath, first, last, step);
217 if ((c == 1) || (c == -1)) {
219 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
220 std::cerr <<
"ERROR: " << std::endl;
221 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
228 int main(
int argc,
const char **argv)
231 std::string env_ipath;
232 std::string opt_ipath;
234 std::string opt_ppath;
236 std::string filename;
237 unsigned opt_first = 0;
238 unsigned opt_last = 80;
239 unsigned opt_step = 1;
240 bool opt_click_allowed =
true;
241 bool opt_display =
true;
244 #if VISP_HAVE_DATASET_VERSION >= 0x030600
245 std::string ext(
"png");
247 std::string ext(
"pgm");
250 std::cout <<
"-------------------------------------------------------" << std::endl;
251 std::cout <<
" poseVirtualVS.cpp" << std::endl << std::endl;
253 std::cout <<
" Example of dots tracking in an image sequence and pose "
256 std::cout <<
"-------------------------------------------------------" << std::endl;
257 std::cout << std::endl;
264 if (!env_ipath.empty())
268 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
269 opt_display) ==
false) {
274 if (!opt_ipath.empty())
279 if (opt_ipath.empty() && opt_ppath.empty()) {
280 if (ipath != env_ipath) {
281 std::cout << std::endl <<
"WARNING: " << std::endl;
282 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
283 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
284 <<
" we skip the environment variable." << std::endl;
288 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
289 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
290 std::cerr << std::endl <<
"ERROR:" << std::endl;
291 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
292 <<
" environment variable to specify the location of the " << std::endl
293 <<
" image path where test images are located." << std::endl
294 <<
" Use -p <personal image path> option if you want to " << std::endl
295 <<
" use personal images" << std::endl
305 unsigned iter = opt_first;
306 std::ostringstream s;
307 char cfilename[FILENAME_MAX];
309 if (opt_ppath.empty()) {
316 s.setf(std::ios::right, std::ios::adjustfield);
317 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
321 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
322 filename = cfilename;
328 for (i = 0; i < 4; i++) {
335 d[i].setGraphics(
true);
337 d[i].setGraphics(
false);
345 if (opt_ppath.empty()) {
346 std::cerr << std::endl <<
"ERROR:" << std::endl;
347 std::cerr <<
" Cannot read " << filename << std::endl;
348 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
349 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
351 std::cerr << std::endl <<
"ERROR:" << std::endl;
352 std::cerr <<
" Cannot read " << filename << std::endl;
353 std::cerr <<
" or your -p " << opt_ppath <<
" option " << std::endl << std::endl;
361 #if defined(VISP_HAVE_X11)
363 #elif defined(VISP_HAVE_GTK)
365 #elif defined(VISP_HAVE_GDI)
367 #elif defined(HAVE_OPENCV_HIGHGUI)
372 display.init(I, 100, 100,
"tracking using vpDot");
384 if (opt_display && opt_click_allowed) {
386 std::cout <<
"Click the four white dots on the object corner clockwise" << std::endl;
387 for (i = 0; i < 4; i++) {
395 d[i].initTracking(I);
406 d[i].track(I, cog[i]);
412 d[0].initTracking(I, cog[0]);
413 d[0].track(I, cog[0]);
418 d[1].initTracking(I, cog[1]);
419 d[1].track(I, cog[1]);
424 d[2].initTracking(I, cog[2]);
425 d[2].track(I, cog[2]);
430 d[3].initTracking(I, cog[3]);
431 d[3].track(I, cog[3]);
453 for (i = 0; i < 4; i++)
494 for (i = 0; i < 4; i++) {
508 for (i = 0; i < 4; i++) {
529 while (iter < opt_last) {
532 if (opt_ppath.empty()) {
534 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
"." << ext;
537 snprintf(cfilename, FILENAME_MAX, opt_ppath.c_str(), iter);
538 filename = cfilename;
553 for (i = 0; i < 4; i++) {
555 d[i].track(I, cog[i]);
594 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
598 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
601 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
607 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
609 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
610 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
611 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
612 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Generic class defining intrinsic camera parameters.
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 void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
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 bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void set_x(double x)
Set the point x coordinate in the image plane.
void setWorldCoordinates(double oX, double oY, double oZ)
void set_y(double y)
Set the point y coordinate in the image plane.
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
void addPoint(const vpPoint &P)
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=nullptr)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.