50 #include <visp/vpConfig.h>
54 #if defined(VISP_HAVE_OGRE) && (defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK) || (defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__))))
57 #if defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__))
62 # include <visp/vpDisplayX.h>
64 #include <visp/vpDisplayGTK.h>
65 #include <visp/vpDisplayGDI.h>
66 #include <visp/vpDisplayOpenCV.h>
67 #include <visp/vpDisplayD3D.h>
68 #include <visp/vpPose.h>
69 #include <visp/vpPoint.h>
70 #include <visp/vpImagePoint.h>
71 #include <visp/vpDot2.h>
72 #include <visp/vpPixelMeterConversion.h>
73 #include <visp/vpVideoReader.h>
74 #include <visp/vpParseArgv.h>
75 #include <visp/vpIoTools.h>
76 #include <visp/vpDebug.h>
77 #include <visp/vpAROgre.h>
80 #define GETOPTARGS "ci:p:h"
92 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
95 Test augmented reality using the vpAROgre class.\n\
98 %s [-i <test image path>] [-p <personal image path>]\n\
103 -i <input image path> %s\n\
104 Set image input path.\n\
105 From this path read images \n\
106 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
107 images come from ViSP-images-x.y.z.tar.gz available \n\
108 on the ViSP website.\n\
109 Setting the VISP_INPUT_IMAGE_PATH environment\n\
110 variable produces the same behaviour than using\n\
113 -p <personal image path> %s\n\
114 Specify a personal sequence containing images \n\
116 By image sequence, we mean one file per image.\n\
117 The following image file formats PNM (PGM P5, PPM P6)\n\
118 are supported. The format is selected by analysing \n\
119 the filename extension.\n\
120 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
121 %%04d is for the image numbering.\n\
124 Disable the mouse click. Useful to automaze the \n\
125 execution of this program without humain intervention.\n\
129 ipath.c_str(), ppath.c_str());
132 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
147 bool getOptions(
int argc,
const char **argv, std::string &ipath,
148 std::string &ppath,
bool &click_allowed)
155 case 'c': click_allowed =
false;
break;
156 case 'i': ipath = optarg;
break;
157 case 'p': ppath = optarg;
break;
158 case 'h': usage(argv[0], NULL, ipath, ppath);
162 usage(argv[0], optarg, ipath, ppath);
167 if ((c == 1) || (c == -1)) {
169 usage(argv[0], NULL, ipath, ppath);
170 std::cerr <<
"ERROR: " << std::endl;
171 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
185 const bool &opt_click_allowed)
190 bool opt_display =
true;
193 #if defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__))
199 #elif defined VISP_HAVE_GTK
201 #elif defined VISP_HAVE_GDI
203 #elif defined VISP_HAVE_OPENCV
205 #elif defined VISP_HAVE_D3D9
209 for (
unsigned int i=0 ; i < 4 ; i++)
222 display.
init(I,100,100,
"Preliminary Pose Calculation");
240 std::cout<<
"************************************************************************************"<<std::endl;
241 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
242 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
243 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
244 std::cout<<
"************************************************************************************"<<std::endl;
248 if (! opt_click_allowed) {
259 for(
unsigned int i=0;i<4;i++) {
269 for(
unsigned int j = 0;j<i;j++)
275 if (opt_click_allowed) {
322 for (
unsigned int i=0 ; i < 4 ; i++)
345 for (
unsigned int i=0 ; i < 4 ; i++)
361 for (
unsigned int i=0 ; i < 4 ; i++)
386 int main(
int argc,
const char **argv)
389 std::string env_ipath;
390 std::string opt_ipath;
392 std::string opt_ppath;
394 std::string filename;
395 bool opt_click_allowed =
true;
401 if (! env_ipath.empty())
406 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
411 if (!opt_ipath.empty())
416 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
417 if (ipath != env_ipath) {
418 std::cout << std::endl
419 <<
"WARNING: " << std::endl;
420 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
421 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
422 <<
" we skip the environment variable." << std::endl;
427 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
428 usage(argv[0], NULL, ipath, opt_ppath);
429 std::cerr << std::endl
430 <<
"ERROR:" << std::endl;
431 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
433 <<
" environment variable to specify the location of the " << std::endl
434 <<
" image path where test images are located." << std::endl
435 <<
" Use -p <personal image path> option if you want to "<<std::endl
436 <<
" use personal images." << std::endl
448 std::ostringstream s;
451 if (opt_ppath.empty()){
457 s.setf(std::ios::right, std::ios::adjustfield);
458 s <<
"image.%04d.pgm";
462 filename = opt_ppath;
495 vpCTRACE <<
"Load: " << filename << std::endl;
496 grabber.
open(Idisplay);
500 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP,
515 std::cerr << std::endl
516 <<
"ERROR:" << std::endl;
517 std::cerr <<
" Cannot read " << filename << std::endl;
518 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
519 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
528 ogre.load(
"Robot",
"robot.mesh");
529 ogre.setScale(
"Robot", 0.001f,0.001f,0.001f);
533 Ogre::Light * light = ogre.getSceneManager()->createLight();
534 light->setDiffuseColour(1, 1, 1);
535 light->setSpecularColour(1, 1, 1);
536 light->setPosition(-5, -5, 10);
537 light->setType(Ogre::Light::LT_POINT);
540 while(ogre.continueRendering() && !grabber.
end()) {
551 for (
int i=0 ; i < 4 ; i++) {
553 md[i].
track(I, mcog[i]) ;
574 ogre.display(IC,cMo);
584 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
588 std::cout <<
"Catch an exception " << std::endl;
592 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY
596 std::cout <<
"You should install Ogre3D or a display (GTK or OpenCV...) to run this example..." << std::endl;
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.
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)
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.
vpImagePoint getCog() const
void open(vpImage< vpRGBa > &I)
Display for windows using Direct3D.
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.
bool computePose(vpPoseMethodType methode, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
compute the pose for a given method
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
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).
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 init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void set_j(const double jj)
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 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)
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