50 #include <visp/vpConfig.h>
53 #if defined(VISP_HAVE_OGRE) && (defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK))
55 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
60 # include <visp/vpDisplayX.h>
62 #include <visp/vpDisplayGTK.h>
63 #include <visp/vpDisplayGDI.h>
64 #include <visp/vpDisplayOpenCV.h>
65 #include <visp/vpDisplayD3D.h>
66 #include <visp/vpPose.h>
67 #include <visp/vpPoint.h>
68 #include <visp/vpImagePoint.h>
69 #include <visp/vpDot2.h>
70 #include <visp/vpPixelMeterConversion.h>
71 #include <visp/vpVideoReader.h>
72 #include <visp/vpParseArgv.h>
73 #include <visp/vpIoTools.h>
74 #include <visp/vpDebug.h>
75 #include <visp/vpAROgre.h>
78 #define GETOPTARGS "ci:p:h"
90 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
93 Test augmented reality using the vpAROgre class.\n\
96 %s [-i <test image path>] [-p <personal image path>]\n\
101 -i <input image path> %s\n\
102 Set image input path.\n\
103 From this path read images \n\
104 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
105 images come from ViSP-images-x.y.z.tar.gz available \n\
106 on the ViSP website.\n\
107 Setting the VISP_INPUT_IMAGE_PATH environment\n\
108 variable produces the same behaviour than using\n\
111 -p <personal image path> %s\n\
112 Specify a personal sequence containing images \n\
114 By image sequence, we mean one file per image.\n\
115 The following image file formats PNM (PGM P5, PPM P6)\n\
116 are supported. The format is selected by analysing \n\
117 the filename extension.\n\
118 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
119 %%04d is for the image numbering.\n\
122 Disable the mouse click. Useful to automaze the \n\
123 execution of this program without humain intervention.\n\
127 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,
146 std::string &ppath,
bool &click_allowed)
153 case 'c': click_allowed =
false;
break;
154 case 'i': ipath = optarg;
break;
155 case 'p': ppath = optarg;
break;
156 case 'h': usage(argv[0], NULL, ipath, ppath);
160 usage(argv[0], optarg, ipath, ppath);
165 if ((c == 1) || (c == -1)) {
167 usage(argv[0], NULL, ipath, ppath);
168 std::cerr <<
"ERROR: " << std::endl;
169 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
183 const bool &opt_click_allowed)
188 bool opt_display =
true;
190 #if defined(VISP_HAVE_X11) && ! defined(APPLE)
196 #elif defined VISP_HAVE_GTK
198 #elif defined VISP_HAVE_GDI
200 #elif defined VISP_HAVE_OPENCV
202 #elif defined VISP_HAVE_D3D9
206 for (
unsigned int i=0 ; i < 4 ; i++)
219 display.
init(I,100,100,
"Preliminary Pose Calculation");
237 std::cout<<
"************************************************************************************"<<std::endl;
238 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
239 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
240 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
241 std::cout<<
"************************************************************************************"<<std::endl;
245 if (! opt_click_allowed) {
256 for(
unsigned int i=0;i<4;i++) {
266 for(
unsigned int j = 0;j<i;j++)
272 if (opt_click_allowed) {
319 for (
unsigned int i=0 ; i < 4 ; i++)
342 for (
unsigned int i=0 ; i < 4 ; i++)
358 for (
unsigned int i=0 ; i < 4 ; i++)
383 int main(
int argc,
const char **argv)
385 std::string env_ipath;
386 std::string opt_ipath;
388 std::string opt_ppath;
390 std::string filename;
391 bool opt_click_allowed =
true;
394 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
399 if (! env_ipath.empty())
404 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
409 if (!opt_ipath.empty())
414 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
415 if (ipath != env_ipath) {
416 std::cout << std::endl
417 <<
"WARNING: " << std::endl;
418 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
419 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
420 <<
" we skip the environment variable." << std::endl;
425 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
426 usage(argv[0], NULL, ipath, opt_ppath);
427 std::cerr << std::endl
428 <<
"ERROR:" << std::endl;
429 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
431 <<
" environment variable to specify the location of the " << std::endl
432 <<
" image path where test images are located." << std::endl
433 <<
" Use -p <personal image path> option if you want to "<<std::endl
434 <<
" use personal images." << std::endl
446 std::ostringstream s;
449 if (opt_ppath.empty()){
455 s.setf(std::ios::right, std::ios::adjustfield);
456 s <<
"image.%04d.pgm";
457 filename = dirname + s.str();
460 filename = opt_ppath;
493 vpCTRACE <<
"Load: " << filename << std::endl;
494 grabber.
open(Idisplay);
498 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cmo, mP,
513 std::cerr << std::endl
514 <<
"ERROR:" << std::endl;
515 std::cerr <<
" Cannot read " << filename << std::endl;
516 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
517 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
526 ogre.load(
"Robot",
"robot.mesh");
527 ogre.setScale(
"Robot", 0.001f,0.001f,0.001f);
533 while(ogre.continueRendering() && !grabber.
end()){
546 for (
int i=0 ; i < 4 ; i++)
549 md[i].
track(I, mcog[i]) ;
575 ogre.display(IC,cmo);
583 catch (Ogre::Exception& e)
585 std::cerr <<
"Exception:\n";
586 std::cerr << e.getFullDescription().c_str() <<
"\n";
591 std::cerr <<
"Exception: " <<
"\n";
597 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY
601 std::cout <<
"You should install Ogre3D to run this example..." << std::endl;