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"
89 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
92 Test augmented reality using the vpAROgre class.\n\
95 %s [-i <test image path>] [-p <personal image path>]\n\
100 -i <input image path> %s\n\
101 Set image input path.\n\
102 From this path read images \n\
103 \"ViSP-images/mire-2/image.%%04d.pgm\". These \n\
104 images come from ViSP-images-x.y.z.tar.gz available \n\
105 on the ViSP website.\n\
106 Setting the VISP_INPUT_IMAGE_PATH environment\n\
107 variable produces the same behaviour than using\n\
110 -p <personal image path> %s\n\
111 Specify a personal sequence containing images \n\
113 By image sequence, we mean one file per image.\n\
114 The following image file formats PNM (PGM P5, PPM P6)\n\
115 are supported. The format is selected by analysing \n\
116 the filename extension.\n\
117 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\
118 %%04d is for the image numbering.\n\
121 Disable the mouse click. Useful to automaze the \n\
122 execution of this program without humain intervention.\n\
126 ipath.c_str(), ppath.c_str());
129 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
144 bool getOptions(
int argc,
const char **argv, std::string &ipath,
145 std::string &ppath,
bool &click_allowed)
152 case 'c': click_allowed =
false;
break;
153 case 'i': ipath = optarg;
break;
154 case 'p': ppath = optarg;
break;
155 case 'h': usage(argv[0], NULL, ipath, ppath);
159 usage(argv[0], optarg, ipath, ppath);
164 if ((c == 1) || (c == -1)) {
166 usage(argv[0], NULL, ipath, ppath);
167 std::cerr <<
"ERROR: " << std::endl;
168 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
176 #ifndef DOXYGEN_SHOULD_SKIP_THIS
178 class vpAROgreExample :
public vpAROgre
183 unsigned int width = 640,
unsigned int height = 480,
184 const char *resourcePath=NULL)
187 if (resourcePath) mResourcePath = resourcePath;
188 std::cout <<
"mResourcePath: " << mResourcePath<< std::endl;
189 vecDevant = Ogre::Vector3(0,-1,0);
191 mAnimationState = NULL;
198 Ogre::Vector3 vecDevant;
200 Ogre::AnimationState * mAnimationState;
208 mSceneMgr->setAmbientLight(Ogre::ColourValue((
float)0.6,(
float)0.6,(
float)0.6));
209 Ogre::Light * light = mSceneMgr->createLight();
210 light->setDiffuseColour(1.0,1.0,1.0);
211 light->setSpecularColour(1.0,1.0,1.0);
213 light->setPosition(-5, -5, 10);
214 light->setType(Ogre::Light::LT_POINT);
215 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
217 light->setCastShadows(
true);
220 robot = mSceneMgr->createEntity(
"Robot",
"robot.mesh");
222 Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Robot");
223 RobotNode->attachObject(robot);
224 RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001);
225 RobotNode->pitch(Ogre::Degree(90));
226 RobotNode->yaw(Ogre::Degree(-90));
227 robot->setCastShadows(
true);
228 mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
232 mAnimationState = robot->getAnimationState(
"Idle" );
234 mAnimationState->setLoop(
true );
236 mAnimationState->setEnabled(
true );
241 plan.normal = Ogre::Vector3::UNIT_Z;
242 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);
243 Ogre::Entity* ent = mSceneMgr->createEntity(
"Entitesol",
"sol");
244 Ogre::SceneNode* PlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Entitesol");
245 PlaneNode->attachObject(ent);
246 ent->setMaterialName(
"Examples/GrassFloor");
252 mAnimationState->addTime( evt.timeSinceLastFrame );
258 mKeyboard->capture();
260 double angle = -M_PI/8;
261 if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
267 if(mKeyboard->isKeyDown(OIS::KC_Z) || mKeyboard->isKeyDown(OIS::KC_UP)){
268 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition()+(Ogre::Real)0.003*vecDevant);
271 if(mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)){
272 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition()-(Ogre::Real)0.003*vecDevant);
275 if(mKeyboard->isKeyDown(OIS::KC_Q) || mKeyboard->isKeyDown(OIS::KC_LEFT)){
276 rotmy = Ogre::Matrix3((Ogre::Real)cos(-angle), (Ogre::Real)sin(-angle), 0,
277 (Ogre::Real)(-sin(-angle)), (Ogre::Real)cos(-angle),0,
279 vecDevant=vecDevant*rotmy;
280 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)(-angle)));
283 if(mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)){
284 rotmy = Ogre::Matrix3((Ogre::Real)cos(angle), (Ogre::Real)sin(angle), 0,
285 (Ogre::Real)(-sin(angle)), (Ogre::Real)cos(angle),0,
287 vecDevant=vecDevant*rotmy;
288 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)angle));
294 mAnimationState = robot->getAnimationState(
"Walk");
296 else mAnimationState = robot->getAnimationState(
"Idle" );
299 mAnimationState->setLoop(
true );
301 mAnimationState->setEnabled(
true );
315 const bool &opt_click_allowed)
320 bool opt_display =
true;
323 #if defined(VISP_HAVE_X11) && ! (defined(__APPLE__) && defined(__MACH__))
329 #elif defined VISP_HAVE_GTK
331 #elif defined VISP_HAVE_GDI
333 #elif defined VISP_HAVE_OPENCV
335 #elif defined VISP_HAVE_D3D9
338 for (
unsigned int i=0 ; i < 4 ; i++)
351 display.
init(I,100,100,
"Preliminary Pose Calculation");
369 std::cout<<
"************************************************************************************"<<std::endl;
370 std::cout<<
"*************************** Preliminary Pose Calculation ***************************"<<std::endl;
371 std::cout<<
"****************************** Click on the 4 dots *******************************"<<std::endl;
372 std::cout<<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), Dot4 : (-x,y,0)**********"<<std::endl;
373 std::cout<<
"************************************************************************************"<<std::endl;
377 if (! opt_click_allowed) {
387 for(
unsigned int i=0;i<4;i++) {
397 for(
unsigned int j = 0;j<i;j++)
403 if (opt_click_allowed)
447 for (
unsigned int i=0 ; i < 4 ; i++)
470 for (
unsigned int i=0 ; i < 4 ; i++)
486 for (
unsigned int i=0 ; i < 4 ; i++)
512 int main(
int argc,
const char **argv)
515 std::string env_ipath;
516 std::string opt_ipath;
518 std::string opt_ppath;
520 std::string filename;
521 bool opt_click_allowed =
true;
527 if (! env_ipath.empty())
531 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
536 if (!opt_ipath.empty())
541 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
542 if (ipath != env_ipath) {
543 std::cout << std::endl
544 <<
"WARNING: " << std::endl;
545 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
546 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
547 <<
" we skip the environment variable." << std::endl;
552 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty() ){
553 usage(argv[0], NULL, ipath, opt_ppath);
554 std::cerr << std::endl
555 <<
"ERROR:" << std::endl;
556 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
558 <<
" environment variable to specify the location of the " << std::endl
559 <<
" image path where test images are located." << std::endl
560 <<
" Use -p <personal image path> option if you want to "<<std::endl
561 <<
" use personal images." << std::endl
567 std::ostringstream s;
569 if (opt_ppath.empty()){
575 s.setf(std::ios::right, std::ios::adjustfield);
576 s <<
"image.%04d.pgm";
580 filename = opt_ppath;
613 vpCTRACE <<
"Load: " << filename << std::endl;
614 grabber.
open(Idisplay);
618 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP,
633 std::cerr << std::endl
634 <<
"ERROR:" << std::endl;
635 std::cerr <<
" Cannot read " << filename << std::endl;
636 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
637 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
643 vpAROgreExample ogre(mcam, (
unsigned int)grabber.
getWidth(), (
unsigned int)grabber.
getHeight());
650 while(ogre.continueRendering() && !grabber.
end()) {
661 for (
int i=0 ; i < 4 ; i++)
664 md[i].
track(I, mcog[i]) ;
685 ogre.display(IC,cMo);
689 std::cout <<
"\r> " << 1000 / (t1 - t0) <<
" fps" ;
698 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
701 catch(Ogre::Exception e) {
702 std::cout <<
"Catch an Ogre exception: " << e.getDescription() << std::endl;
706 std::cout <<
"Catch an exception " << std::endl;
710 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY
714 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.
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.
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 &)
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)
VISP_EXPORT double measureTimeMs()
void set_j(const double jj)
void setSizePrecision(const double &sizePrecision)
void setWorldCoordinates(const double oX, const double oY, const double oZ)
virtual void createScene(void)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
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 clearPoint()
suppress all the point in the array of point