43 #include <visp3/core/vpConfig.h>
48 #if defined(VISP_HAVE_OGRE) && \
49 (defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_GTK) || \
50 (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/ar/vpAROgre.h>
61 #include <visp3/blob/vpDot2.h>
62 #include <visp3/core/vpDebug.h>
63 #include <visp3/core/vpImagePoint.h>
64 #include <visp3/core/vpIoTools.h>
65 #include <visp3/core/vpPixelMeterConversion.h>
66 #include <visp3/core/vpPoint.h>
67 #include <visp3/gui/vpDisplayD3D.h>
68 #include <visp3/gui/vpDisplayGDI.h>
69 #include <visp3/gui/vpDisplayGTK.h>
70 #include <visp3/gui/vpDisplayOpenCV.h>
71 #include <visp3/io/vpParseArgv.h>
72 #include <visp3/io/vpVideoReader.h>
73 #include <visp3/vision/vpPose.h>
76 #define GETOPTARGS "ci:p:h"
89 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
91 #if VISP_HAVE_DATASET_VERSION >= 0x030600
92 std::string ext(
"png");
94 std::string ext(
"pgm");
98 Test augmented reality using the vpAROgre class.\n\
101 %s [-i <test image path>] [-p <personal image path>]\n\
106 -i <input image path> %s\n\
107 Set image input path.\n\
108 From this path read images \n\
109 \"mire-2/image.%%04d.%s\". These \n\
110 images come from visp-images-x.y.z.tar.gz available \n\
111 on the ViSP website.\n\
112 Setting the VISP_INPUT_IMAGE_PATH environment\n\
113 variable produces the same behaviour than using\n\
116 -p <personal image path> %s\n\
117 Specify a personal sequence containing images \n\
119 By image sequence, we mean one file per image.\n\
120 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
121 %%04d is for the image numbering.\n\
124 Disable the mouse click. Useful to automate the \n\
125 execution of this program without human intervention.\n\
129 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str());
132 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
147 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed)
155 click_allowed =
false;
164 usage(argv[0],
nullptr, ipath, ppath);
169 usage(argv[0], optarg_, ipath, ppath);
175 if ((c == 1) || (c == -1)) {
177 usage(argv[0],
nullptr, ipath, ppath);
178 std::cerr <<
"ERROR: " << std::endl;
179 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
186 #ifndef DOXYGEN_SHOULD_SKIP_THIS
188 class vpAROgreExample :
public vpAROgre
193 unsigned int height = 480,
const char *resourcePath =
nullptr)
198 mResourcePath = resourcePath;
199 std::cout <<
"mResourcePath: " << mResourcePath << std::endl;
200 vecDevant = Ogre::Vector3(0, -1, 0);
202 mAnimationState =
nullptr;
208 Ogre::Vector3 vecDevant;
210 Ogre::AnimationState *mAnimationState;
218 mSceneMgr->setAmbientLight(Ogre::ColourValue((
float)0.6, (
float)0.6, (
float)0.6));
219 Ogre::Light *light = mSceneMgr->createLight();
220 light->setDiffuseColour(1.0, 1.0, 1.0);
221 light->setSpecularColour(1.0, 1.0, 1.0);
223 light->setPosition(-5, -5, 10);
224 light->setType(Ogre::Light::LT_POINT);
225 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
227 light->setCastShadows(
true);
230 robot = mSceneMgr->createEntity(
"Robot",
"robot.mesh");
232 Ogre::SceneNode *RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Robot");
233 RobotNode->attachObject(robot);
234 RobotNode->scale((Ogre::Real)0.001, (Ogre::Real)0.001, (Ogre::Real)0.001);
235 RobotNode->pitch(Ogre::Degree(90));
236 RobotNode->yaw(Ogre::Degree(-90));
237 robot->setCastShadows(
true);
238 mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
242 mAnimationState = robot->getAnimationState(
"Idle");
244 mAnimationState->setLoop(
true);
246 mAnimationState->setEnabled(
true);
251 plan.normal = Ogre::Vector3::UNIT_Z;
252 Ogre::MeshManager::getSingleton().createPlane(
"sol", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plan,
253 (Ogre::Real)0.22, (Ogre::Real)0.16, 10, 10,
true, 1, 1, 1);
254 Ogre::Entity *ent = mSceneMgr->createEntity(
"Entitesol",
"sol");
255 Ogre::SceneNode *PlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Entitesol");
256 PlaneNode->attachObject(ent);
257 ent->setMaterialName(
"Examples/GrassFloor");
264 mAnimationState->addTime(evt.timeSinceLastFrame);
271 mKeyboard->capture();
273 double angle = -M_PI / 8;
274 if (mKeyboard->isKeyDown(OIS::KC_ESCAPE))
281 if (mKeyboard->isKeyDown(OIS::KC_Z) || mKeyboard->isKeyDown(OIS::KC_UP)) {
282 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition() +
283 (Ogre::Real)0.003 * vecDevant);
286 if (mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)) {
287 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition() -
288 (Ogre::Real)0.003 * vecDevant);
291 if (mKeyboard->isKeyDown(OIS::KC_Q) || mKeyboard->isKeyDown(OIS::KC_LEFT)) {
292 rotmy = Ogre::Matrix3((Ogre::Real)cos(-angle), (Ogre::Real)sin(-angle), 0, (Ogre::Real)(-sin(-angle)),
293 (Ogre::Real)cos(-angle), 0, 0, 0, 1);
294 vecDevant = vecDevant * rotmy;
295 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)(-angle)));
298 if (mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)) {
299 rotmy = Ogre::Matrix3((Ogre::Real)cos(angle), (Ogre::Real)sin(angle), 0, (Ogre::Real)(-sin(angle)),
300 (Ogre::Real)cos(angle), 0, 0, 0, 1);
301 vecDevant = vecDevant * rotmy;
302 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)angle));
308 mAnimationState = robot->getAnimationState(
"Walk");
311 mAnimationState = robot->getAnimationState(
"Idle");
314 mAnimationState->setLoop(
true);
316 mAnimationState->setEnabled(
true);
335 bool opt_display =
true;
338 #if defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__))
344 #elif defined(VISP_HAVE_GTK)
346 #elif defined(VISP_HAVE_GDI)
348 #elif defined(HAVE_OPENCV_HIGHGUI)
350 #elif defined(VISP_HAVE_D3D9)
353 for (
unsigned int i = 0; i < 4; i++) {
365 display.init(I, 100, 100,
"Preliminary Pose Calculation");
382 std::cout <<
"*************************************************************"
383 "***********************"
385 std::cout <<
"*************************** Preliminary Pose Calculation "
386 "***************************"
388 std::cout <<
"****************************** Click on the 4 dots "
389 "*******************************"
391 std::cout <<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), "
392 "Dot4 : (-x,y,0)**********"
394 std::cout <<
"*************************************************************"
395 "***********************"
400 if (!opt_click_allowed) {
410 for (
unsigned int i = 0; i < 4; i++) {
420 for (
unsigned int j = 0; j < i; j++)
426 if (opt_click_allowed)
471 for (
unsigned int i = 0; i < 4; i++)
494 for (
unsigned int i = 0; i < 4; i++) {
508 for (
unsigned int i = 0; i < 4; i++) {
529 int main(
int argc,
const char **argv)
531 #if VISP_HAVE_DATASET_VERSION >= 0x030600
532 std::string ext(
"png");
534 std::string ext(
"pgm");
537 std::string env_ipath;
538 std::string opt_ipath;
540 std::string opt_ppath;
542 std::string filename;
543 bool opt_click_allowed =
true;
550 if (!env_ipath.empty())
554 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
559 if (!opt_ipath.empty())
564 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
565 if (ipath != env_ipath) {
566 std::cout << std::endl <<
"WARNING: " << std::endl;
567 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
568 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
569 <<
" we skip the environment variable." << std::endl;
574 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
575 usage(argv[0],
nullptr, ipath, opt_ppath);
576 std::cerr << std::endl <<
"ERROR:" << std::endl;
577 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
578 <<
" environment variable to specify the location of the " << std::endl
579 <<
" image path where test images are located." << std::endl
580 <<
" Use -p <personal image path> option if you want to " << std::endl
581 <<
" use personal images." << std::endl
587 std::ostringstream s;
589 if (opt_ppath.empty()) {
595 s.setf(std::ios::right, std::ios::adjustfield);
601 filename = opt_ppath;
629 vpCTRACE <<
"Load: " << filename << std::endl;
630 grabber.
open(Idisplay);
634 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";
705 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
708 catch (Ogre::Exception &e) {
709 std::cout <<
"Catch an Ogre exception: " << e.getDescription() << std::endl;
713 std::cout <<
"Catch an exception " << std::endl;
720 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)))
721 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
723 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
724 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
725 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
726 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
728 std::cout <<
"You do not have Ogre functionalities" << std::endl;
729 std::cout <<
"Tip:" << std::endl;
730 std::cout <<
"- Install Ogre3D, configure again ViSP using cmake and build again this example" << std::endl;
Implementation of an augmented reality viewer using Ogre3D 3rd party.
virtual bool customframeEnded(const Ogre::FrameEvent &evt)
virtual bool processInputEvent(const Ogre::FrameEvent &)
virtual void createScene(void)
Generic class defining intrinsic camera parameters.
void init()
Basic initialization with the default parameters.
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
void track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
void setGraphics(bool activate)
void display(const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
void setSizePrecision(const double &sizePrecision)
void setGrayLevelPrecision(const double &grayLevelPrecision)
vpImagePoint getCog() const
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
error that can be emitted by ViSP classes.
unsigned int getWidth() const
Return the number of columns in the image.
unsigned int getHeight() const
Return the number of rows in the image.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void set_x(double x)
Set the point x coordinate in the image plane.
void setWorldCoordinates(double oX, double oY, double oZ)
void set_y(double y)
Set the point y coordinate in the image plane.
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
void addPoint(const vpPoint &P)
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, bool(*func)(const vpHomogeneousMatrix &)=nullptr)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeMs()