66 #include <visp3/core/vpConfig.h> 67 #include <visp3/core/vpDebug.h> 69 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) \ 70 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 73 #include <visp3/core/vpImage.h> 74 #include <visp3/core/vpImagePoint.h> 75 #include <visp3/io/vpImageIo.h> 77 #include <visp3/gui/vpDisplayGDI.h> 78 #include <visp3/gui/vpDisplayGTK.h> 79 #include <visp3/gui/vpDisplayOpenCV.h> 80 #include <visp3/gui/vpDisplayX.h> 82 #include <visp3/blob/vpDot.h> 83 #include <visp3/core/vpIoTools.h> 84 #include <visp3/core/vpPixelMeterConversion.h> 85 #include <visp3/io/vpParseArgv.h> 86 #include <visp3/vision/vpPose.h> 89 #define GETOPTARGS "cdi:p:hf:n:s:" 91 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
92 unsigned nimages,
unsigned step);
93 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
94 unsigned &step,
bool &click_allowed,
bool &display);
109 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath,
unsigned first,
110 unsigned nimages,
unsigned step)
113 Test dot tracking.\n\ 116 %s [-i <input image path>] [-p <personal image path>]\n\ 117 [-f <first image>] [-n <number of images>] [-s <step>][-c] [-d] [-h]\n", name);
121 -i <input image path> %s\n\ 122 Set image input path.\n\ 123 From this path read images \n\ 124 \"cube/image.%%04d.pgm\"\n\ 125 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 126 variable produces the same behaviour than using\n\ 129 -p <personal image path> %s\n\ 130 Specify a personal sequence containing images \n\ 132 By image sequence, we mean one file per image.\n\ 133 The following image file formats PNM (PGM P5, PPM P6)\n\ 134 are supported. The format is selected by analysing \n\ 135 the filename extension.\n\ 136 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 137 %%04d is for the image numbering.\n\ 139 -f <first image> %u\n\ 140 First image number of the sequence.\n\ 142 -n <number of images> %u\n\ 143 Number of images to load from the sequence.\n\ 146 Step between two images.\n\ 149 Disable the mouse click. Useful to automaze the \n\ 150 execution of this program without humain intervention.\n\ 153 Turn off the display.\n\ 156 Print the help.\n", ipath.c_str(), ppath.c_str(), first, nimages, step);
159 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
181 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &nimages,
182 unsigned &step,
bool &click_allowed,
bool &display)
190 click_allowed =
false;
202 first = (unsigned)atoi(optarg_);
205 nimages = (unsigned)atoi(optarg_);
208 step = (unsigned)atoi(optarg_);
211 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
216 usage(argv[0], optarg_, ipath, ppath, first, nimages, step);
222 if ((c == 1) || (c == -1)) {
224 usage(argv[0], NULL, ipath, ppath, first, nimages, step);
225 std::cerr <<
"ERROR: " << std::endl;
226 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
233 int main(
int argc,
const char **argv)
236 std::string env_ipath;
237 std::string opt_ipath;
239 std::string opt_ppath;
241 std::string filename;
242 unsigned opt_first = 0;
243 unsigned opt_nimages = 80;
244 unsigned opt_step = 1;
245 bool opt_click_allowed =
true;
246 bool opt_display =
true;
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_nimages, 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], NULL, ipath, opt_ppath, opt_first, opt_nimages, 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()) {
328 s.setf(std::ios::right, std::ios::adjustfield);
329 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
333 sprintf(cfilename, opt_ppath.c_str(), iter);
334 filename = cfilename;
340 for (i = 0; i < 4; i++) {
366 if (opt_ppath.empty()) {
367 std::cerr << std::endl <<
"ERROR:" << std::endl;
368 std::cerr <<
" Cannot read " << filename << std::endl;
369 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
370 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
372 std::cerr << std::endl <<
"ERROR:" << std::endl;
373 std::cerr <<
" Cannot read " << filename << std::endl;
374 std::cerr <<
" or your -p " << opt_ppath <<
" option " << std::endl << std::endl;
382 #if defined VISP_HAVE_X11 384 #elif defined VISP_HAVE_GTK 386 #elif defined VISP_HAVE_GDI 388 #elif defined VISP_HAVE_OPENCV 393 display.
init(I, 100, 100,
"tracking using vpDot");
405 if (opt_display && opt_click_allowed) {
407 std::cout <<
"Click the four white dots on the object corner clockwise" << std::endl;
408 for (i = 0; i < 4; i++) {
427 d[i].
track(I, cog[i]);
434 d[0].
track(I, cog[0]);
440 d[1].
track(I, cog[1]);
446 d[2].
track(I, cog[2]);
452 d[3].
track(I, cog[3]);
474 for (i = 0; i < 4; i++)
515 for (i = 0; i < 4; i++) {
529 for (i = 0; i < 4; i++) {
554 while (iter < opt_nimages) {
557 if (opt_ppath.empty()) {
559 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
562 sprintf(cfilename, opt_ppath.c_str(), iter);
563 filename = cfilename;
578 for (i = 0; i < 4; i++) {
580 d[i].
track(I, cog[i]);
621 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
625 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 628 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
634 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
635 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
636 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
637 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
638 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)
void setWorldCoordinates(double oX, double oY, double oZ)
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 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 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 set_y(double y)
Set the point y coordinate in the image plane.
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
Generic class defining intrinsic camera parameters.
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)
static void read(vpImage< unsigned char > &I, const std::string &filename)
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 setGraphics(bool activate)
void addPoint(const vpPoint &P)
void initTracking(const vpImage< unsigned char > &I)