66 #include <visp3/core/vpConfig.h> 67 #include <visp3/core/vpDebug.h> 68 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) 70 #include <visp3/core/vpImage.h> 71 #include <visp3/core/vpImagePoint.h> 72 #include <visp3/io/vpImageIo.h> 74 #include <visp3/gui/vpDisplayGDI.h> 75 #include <visp3/gui/vpDisplayGTK.h> 76 #include <visp3/gui/vpDisplayOpenCV.h> 77 #include <visp3/gui/vpDisplayX.h> 79 #include <visp3/blob/vpDot.h> 80 #include <visp3/core/vpIoTools.h> 81 #include <visp3/core/vpPixelMeterConversion.h> 82 #include <visp3/io/vpParseArgv.h> 83 #include <visp3/vision/vpPose.h> 86 #define GETOPTARGS "cdi:p:hf:n:s:" 88 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
89 unsigned nimages,
unsigned step);
90 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
91 unsigned &step,
bool &click_allowed,
bool &display);
106 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
107 unsigned nimages,
unsigned step)
110 Test dot tracking.\n\ 113 %s [-i <input image path>] [-p <personal image path>]\n\ 114 [-f <first image>] [-n <number of images>] [-s <step>][-c] [-d] [-h]\n", name);
118 -i <input image path> %s\n\ 119 Set image input path.\n\ 120 From this path read images \n\ 121 \"cube/image.%%04d.pgm\"\n\ 122 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 123 variable produces the same behaviour than using\n\ 126 -p <personal image path> %s\n\ 127 Specify a personal sequence containing images \n\ 129 By image sequence, we mean one file per image.\n\ 130 The following image file formats PNM (PGM P5, PPM P6)\n\ 131 are supported. The format is selected by analysing \n\ 132 the filename extension.\n\ 133 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 134 %%04d is for the image numbering.\n\ 136 -f <first image> %u\n\ 137 First image number of the sequence.\n\ 139 -n <number of images> %u\n\ 140 Number of images to load from the sequence.\n\ 143 Step between two images.\n\ 146 Disable the mouse click. Useful to automaze the \n\ 147 execution of this program without humain intervention.\n\ 150 Turn off the display.\n\ 153 Print the help.\n", ipath.c_str(), ppath.c_str(), first, nimages, step);
156 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
178 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
179 unsigned &step,
bool &click_allowed,
bool &display)
187 click_allowed =
false;
199 first = (unsigned)atoi(optarg_);
202 nimages = (unsigned)atoi(optarg_);
205 step = (unsigned)atoi(optarg_);
208 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
213 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
219 if ((c == 1) || (c == -1)) {
221 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
222 std::cerr <<
"ERROR: " << std::endl;
223 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
230 int main(
int argc,
const char **argv)
233 std::string env_ipath;
234 std::string opt_ipath;
236 std::string opt_ppath;
238 std::string filename;
239 unsigned opt_first = 0;
240 unsigned opt_nimages = 80;
241 unsigned opt_step = 1;
242 bool opt_click_allowed =
true;
243 bool opt_display =
true;
247 std::cout <<
"-------------------------------------------------------" << std::endl;
248 std::cout <<
" poseVirtualVS.cpp" << std::endl << std::endl;
250 std::cout <<
" Example of dots tracking in an image sequence and pose " 253 std::cout <<
"-------------------------------------------------------" << std::endl;
254 std::cout << std::endl;
261 if (!env_ipath.empty())
265 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_nimages, opt_step, opt_click_allowed,
266 opt_display) ==
false) {
271 if (!opt_ipath.empty())
276 if (opt_ipath.empty() && opt_ppath.empty()) {
277 if (ipath != env_ipath) {
278 std::cout << std::endl <<
"WARNING: " << std::endl;
279 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 280 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
281 <<
" we skip the environment variable." << std::endl;
285 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
286 usage(argv[0], NULL, ipath, opt_ppath, opt_first, opt_nimages, opt_step);
287 std::cerr << std::endl <<
"ERROR:" << std::endl;
288 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
289 <<
" environment variable to specify the location of the " << std::endl
290 <<
" image path where test images are located." << std::endl
291 <<
" Use -p <personal image path> option if you want to " << std::endl
292 <<
" use personal images" << std::endl
302 unsigned iter = opt_first;
303 std::ostringstream s;
304 char cfilename[FILENAME_MAX];
306 if (opt_ppath.empty()) {
325 s.setf(std::ios::right, std::ios::adjustfield);
326 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
330 sprintf(cfilename, opt_ppath.c_str(), iter);
331 filename = cfilename;
337 for (i = 0; i < 4; i++) {
363 if (opt_ppath.empty()) {
364 std::cerr << std::endl <<
"ERROR:" << std::endl;
365 std::cerr <<
" Cannot read " << filename << std::endl;
366 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
367 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
369 std::cerr << std::endl <<
"ERROR:" << std::endl;
370 std::cerr <<
" Cannot read " << filename << std::endl;
371 std::cerr <<
" or your -p " << opt_ppath <<
" option " << std::endl << std::endl;
379 #if defined VISP_HAVE_X11 381 #elif defined VISP_HAVE_GTK 383 #elif defined VISP_HAVE_GDI 385 #elif defined VISP_HAVE_OPENCV 390 display.
init(I, 100, 100,
"tracking using vpDot");
402 if (opt_display && opt_click_allowed) {
404 std::cout <<
"Click the four white dots on the object corner clockwise" << std::endl;
405 for (i = 0; i < 4; i++) {
424 d[i].
track(I, cog[i]);
431 d[0].
track(I, cog[0]);
437 d[1].
track(I, cog[1]);
443 d[2].
track(I, cog[2]);
449 d[3].
track(I, cog[3]);
471 for (i = 0; i < 4; i++)
512 for (i = 0; i < 4; i++) {
526 for (i = 0; i < 4; i++) {
551 while (iter < opt_nimages) {
554 if (opt_ppath.empty()) {
556 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
559 sprintf(cfilename, opt_ppath.c_str(), iter);
560 filename = cfilename;
575 for (i = 0; i < 4; i++) {
577 d[i].
track(I, cog[i]);
618 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
625 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
626 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
627 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
628 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
629 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void track(const vpImage< unsigned char > &I)
error that can be emited by ViSP classes.
void set_x(const double x)
Set the point x coordinate in the image plane.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that defines what is a point.
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
void set_u(const double u)
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 set_v(const double v)
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Generic class defining intrinsic camera parameters.
void set_y(const double y)
Set the point y coordinate in the image plane.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setWorldCoordinates(const double oX, const double oY, const double oZ)
static void read(vpImage< unsigned char > &I, const std::string &filename)
void setGraphics(const bool activate)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void addPoint(const vpPoint &P)
void initTracking(const vpImage< unsigned char > &I)