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"
93 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
96 Test augmented reality using the vpAROgre class.\n\
99 %s [-i <test image path>] [-p <personal image path>]\n\
104 -i <input image path> %s\n\
105 Set image input path.\n\
106 From this path read images \n\
107 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
108 images come from ViSP-images-x.y.z.tar.gz available \n\
109 on the ViSP website.\n\
110 Setting the VISP_INPUT_IMAGE_PATH environment\n\
111 variable produces the same behaviour than using\n\
114 -p <personal image path> %s\n\
115 Specify a personal sequence containing images \n\
117 By image sequence, we mean one file per image.\n\
118 The following image file formats PNM (PGM P5, PPM P6)\n\
119 are supported. The format is selected by analysing \n\
120 the filename extension.\n\
121 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
122 %%04d is for the image numbering.\n\
125 Disable the mouse click. Useful to automaze the \n\
126 execution of this program without humain intervention.\n\
130 ipath.c_str(), ppath.c_str());
133 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
148 bool getOptions(
int argc,
const char **argv, std::string &ipath,
149 std::string &ppath,
bool &click_allowed)
156 case 'c': click_allowed =
false;
break;
157 case 'i': ipath = optarg;
break;
158 case 'p': ppath = optarg;
break;
159 case 'h': usage(argv[0], NULL, ipath, ppath);
163 usage(argv[0], optarg, ipath, ppath);
168 if ((c == 1) || (c == -1)) {
170 usage(argv[0], NULL, ipath, ppath);
171 std::cerr <<
"ERROR: " << std::endl;
172 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
180 #ifndef DOXYGEN_SHOULD_SKIP_THIS
182 class vpAROgreExample :
public vpAROgre
187 unsigned int width = 640,
unsigned int height = 480,
188 const char *resourcePath=NULL)
191 if (resourcePath) mResourcePath = resourcePath;
192 std::cout <<
"mResourcePath: " << mResourcePath<< std::endl;
193 vecDevant = Ogre::Vector3(0,-1,0);
195 mAnimationState = NULL;
202 Ogre::Vector3 vecDevant;
204 Ogre::AnimationState * mAnimationState;
212 mSceneMgr->setAmbientLight(Ogre::ColourValue((
float)0.6,(
float)0.6,(
float)0.6));
213 Ogre::Light * light = mSceneMgr->createLight();
214 light->setDiffuseColour(1.0,1.0,1.0);
215 light->setSpecularColour(1.0,1.0,1.0);
217 light->setPosition(-5, -5, 10);
218 light->setType(Ogre::Light::LT_POINT);
219 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
221 light->setCastShadows(
true);
224 robot = mSceneMgr->createEntity(
"Robot",
"robot.mesh");
226 Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Robot");
227 RobotNode->attachObject(robot);
228 RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001);
229 RobotNode->pitch(Ogre::Degree(90));
230 RobotNode->yaw(Ogre::Degree(-90));
231 robot->setCastShadows(
true);
232 mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
236 mAnimationState = robot->getAnimationState(
"Idle" );
238 mAnimationState->setLoop(
true );
240 mAnimationState->setEnabled(
true );
245 plan.normal = Ogre::Vector3::UNIT_Z;
246 Ogre::MeshManager::getSingleton().createPlane(
"sol",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plan, (Ogre::Real)0.22, (Ogre::Real)0.16, 10, 10,
true, 1, 1, 1);
247 Ogre::Entity* ent = mSceneMgr->createEntity(
"Entitesol",
"sol");
248 Ogre::SceneNode* PlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Entitesol");
249 PlaneNode->attachObject(ent);
250 ent->setMaterialName(
"Examples/GrassFloor");
256 mAnimationState->addTime( evt.timeSinceLastFrame );
262 mKeyboard->capture();
264 double angle = -M_PI/8;
265 if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
271 if(mKeyboard->isKeyDown(OIS::KC_Z) || mKeyboard->isKeyDown(OIS::KC_UP)){
272 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition()+(Ogre::Real)0.003*vecDevant);
275 if(mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)){
276 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition()-(Ogre::Real)0.003*vecDevant);
279 if(mKeyboard->isKeyDown(OIS::KC_Q) || mKeyboard->isKeyDown(OIS::KC_LEFT)){
280 rotmy = Ogre::Matrix3((Ogre::Real)cos(-angle), (Ogre::Real)sin(-angle), 0,
281 (Ogre::Real)(-sin(-angle)), (Ogre::Real)cos(-angle),0,
283 vecDevant=vecDevant*rotmy;
284 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)(-angle)));
287 if(mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)){
288 rotmy = Ogre::Matrix3((Ogre::Real)cos(angle), (Ogre::Real)sin(angle), 0,
289 (Ogre::Real)(-sin(angle)), (Ogre::Real)cos(angle),0,
291 vecDevant=vecDevant*rotmy;
292 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)angle));
298 mAnimationState = robot->getAnimationState(
"Walk");
300 else mAnimationState = robot->getAnimationState(
"Idle" );
303 mAnimationState->setLoop(
true );
305 mAnimationState->setEnabled(
true );
319 const bool &opt_click_allowed)
324 bool opt_display =
true;
327 #if defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__))
333 #elif defined VISP_HAVE_GTK
335 #elif defined VISP_HAVE_GDI
337 #elif defined VISP_HAVE_OPENCV
339 #elif defined VISP_HAVE_D3D9
342 for (
unsigned int i=0 ; i < 4 ; i++)
355 display.
init(I,100,100,
"Preliminary Pose Calculation");
373 std::cout<<
"************************************************************************************"<<std::endl;
374 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
375 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
376 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
377 std::cout<<
"************************************************************************************"<<std::endl;
381 if (! opt_click_allowed) {
391 for(
unsigned int i=0;i<4;i++) {
401 for(
unsigned int j = 0;j<i;j++)
407 if (opt_click_allowed)
451 for (
unsigned int i=0 ; i < 4 ; i++)
474 for (
unsigned int i=0 ; i < 4 ; i++)
490 for (
unsigned int i=0 ; i < 4 ; i++)
516 int main(
int argc,
const char **argv)
519 std::string env_ipath;
520 std::string opt_ipath;
522 std::string opt_ppath;
524 std::string filename;
525 bool opt_click_allowed =
true;
528 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
533 if (! env_ipath.empty())
538 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
543 if (!opt_ipath.empty())
548 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
549 if (ipath != env_ipath) {
550 std::cout << std::endl
551 <<
"WARNING: " << std::endl;
552 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
553 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
554 <<
" we skip the environment variable." << std::endl;
559 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
560 usage(argv[0], NULL, ipath, opt_ppath);
561 std::cerr << std::endl
562 <<
"ERROR:" << std::endl;
563 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
565 <<
" environment variable to specify the location of the " << std::endl
566 <<
" image path where test images are located." << std::endl
567 <<
" Use -p <personal image path> option if you want to "<<std::endl
568 <<
" use personal images." << std::endl
574 std::ostringstream s;
576 if (opt_ppath.empty()){
582 s.setf(std::ios::right, std::ios::adjustfield);
583 s <<
"image.%04d.pgm";
584 filename = dirname + s.str();
587 filename = opt_ppath;
620 vpCTRACE <<
"Load: " << filename << std::endl;
621 grabber.
open(Idisplay);
625 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP,
640 std::cerr << std::endl
641 <<
"ERROR:" << std::endl;
642 std::cerr <<
" Cannot read " << filename << std::endl;
643 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
644 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
650 vpAROgreExample ogre(mcam, (
unsigned int)grabber.
getWidth(), (
unsigned int)grabber.
getHeight());
657 while(ogre.continueRendering() && !grabber.
end()) {
668 for (
int i=0 ; i < 4 ; i++)
671 md[i].
track(I, mcog[i]) ;
692 ogre.display(IC,cMo);
696 std::cout <<
"\r> " << 1000 / (t1 - t0) <<
" fps" ;
705 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
709 std::cout <<
"Catch an exception " << std::endl;
713 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY
717 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...
virtual bool customframeEnded(const Ogre::FrameEvent &evt)
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 double measureTimeMs()
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.
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)
unsigned int getWidth() const
Return the number of columns in the image.
virtual bool processInputEvent(const Ogre::FrameEvent &)
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)
virtual void createScene(void)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
void setFirstFrameIndex(const long first_frame)
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