46 #include <visp3/core/vpConfig.h> 51 #if defined(VISP_HAVE_OGRE) && \ 52 (defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK) || \ 53 (defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__)))) 56 #if defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__)) 61 #include <visp3/gui/vpDisplayX.h> 63 #include <visp3/ar/vpAROgre.h> 64 #include <visp3/blob/vpDot2.h> 65 #include <visp3/core/vpDebug.h> 66 #include <visp3/core/vpImagePoint.h> 67 #include <visp3/core/vpIoTools.h> 68 #include <visp3/core/vpPixelMeterConversion.h> 69 #include <visp3/core/vpPoint.h> 70 #include <visp3/gui/vpDisplayD3D.h> 71 #include <visp3/gui/vpDisplayGDI.h> 72 #include <visp3/gui/vpDisplayGTK.h> 73 #include <visp3/gui/vpDisplayOpenCV.h> 74 #include <visp3/io/vpParseArgv.h> 75 #include <visp3/io/vpVideoReader.h> 76 #include <visp3/vision/vpPose.h> 79 #define GETOPTARGS "ci:p:h" 91 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
94 Test augmented reality using the vpAROgre class.\n\ 97 %s [-i <test image path>] [-p <personal image path>]\n\ 102 -i <input image path> %s\n\ 103 Set image input path.\n\ 104 From this path read images \n\ 105 \"mire-2/image.%%04d.pgm\". These \n\ 106 images come from ViSP-images-x.y.z.tar.gz available \n\ 107 on the ViSP website.\n\ 108 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 109 variable produces the same behaviour than using\n\ 112 -p <personal image path> %s\n\ 113 Specify a personal sequence containing images \n\ 115 By image sequence, we mean one file per image.\n\ 116 The following image file formats PNM (PGM P5, PPM P6)\n\ 117 are supported. The format is selected by analysing \n\ 118 the filename extension.\n\ 119 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 120 %%04d is for the image numbering.\n\ 123 Disable the mouse click. Useful to automaze the \n\ 124 execution of this program without humain intervention.\n\ 127 Print the help.\n", ipath.c_str(), ppath.c_str());
130 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
145 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed)
153 click_allowed =
false;
162 usage(argv[0], NULL, ipath, ppath);
167 usage(argv[0], optarg, ipath, ppath);
173 if ((c == 1) || (c == -1)) {
175 usage(argv[0], NULL, ipath, ppath);
176 std::cerr <<
"ERROR: " << std::endl;
177 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
196 bool opt_display =
true;
199 #if defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__)) 205 #elif defined VISP_HAVE_GTK 207 #elif defined VISP_HAVE_GDI 209 #elif defined VISP_HAVE_OPENCV 211 #elif defined VISP_HAVE_D3D9 215 for (
unsigned int i = 0; i < 4; i++) {
226 display.
init(I, 100, 100,
"Preliminary Pose Calculation");
242 std::cout <<
"*************************************************************" 243 "***********************" 245 std::cout <<
"*************************** Preliminary Pose Calculation " 246 "***************************" 248 std::cout <<
"****************************** Click on the 4 dots " 249 "*******************************" 251 std::cout <<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), " 252 "Dot4 : (-x,y,0)**********" 254 std::cout <<
"*************************************************************" 255 "***********************" 260 if (!opt_click_allowed) {
271 for (
unsigned int i = 0; i < 4; i++) {
281 for (
unsigned int j = 0; j < i; j++)
287 if (opt_click_allowed) {
332 for (
unsigned int i = 0; i < 4; i++)
355 for (
unsigned int i = 0; i < 4; i++) {
369 for (
unsigned int i = 0; i < 4; i++) {
392 int main(
int argc,
const char **argv)
395 std::string env_ipath;
396 std::string opt_ipath;
398 std::string opt_ppath;
400 std::string filename;
401 bool opt_click_allowed =
true;
408 if (!env_ipath.empty())
412 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
417 if (!opt_ipath.empty())
422 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
423 if (ipath != env_ipath) {
424 std::cout << std::endl <<
"WARNING: " << std::endl;
425 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 426 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
427 <<
" we skip the environment variable." << std::endl;
432 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
433 usage(argv[0], NULL, ipath, opt_ppath);
434 std::cerr << std::endl <<
"ERROR:" << std::endl;
435 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
436 <<
" environment variable to specify the location of the " << std::endl
437 <<
" image path where test images are located." << std::endl
438 <<
" Use -p <personal image path> option if you want to " << std::endl
439 <<
" use personal images." << std::endl
451 std::ostringstream s;
454 if (opt_ppath.empty()) {
460 s.setf(std::ios::right, std::ios::adjustfield);
461 s <<
"image.%04d.pgm";
464 filename = opt_ppath;
498 vpCTRACE <<
"Load: " << filename << std::endl;
499 grabber.
open(Idisplay);
503 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP, opt_click_allowed);
515 std::cerr << std::endl <<
"ERROR:" << std::endl;
516 std::cerr <<
" Cannot read " << filename << std::endl;
517 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
518 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
526 ogre.load(
"Robot",
"robot.mesh");
527 ogre.setScale(
"Robot", 0.001f, 0.001f, 0.001f);
531 Ogre::Light *light = ogre.getSceneManager()->createLight();
532 light->setDiffuseColour(1, 1, 1);
533 light->setSpecularColour(1, 1, 1);
534 light->setPosition(-5, -5, 10);
535 light->setType(Ogre::Light::LT_POINT);
538 while (ogre.continueRendering() && !grabber.
end()) {
549 for (
int i = 0; i < 4; i++) {
551 md[i].
track(I, mcog[i]);
572 ogre.display(IC, cMo);
581 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
583 }
catch (Ogre::Exception &e) {
584 std::cout <<
"Catch an Ogre exception: " << e.getDescription() << std::endl;
587 std::cout <<
"Catch an exception " << std::endl;
591 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY 594 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))) 595 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
596 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
597 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
598 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
599 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
601 std::cout <<
"You do not have Ogre functionalities" << std::endl;
602 std::cout <<
"Tip:" << std::endl;
603 std::cout <<
"- Install Ogre3D, configure again ViSP using cmake and build again this example" << std::endl;
VISP_EXPORT int wait(double t0, double t)
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
void init()
basic initialization with the default parameters
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
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...
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
error that can be emited by ViSP classes.
void set_x(const double x)
Set the point x coordinate in the image plane.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Implementation of an augmented reality viewer using Ogre3D 3rd party.
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
void track(const vpImage< unsigned char > &I)
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.
Implementation of a rotation matrix and operations on such kind of matrices.
vpImagePoint getCog() const
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
void setGrayLevelPrecision(const double &grayLevelPrecision)
void set_i(const double ii)
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
virtual void init(vpImage< unsigned char > &I, bool bufferedKeys=false, bool hidden=false)
unsigned int getWidth() const
Return the number of columns in the image.
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 display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
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...
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
void set_j(const double jj)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setSizePrecision(const double &sizePrecision)
void setWorldCoordinates(const double oX, const double oY, const double oZ)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Implementation of a rotation vector as Euler angle minimal representation.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void setFirstFrameIndex(const long first_frame)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void addPoint(const vpPoint &P)
unsigned int getHeight() const
Return the number of rows in the image.
void setGraphics(const bool activate)