46 #include <visp3/core/vpConfig.h> 51 #if defined(VISP_HAVE_OGRE) && \ 52 (defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK) || \ 53 (defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__)))) 56 #if defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__)) 61 #include <visp3/gui/vpDisplayX.h> 63 #include <visp3/ar/vpAROgre.h> 64 #include <visp3/blob/vpDot2.h> 65 #include <visp3/core/vpDebug.h> 66 #include <visp3/core/vpImagePoint.h> 67 #include <visp3/core/vpIoTools.h> 68 #include <visp3/core/vpPixelMeterConversion.h> 69 #include <visp3/core/vpPoint.h> 70 #include <visp3/gui/vpDisplayD3D.h> 71 #include <visp3/gui/vpDisplayGDI.h> 72 #include <visp3/gui/vpDisplayGTK.h> 73 #include <visp3/gui/vpDisplayOpenCV.h> 74 #include <visp3/io/vpParseArgv.h> 75 #include <visp3/io/vpVideoReader.h> 76 #include <visp3/vision/vpPose.h> 79 #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 \"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\ 128 Print the help.\n", ipath.c_str(), ppath.c_str());
131 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
146 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed)
154 click_allowed =
false;
163 usage(argv[0], NULL, ipath, ppath);
168 usage(argv[0], optarg, ipath, ppath);
174 if ((c == 1) || (c == -1)) {
176 usage(argv[0], NULL, ipath, ppath);
177 std::cerr <<
"ERROR: " << std::endl;
178 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
185 #ifndef DOXYGEN_SHOULD_SKIP_THIS 187 class vpAROgreExample :
public vpAROgre 192 unsigned int height = 480,
const char *resourcePath = NULL)
197 mResourcePath = resourcePath;
198 std::cout <<
"mResourcePath: " << mResourcePath << std::endl;
199 vecDevant = Ogre::Vector3(0, -1, 0);
201 mAnimationState = NULL;
207 Ogre::Vector3 vecDevant;
209 Ogre::AnimationState *mAnimationState;
217 mSceneMgr->setAmbientLight(Ogre::ColourValue((
float)0.6, (
float)0.6, (
float)0.6));
218 Ogre::Light *light = mSceneMgr->createLight();
219 light->setDiffuseColour(1.0, 1.0, 1.0);
220 light->setSpecularColour(1.0, 1.0, 1.0);
222 light->setPosition(-5, -5, 10);
223 light->setType(Ogre::Light::LT_POINT);
224 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
226 light->setCastShadows(
true);
229 robot = mSceneMgr->createEntity(
"Robot",
"robot.mesh");
231 Ogre::SceneNode *RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Robot");
232 RobotNode->attachObject(robot);
233 RobotNode->scale((Ogre::Real)0.001, (Ogre::Real)0.001, (Ogre::Real)0.001);
234 RobotNode->pitch(Ogre::Degree(90));
235 RobotNode->yaw(Ogre::Degree(-90));
236 robot->setCastShadows(
true);
237 mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
241 mAnimationState = robot->getAnimationState(
"Idle");
243 mAnimationState->setLoop(
true);
245 mAnimationState->setEnabled(
true);
250 plan.normal = Ogre::Vector3::UNIT_Z;
251 Ogre::MeshManager::getSingleton().createPlane(
"sol", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plan,
252 (Ogre::Real)0.22, (Ogre::Real)0.16, 10, 10,
true, 1, 1, 1);
253 Ogre::Entity *ent = mSceneMgr->createEntity(
"Entitesol",
"sol");
254 Ogre::SceneNode *PlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Entitesol");
255 PlaneNode->attachObject(ent);
256 ent->setMaterialName(
"Examples/GrassFloor");
263 mAnimationState->addTime(evt.timeSinceLastFrame);
270 mKeyboard->capture();
272 double angle = -M_PI / 8;
273 if (mKeyboard->isKeyDown(OIS::KC_ESCAPE))
280 if (mKeyboard->isKeyDown(OIS::KC_Z) || mKeyboard->isKeyDown(OIS::KC_UP)) {
281 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition() +
282 (Ogre::Real)0.003 * vecDevant);
285 if (mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)) {
286 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition() -
287 (Ogre::Real)0.003 * vecDevant);
290 if (mKeyboard->isKeyDown(OIS::KC_Q) || mKeyboard->isKeyDown(OIS::KC_LEFT)) {
291 rotmy = Ogre::Matrix3((Ogre::Real)cos(-angle), (Ogre::Real)sin(-angle), 0, (Ogre::Real)(-sin(-angle)),
292 (Ogre::Real)cos(-angle), 0, 0, 0, 1);
293 vecDevant = vecDevant * rotmy;
294 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)(-angle)));
297 if (mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)) {
298 rotmy = Ogre::Matrix3((Ogre::Real)cos(angle), (Ogre::Real)sin(angle), 0, (Ogre::Real)(-sin(angle)),
299 (Ogre::Real)cos(angle), 0, 0, 0, 1);
300 vecDevant = vecDevant * rotmy;
301 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)angle));
307 mAnimationState = robot->getAnimationState(
"Walk");
309 mAnimationState = robot->getAnimationState(
"Idle");
312 mAnimationState->setLoop(
true);
314 mAnimationState->setEnabled(
true);
333 bool opt_display =
true;
336 #if defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__)) 342 #elif defined VISP_HAVE_GTK 344 #elif defined VISP_HAVE_GDI 346 #elif defined VISP_HAVE_OPENCV 348 #elif defined VISP_HAVE_D3D9 351 for (
unsigned int i = 0; i < 4; i++) {
362 display.
init(I, 100, 100,
"Preliminary Pose Calculation");
378 std::cout <<
"*************************************************************" 379 "***********************" 381 std::cout <<
"*************************** Preliminary Pose Calculation " 382 "***************************" 384 std::cout <<
"****************************** Click on the 4 dots " 385 "*******************************" 387 std::cout <<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), " 388 "Dot4 : (-x,y,0)**********" 390 std::cout <<
"*************************************************************" 391 "***********************" 396 if (!opt_click_allowed) {
406 for (
unsigned int i = 0; i < 4; i++) {
416 for (
unsigned int j = 0; j < i; j++)
422 if (opt_click_allowed)
465 for (
unsigned int i = 0; i < 4; i++)
488 for (
unsigned int i = 0; i < 4; i++) {
502 for (
unsigned int i = 0; i < 4; i++) {
527 int main(
int argc,
const char **argv)
530 std::string env_ipath;
531 std::string opt_ipath;
533 std::string opt_ppath;
535 std::string filename;
536 bool opt_click_allowed =
true;
543 if (!env_ipath.empty())
547 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
552 if (!opt_ipath.empty())
557 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
558 if (ipath != env_ipath) {
559 std::cout << std::endl <<
"WARNING: " << std::endl;
560 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 561 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
562 <<
" we skip the environment variable." << std::endl;
567 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
568 usage(argv[0], NULL, ipath, opt_ppath);
569 std::cerr << std::endl <<
"ERROR:" << std::endl;
570 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
571 <<
" environment variable to specify the location of the " << std::endl
572 <<
" image path where test images are located." << std::endl
573 <<
" Use -p <personal image path> option if you want to " << std::endl
574 <<
" use personal images." << std::endl
580 std::ostringstream s;
582 if (opt_ppath.empty()) {
588 s.setf(std::ios::right, std::ios::adjustfield);
589 s <<
"image.%04d.pgm";
592 filename = opt_ppath;
626 vpCTRACE <<
"Load: " << filename << std::endl;
627 grabber.
open(Idisplay);
631 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP, opt_click_allowed);
643 std::cerr << std::endl <<
"ERROR:" << std::endl;
644 std::cerr <<
" Cannot read " << filename << std::endl;
645 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
646 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
651 vpAROgreExample ogre(mcam, (
unsigned int)grabber.
getWidth(), (
unsigned int)grabber.
getHeight());
658 while (ogre.continueRendering() && !grabber.
end()) {
669 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";
704 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
706 }
catch (Ogre::Exception &e) {
707 std::cout <<
"Catch an Ogre exception: " << e.getDescription() << std::endl;
710 std::cout <<
"Catch an exception " << std::endl;
714 #else // VISP_HAVE_OGRE && VISP_HAVE_DISPLAY 717 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))) 718 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
719 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
720 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
721 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
722 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
724 std::cout <<
"You do not have Ogre functionalities" << std::endl;
725 std::cout <<
"Tip:" << std::endl;
726 std::cout <<
"- Install Ogre3D, configure again ViSP using cmake and build again this example" << std::endl;
VISP_EXPORT int wait(double t0, double t)
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=NULL)
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).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
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)
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)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
VISP_EXPORT double measureTimeMs()
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 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)
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. Thus to enable this class OpenC...
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). 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)
void setFileName(const char *filename)
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)
virtual void createScene(void)
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
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)
unsigned int getHeight() const
Return the number of rows in the image.
void setGraphics(const bool activate)