46 #include <visp3/core/vpConfig.h> 50 #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__)))) 53 #if defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__)) 58 # include <visp3/gui/vpDisplayX.h> 60 #include <visp3/gui/vpDisplayGTK.h> 61 #include <visp3/gui/vpDisplayGDI.h> 62 #include <visp3/gui/vpDisplayOpenCV.h> 63 #include <visp3/gui/vpDisplayD3D.h> 64 #include <visp3/vision/vpPose.h> 65 #include <visp3/core/vpPoint.h> 66 #include <visp3/core/vpImagePoint.h> 67 #include <visp3/blob/vpDot2.h> 68 #include <visp3/core/vpPixelMeterConversion.h> 69 #include <visp3/io/vpVideoReader.h> 70 #include <visp3/io/vpParseArgv.h> 71 #include <visp3/core/vpIoTools.h> 72 #include <visp3/core/vpDebug.h> 73 #include <visp3/ar/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;
189 #if defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__)) 195 #elif defined VISP_HAVE_GTK 197 #elif defined VISP_HAVE_GDI 199 #elif defined VISP_HAVE_OPENCV 201 #elif defined VISP_HAVE_D3D9 205 for (
unsigned int i=0 ; i < 4 ; i++)
218 display.
init(I,100,100,
"Preliminary Pose Calculation");
236 std::cout<<
"************************************************************************************"<<std::endl;
237 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
238 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
239 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
240 std::cout<<
"************************************************************************************"<<std::endl;
244 if (! opt_click_allowed) {
255 for(
unsigned int i=0;i<4;i++) {
265 for(
unsigned int j = 0;j<i;j++)
271 if (opt_click_allowed) {
318 for (
unsigned int i=0 ; i < 4 ; i++)
341 for (
unsigned int i=0 ; i < 4 ; i++)
357 for (
unsigned int i=0 ; i < 4 ; i++)
382 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;
397 if (! env_ipath.empty())
402 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
407 if (!opt_ipath.empty())
412 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
413 if (ipath != env_ipath) {
414 std::cout << std::endl
415 <<
"WARNING: " << std::endl;
416 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 417 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
418 <<
" we skip the environment variable." << std::endl;
423 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
424 usage(argv[0], NULL, ipath, opt_ppath);
425 std::cerr << std::endl
426 <<
"ERROR:" << std::endl;
427 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " 429 <<
" environment variable to specify the location of the " << std::endl
430 <<
" image path where test images are located." << std::endl
431 <<
" Use -p <personal image path> option if you want to "<<std::endl
432 <<
" use personal images." << std::endl
444 std::ostringstream s;
447 if (opt_ppath.empty()){
453 s.setf(std::ios::right, std::ios::adjustfield);
454 s <<
"image.%04d.pgm";
458 filename = opt_ppath;
491 vpCTRACE <<
"Load: " << filename << std::endl;
492 grabber.
open(Idisplay);
496 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP,
511 std::cerr << std::endl
512 <<
"ERROR:" << std::endl;
513 std::cerr <<
" Cannot read " << filename << std::endl;
514 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
515 <<
" or VISP_INPUT_IMAGE_PATH environment variable." 524 ogre.load(
"Robot",
"robot.mesh");
525 ogre.setScale(
"Robot", 0.001f,0.001f,0.001f);
529 Ogre::Light * light = ogre.getSceneManager()->createLight();
530 light->setDiffuseColour(1, 1, 1);
531 light->setSpecularColour(1, 1, 1);
532 light->setPosition(-5, -5, 10);
533 light->setType(Ogre::Light::LT_POINT);
536 while(ogre.continueRendering() && !grabber.
end()) {
547 for (
int i=0 ; i < 4 ; i++) {
549 md[i].
track(I, mcog[i]) ;
570 ogre.display(IC,cMo);
580 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;
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;
VISP_EXPORT int wait(double t0, double t)
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.
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
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...
unsigned int getHeight() const
Return the number of rows in the image.
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 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.
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)
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.
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)
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(vpHomogeneousMatrix *)=NULL)
void setFileName(const char *filename)
unsigned int getWidth() const
Return the number of columns in the image.
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)
vpImagePoint getCog() const
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)
void setGraphics(const bool activate)