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 "cdi:p:h"
60#ifdef ENABLE_VISP_NAMESPACE
74void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath)
76#if defined(VISP_HAVE_DATASET)
77#if VISP_HAVE_DATASET_VERSION >= 0x030600
78 std::string ext(
"png");
80 std::string ext(
"pgm");
84 std::string ext(
"png");
88Test augmented reality using the vpAROgre class.\n\
91 %s [-i <test image path>] [-p <personal image path>]\n\
96 -i <input image path> %s\n\
97 Set image input path.\n\
98 From this path read images \n\
99 \"mire-2/image.%%04d.%s\". These \n\
100 images come from ViSP-images-x.y.z.tar.gz available \n\
101 on the ViSP website.\n\
102 Setting the VISP_INPUT_IMAGE_PATH environment\n\
103 variable produces the same behaviour than using\n\
106 -p <personal image path> %s\n\
107 Specify a personal sequence containing images \n\
109 By image sequence, we mean one file per image.\n\
110 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
111 %%04d is for the image numbering.\n\
114 Disable the mouse click. Useful to automate the \n\
115 execution of this program without human intervention.\n\
118 Disable the display.\n\
122 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str());
125 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
140bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
bool &use_display)
148 click_allowed =
false;
160 usage(argv[0],
nullptr, ipath, ppath);
164 usage(argv[0], optarg_, ipath, ppath);
169 if ((c == 1) || (c == -1)) {
171 usage(argv[0],
nullptr, ipath, ppath);
172 std::cerr <<
"ERROR: " << std::endl;
173 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
191#if defined(VISP_HAVE_DISPLAY)
198 for (
unsigned int i = 0;
i < 4; ++
i) {
209 display->init(I, 100, 100,
"Preliminary Pose Calculation");
220 std::cout <<
"**"<< std::endl;
221 std::cout <<
"** Preliminary Pose Calculation" << std::endl;
222 std::cout <<
"** Click on the 4 dots" << std::endl;
223 std::cout <<
"** Dot1: (-x,-y,0), Dot2: (x,-y,0), Dot3: (x,y,0), Dot4: (-x,y,0)" << std::endl;
224 std::cout <<
"**" << std::endl;
227 if (!opt_click_allowed) {
238 for (
unsigned int i = 0;
i < 4; ++
i) {
248 for (
unsigned int j = 0;
j <
i;
j++)
256 if (opt_click_allowed && opt_display) {
298 for (
unsigned int i = 0;
i < 4; ++
i) {
322 for (
unsigned int i = 0;
i < 4; ++
i) {
336 for (
unsigned int i = 0;
i < 4; ++
i) {
354 if (opt_display && display !=
nullptr) {
359int main(
int argc,
const char **argv)
361#if defined(VISP_HAVE_DATASET)
362#if VISP_HAVE_DATASET_VERSION >= 0x030600
363 std::string ext(
"png");
365 std::string ext(
"pgm");
369 std::string ext(
"png");
373 std::string env_ipath;
374 std::string opt_ipath;
376 std::string opt_ppath;
379 bool opt_click_allowed =
true;
380 bool opt_display =
true;
387 if (!env_ipath.empty())
391 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed, opt_display) ==
false) {
396 if (!opt_ipath.empty())
401 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
402 if (ipath != env_ipath) {
403 std::cout << std::endl <<
"WARNING: " << std::endl;
404 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
405 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
406 <<
" we skip the environment variable." << std::endl;
411 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
412 usage(argv[0],
nullptr, ipath, opt_ppath);
413 std::cerr << std::endl <<
"ERROR:" << std::endl;
414 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
415 <<
" environment variable to specify the location of the " << std::endl
416 <<
" image path where test images are located." << std::endl
417 <<
" Use -p <personal image path> option if you want to " << std::endl
418 <<
" use personal images." << std::endl
424 if (!opt_display && opt_click_allowed) {
425 std::cerr << std::endl <<
"ERROR:" << std::endl;
426 std::cerr <<
" Display is disabled but clicks are required !" << std::endl;
430 std::ostringstream
s;
432 if (opt_ppath.empty()) {
438 s.setf(std::ios::right, std::ios::adjustfield);
472 std::cout <<
"Load: " <<
filename << std::endl;
473 grabber.
open(Idisplay);
477 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP, opt_click_allowed, opt_display);
486 std::cerr << std::endl <<
"ERROR:" << std::endl;
487 std::cerr <<
" Cannot read " <<
filename << std::endl;
488 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
489 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
496 ogre.setShowConfigDialog(opt_display);
497 ogre.init(IC,
false, !opt_display);
498 ogre.load(
"Robot",
"robot.mesh");
499 ogre.setScale(
"Robot", 0.001f, 0.001f, 0.001f);
503 ogre.getSceneManager()->setAmbientLight(Ogre::ColourValue(
static_cast<float>(0.6),
static_cast<float>(0.6),
static_cast<float>(0.6)));
504 Ogre::Light *light = ogre.getSceneManager()->createLight();
505 light->setDiffuseColour(1.0, 1.0, 1.0);
506 light->setSpecularColour(1.0, 1.0, 1.0);
508#if (VISP_HAVE_OGRE_VERSION < (1 << 16 | 10 << 8 | 0))
509 light->setPosition(-5, -5, 10);
511 Ogre::SceneNode *spotLightNode = ogre.getSceneManager()->getRootSceneNode()->createChildSceneNode();
512 spotLightNode->attachObject(light);
513 spotLightNode->setPosition(Ogre::Vector3(-5, -5, 10));
515 light->setType(Ogre::Light::LT_POINT);
516 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
518 light->setCastShadows(
true);
521 while (ogre.continueRendering() && !grabber.
end()) {
532 for (
int i = 0;
i < 4; ++
i) {
556 ogre.display(IC, cMo);
567 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
570 catch (Ogre::Exception &e) {
571 std::cout <<
"Catch an Ogre exception: " <<
e.getDescription() << std::endl;
575 std::cout <<
"Catch an exception " << std::endl;
582#if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)))
583 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
585 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
586 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
587 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
588 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
590 std::cout <<
"You do not have Ogre functionalities" << std::endl;
591 std::cout <<
"Tip:" << std::endl;
592 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.
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)
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
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 int wait(double t0, double t)