41#include <visp3/core/vpConfig.h>
43#if defined(VISP_HAVE_OGRE) && defined(VISP_HAVE_DISPLAY)
45#include <visp3/ar/vpAROgre.h>
46#include <visp3/blob/vpDot2.h>
47#include <visp3/core/vpDebug.h>
48#include <visp3/core/vpImagePoint.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/core/vpPixelMeterConversion.h>
51#include <visp3/core/vpPoint.h>
52#include <visp3/gui/vpDisplayFactory.h>
53#include <visp3/io/vpParseArgv.h>
54#include <visp3/io/vpVideoReader.h>
55#include <visp3/vision/vpPose.h>
58#define GETOPTARGS "ci:p:h"
60#ifdef ENABLE_VISP_NAMESPACE
72void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath)
74#if defined(VISP_HAVE_DATASET)
75#if VISP_HAVE_DATASET_VERSION >= 0x030600
76 std::string ext(
"png");
78 std::string ext(
"pgm");
82 std::string ext(
"png");
86Test augmented reality using the vpAROgre class.\n\
89 %s [-i <test image path>] [-p <personal image path>]\n\
94 -i <input image path> %s\n\
95 Set image input path.\n\
96 From this path read images \n\
97 \"mire-2/image.%%04d.%s\". These \n\
98 images come from visp-images-x.y.z.tar.gz available \n\
99 on the ViSP website.\n\
100 Setting the VISP_INPUT_IMAGE_PATH environment\n\
101 variable produces the same behaviour than using\n\
104 -p <personal image path> %s\n\
105 Specify a personal sequence containing images \n\
107 By image sequence, we mean one file per image.\n\
108 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
109 %%04d is for the image numbering.\n\
112 Disable the mouse click. Useful to automate the \n\
113 execution of this program without human intervention.\n\
117 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str());
120 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
134bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed)
142 click_allowed =
false;
151 usage(argv[0],
nullptr, ipath, ppath);
155 usage(argv[0], optarg_, ipath, ppath);
160 if ((c == 1) || (c == -1)) {
162 usage(argv[0],
nullptr, ipath, ppath);
163 std::cerr <<
"ERROR: " << std::endl;
164 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
171#ifndef DOXYGEN_SHOULD_SKIP_THIS
173class vpAROgreExample :
public vpAROgre
177 vpAROgreExample(
const vpCameraParameters &cam = vpCameraParameters(),
unsigned int width = 640,
178 unsigned int height = 480,
const char *resourcePath =
nullptr)
183 mResourcePath = resourcePath;
184 std::cout <<
"mResourcePath: " << mResourcePath << std::endl;
185 vecDevant = Ogre::Vector3(0, -1, 0);
187 mAnimationState =
nullptr;
193 Ogre::Vector3 vecDevant;
195 Ogre::AnimationState *mAnimationState;
204 mSceneMgr->setAmbientLight(Ogre::ColourValue(
static_cast<float>(0.6),
static_cast<float>(0.6),
static_cast<float>(0.6)));
205 Ogre::Light *light = mSceneMgr->createLight();
206 light->setDiffuseColour(1.0, 1.0, 1.0);
207 light->setSpecularColour(1.0, 1.0, 1.0);
209#if (VISP_HAVE_OGRE_VERSION < (1 << 16 | 10 << 8 | 0))
210 light->setPosition(-5, -5, 10);
212 Ogre::SceneNode *spotLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
213 spotLightNode->attachObject(light);
214 spotLightNode->setPosition(Ogre::Vector3(-5, -5, 10));
216 light->setType(Ogre::Light::LT_POINT);
217 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
219 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);
238 mAnimationState = robot->getAnimationState(
"Idle");
240 mAnimationState->setLoop(
true);
242 mAnimationState->setEnabled(
true);
249 plan.normal = Ogre::Vector3::UNIT_Z;
250 Ogre::MeshManager::getSingleton().createPlane(
"sol", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plan,
251 (Ogre::Real)0.22, (Ogre::Real)0.16, 10, 10,
true, 1, 1, 1);
252 Ogre::Entity *ent = mSceneMgr->createEntity(
"Entitesol",
"sol");
253 Ogre::SceneNode *PlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
"Entitesol");
254 PlaneNode->attachObject(ent);
255 ent->setMaterialName(
"Examples/GrassFloor");
264 mAnimationState->addTime(evt.timeSinceLastFrame);
273 mKeyboard->capture();
275 double angle = -M_PI / 8;
276 if (mKeyboard->isKeyDown(OIS::KC_ESCAPE))
283 if (mKeyboard->isKeyDown(OIS::KC_Z) || mKeyboard->isKeyDown(OIS::KC_UP)) {
284 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition() +
285 (Ogre::Real)0.003 * vecDevant);
288 if (mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)) {
289 mSceneMgr->getSceneNode(
"Robot")->setPosition(mSceneMgr->getSceneNode(
"Robot")->getPosition() -
290 (Ogre::Real)0.003 * vecDevant);
293 if (mKeyboard->isKeyDown(OIS::KC_Q) || mKeyboard->isKeyDown(OIS::KC_LEFT)) {
294 rotmy = Ogre::Matrix3((Ogre::Real)cos(-angle), (Ogre::Real)sin(-angle), 0, (Ogre::Real)(-sin(-angle)),
295 (Ogre::Real)cos(-angle), 0, 0, 0, 1);
296 vecDevant = vecDevant * rotmy;
297 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)(-angle)));
300 if (mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)) {
301 rotmy = Ogre::Matrix3((Ogre::Real)cos(angle), (Ogre::Real)sin(angle), 0, (Ogre::Real)(-sin(angle)),
302 (Ogre::Real)cos(angle), 0, 0, 0, 1);
303 vecDevant = vecDevant * rotmy;
304 mSceneMgr->getSceneNode(
"Robot")->yaw(Ogre::Radian((Ogre::Real)angle));
310 mAnimationState = robot->getAnimationState(
"Walk");
313 mAnimationState = robot->getAnimationState(
"Idle");
316 mAnimationState->setLoop(
true);
318 mAnimationState->setEnabled(
true);
338 bool opt_display =
true;
342#if defined(VISP_HAVE_DISPLAY)
349 for (
unsigned int i = 0;
i < 4; ++
i) {
360 display->init(I, 100, 100,
"Preliminary Pose Calculation");
371 std::cout <<
"**"<< std::endl;
372 std::cout <<
"** Preliminary Pose Calculation" << std::endl;
373 std::cout <<
"** Click on the 4 dots" << std::endl;
374 std::cout <<
"** Dot1: (-x,-y,0), Dot2: (x,-y,0), Dot3: (x,y,0), Dot4: (-x,y,0)" << std::endl;
375 std::cout <<
"**" << std::endl;
378 if (!opt_click_allowed) {
388 for (
unsigned int i = 0;
i < 4; ++
i) {
398 for (
unsigned int j = 0;
j <
i;
j++)
404 if (opt_click_allowed)
441 for (
unsigned int i = 0;
i < 4; ++
i) {
465 for (
unsigned int i = 0;
i < 4; ++
i) {
479 for (
unsigned int i = 0;
i < 4; ++
i) {
500int main(
int argc,
const char **argv)
502#if defined(VISP_HAVE_DATASET)
503#if VISP_HAVE_DATASET_VERSION >= 0x030600
504 std::string ext(
"png");
506 std::string ext(
"pgm");
510 std::string ext(
"png");
514 std::string env_ipath;
515 std::string opt_ipath;
517 std::string opt_ppath;
520 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 <<
"WARNING: " << std::endl;
544 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
545 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
546 <<
" we skip the environment variable." << std::endl;
551 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
552 usage(argv[0],
nullptr, ipath, opt_ppath);
553 std::cerr << std::endl <<
"ERROR:" << std::endl;
554 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
555 <<
" environment variable to specify the location of the " << std::endl
556 <<
" image path where test images are located." << std::endl
557 <<
" Use -p <personal image path> option if you want to " << std::endl
558 <<
" use personal images." << std::endl
564 std::ostringstream
s;
566 if (opt_ppath.empty()) {
572 s.setf(std::ios::right, std::ios::adjustfield);
606 std::cout <<
"Load: " <<
filename << std::endl;
607 grabber.
open(Idisplay);
611 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP, opt_click_allowed);
620 std::cerr << std::endl <<
"ERROR:" << std::endl;
621 std::cerr <<
" Cannot read " <<
filename << std::endl;
622 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
623 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
629 vpAROgreExample ogre(mcam,
static_cast<unsigned int>(grabber.
getWidth()),
static_cast<unsigned int>(grabber.
getHeight()));
631 bool bufferedKeys =
false, hidden =
false;
632 ogre.init(IC, bufferedKeys, hidden);
638 while (ogre.continueRendering() && !grabber.
end() && !quit) {
652 for (
int i = 0;
i < 4; ++
i) {
677 ogre.display(IC, cMo);
685 std::cout <<
"\r> " << 1000 / (
t1 - t0) <<
" fps";
695 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
698 catch (Ogre::Exception &e) {
699 std::cout <<
"Catch an Ogre exception: " <<
e.getDescription() << std::endl;
703 std::cout <<
"Catch an exception " << std::endl;
710#if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)))
711 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
713 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
714 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
715 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
716 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
718 std::cout <<
"You do not have Ogre functionalities" << std::endl;
719 std::cout <<
"Tip:" << std::endl;
720 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.
Class that defines generic functionalities for display.
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 ...
Definition of the vpImage class member functions.
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
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)