50 #include <visp/vpConfig.h>
54 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
59 # include <visp/vpDisplayX.h>
61 #include <visp/vpDisplayGTK.h>
62 #include <visp/vpDisplayGDI.h>
63 #include <visp/vpDisplayOpenCV.h>
64 #include <visp/vpPose.h>
65 #include <visp/vpPoint.h>
66 #include <visp/vpImagePoint.h>
67 #include <visp/vpDot2.h>
68 #include <visp/vpPixelMeterConversion.h>
69 #include <visp/vpVideoReader.h>
70 #include <visp/vpParseArgv.h>
71 #include <visp/vpIoTools.h>
72 #include <visp/vpDebug.h>
73 #include <visp/vpAROgre.h>
76 #define GETOPTARGS "ci:p:h"
88 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
91 Test augmented reality using the vpAROgre class.\n\
94 %s [-i <test image path>] [-p <personal image path>]\n\
99 -i <input image path> %s\n\
100 Set image input path.\n\
101 From this path read images \n\
102 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
103 images come from ViSP-images-x.y.z.tar.gz available \n\
104 on the ViSP website.\n\
105 Setting the VISP_INPUT_IMAGE_PATH environment\n\
106 variable produces the same behaviour than using\n\
109 -p <personal image path> %s\n\
110 Specify a personal sequence containing images \n\
112 By image sequence, we mean one file per image.\n\
113 The following image file formats PNM (PGM P5, PPM P6)\n\
114 are supported. The format is selected by analysing \n\
115 the filename extension.\n\
116 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
117 %%04d is for the image numbering.\n\
120 Disable the mouse click. Useful to automaze the \n\
121 execution of this program without humain intervention.\n\
125 ipath.c_str(), ppath.c_str());
128 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
143 bool getOptions(
int argc,
const char **argv, std::string &ipath,
144 std::string &ppath,
bool &click_allowed)
151 case 'c': click_allowed =
false;
break;
152 case 'i': ipath = optarg;
break;
153 case 'p': ppath = optarg;
break;
154 case 'h': usage(argv[0], NULL, ipath, ppath);
158 usage(argv[0], optarg, ipath, ppath);
163 if ((c == 1) || (c == -1)) {
165 usage(argv[0], NULL, ipath, ppath);
166 std::cerr <<
"ERROR: " << std::endl;
167 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
181 const bool &opt_click_allowed)
186 bool opt_display =
true;
188 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
194 #elif defined VISP_HAVE_GTK
196 #elif defined VISP_HAVE_GDI
198 #elif defined VISP_HAVE_OPENCV
202 for (
unsigned int i=0 ; i < 4 ; i++)
215 display.
init(I,100,100,
"Preliminary Pose Calculation");
233 std::cout<<
"************************************************************************************"<<std::endl;
234 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
235 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
236 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
237 std::cout<<
"************************************************************************************"<<std::endl;
241 if (! opt_click_allowed) {
252 for(
unsigned int i=0;i<4;i++) {
262 for(
unsigned int j = 0;j<i;j++)
268 if (opt_click_allowed) {
315 for (
unsigned int i=0 ; i < 4 ; i++)
338 for (
unsigned int i=0 ; i < 4 ; i++)
354 for (
unsigned int i=0 ; i < 4 ; i++)
379 int main(
int argc,
const char **argv)
381 std::string env_ipath;
382 std::string opt_ipath;
384 std::string opt_ppath;
386 std::string filename;
387 bool opt_click_allowed =
true;
390 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
395 if (! env_ipath.empty())
400 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
405 if (!opt_ipath.empty())
410 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
411 if (ipath != env_ipath) {
412 std::cout << std::endl
413 <<
"WARNING: " << std::endl;
414 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
415 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
416 <<
" we skip the environment variable." << std::endl;
421 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
422 usage(argv[0], NULL, ipath, opt_ppath);
423 std::cerr << std::endl
424 <<
"ERROR:" << std::endl;
425 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
427 <<
" environment variable to specify the location of the " << std::endl
428 <<
" image path where test images are located." << std::endl
429 <<
" Use -p <personal image path> option if you want to "<<std::endl
430 <<
" use personal images." << std::endl
442 std::ostringstream s;
445 if (opt_ppath.empty()){
451 s.setf(std::ios::right, std::ios::adjustfield);
452 s <<
"image.%04d.pgm";
453 filename = dirname + s.str();
456 filename = opt_ppath;
489 vpCTRACE <<
"Load: " << filename << std::endl;
490 grabber.
open(Idisplay);
494 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cmo, mP,
509 std::cerr << std::endl
510 <<
"ERROR:" << std::endl;
511 std::cerr <<
" Cannot read " << filename << std::endl;
512 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
513 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
522 ogre.load(
"Robot",
"robot.mesh");
523 ogre.setScale(
"Robot", 0.001f,0.001f,0.001f);
529 while(ogre.continueRendering()){
542 for (
int i=0 ; i < 4 ; i++)
545 md[i].
track(I, mcog[i]) ;
571 ogre.display(IC,cmo);
579 catch (Ogre::Exception& e)
581 std::cerr <<
"Exception:\n";
582 std::cerr << e.getFullDescription().c_str() <<
"\n";
587 std::cerr <<
"Exception: " <<
"\n";
593 #else // VISP_HAVE_OGRE
597 std::cout <<
"You should install Ogre3D to run this example..." << std::endl;
void setFirstFrameIndex(const long firstFrame)
void set_j(const double j)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void init()
basic initialization with the default parameters
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void set_i(const double i)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
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)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
Implementation of an augmented reality viewer.
static int wait(double t0, double t)
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.
The vpRotationMatrix considers the particular case of a rotation matrix.
virtual void init(vpImage< unsigned char > &I, bool bufferedKeys=false)
vpImagePoint getCog() const
void open(vpImage< vpRGBa > &I)
void setGrayLevelPrecision(const double &grayLevelPrecision)
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
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.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Class used for pose computation from N points (pose from point only).
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+ library version 1.2.
void acquire(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1)
void setSizePrecision(const double &sizePrecision)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
void computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo)
compute the pose for a given method
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void addPoint(const vpPoint &P)
Add a new point in this array.
unsigned int getHeight() const
Return the number of rows in the image.
void setGraphics(const bool activate)
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
void clearPoint()
suppress all the point in the array of point