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
74 void usage(
const char *name,
const char *badparam, std::string ipath, 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");
88 Test 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);
140 bool 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);
165 usage(argv[0], optarg_, ipath, ppath);
171 if ((c == 1) || (c == -1)) {
173 usage(argv[0],
nullptr, ipath, ppath);
174 std::cerr <<
"ERROR: " << std::endl;
175 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
193 #if defined(VISP_HAVE_DISPLAY)
200 for (
unsigned int i = 0; i < 4; ++i) {
211 display->init(I, 100, 100,
"Preliminary Pose Calculation");
222 std::cout <<
"**"<< std::endl;
223 std::cout <<
"** Preliminary Pose Calculation" << std::endl;
224 std::cout <<
"** Click on the 4 dots" << std::endl;
225 std::cout <<
"** Dot1: (-x,-y,0), Dot2: (x,-y,0), Dot3: (x,y,0), Dot4: (-x,y,0)" << std::endl;
226 std::cout <<
"**" << std::endl;
229 if (!opt_click_allowed) {
240 for (
unsigned int i = 0; i < 4; ++i) {
250 for (
unsigned int j = 0; j < i; j++)
258 if (opt_click_allowed && opt_display) {
300 for (
unsigned int i = 0; i < 4; ++i) {
324 for (
unsigned int i = 0; i < 4; ++i) {
338 for (
unsigned int i = 0; i < 4; ++i) {
356 if (opt_display && display !=
nullptr) {
361 int main(
int argc,
const char **argv)
363 #if defined(VISP_HAVE_DATASET)
364 #if VISP_HAVE_DATASET_VERSION >= 0x030600
365 std::string ext(
"png");
367 std::string ext(
"pgm");
371 std::string ext(
"png");
375 std::string env_ipath;
376 std::string opt_ipath;
378 std::string opt_ppath;
380 std::string filename;
381 bool opt_click_allowed =
true;
382 bool opt_display =
true;
389 if (!env_ipath.empty())
393 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed, opt_display) ==
false) {
398 if (!opt_ipath.empty())
403 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
404 if (ipath != env_ipath) {
405 std::cout << std::endl <<
"WARNING: " << std::endl;
406 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
407 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
408 <<
" we skip the environment variable." << std::endl;
413 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
414 usage(argv[0],
nullptr, ipath, opt_ppath);
415 std::cerr << std::endl <<
"ERROR:" << std::endl;
416 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
417 <<
" environment variable to specify the location of the " << std::endl
418 <<
" image path where test images are located." << std::endl
419 <<
" Use -p <personal image path> option if you want to " << std::endl
420 <<
" use personal images." << std::endl
426 if (!opt_display && opt_click_allowed) {
427 std::cerr << std::endl <<
"ERROR:" << std::endl;
428 std::cerr <<
" Display is disabled but clicks are required !" << std::endl;
432 std::ostringstream s;
434 if (opt_ppath.empty()) {
440 s.setf(std::ios::right, std::ios::adjustfield);
446 filename = opt_ppath;
474 std::cout <<
"Load: " << filename << std::endl;
475 grabber.
open(Idisplay);
479 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP, opt_click_allowed, opt_display);
488 std::cerr << std::endl <<
"ERROR:" << std::endl;
489 std::cerr <<
" Cannot read " << filename << std::endl;
490 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
491 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
498 ogre.setShowConfigDialog(opt_display);
499 ogre.init(IC,
false, !opt_display);
500 ogre.load(
"Robot",
"robot.mesh");
501 ogre.setScale(
"Robot", 0.001f, 0.001f, 0.001f);
505 ogre.getSceneManager()->setAmbientLight(Ogre::ColourValue((
float)0.6, (
float)0.6, (
float)0.6));
506 Ogre::Light *light = ogre.getSceneManager()->createLight();
507 light->setDiffuseColour(1.0, 1.0, 1.0);
508 light->setSpecularColour(1.0, 1.0, 1.0);
510 #if (VISP_HAVE_OGRE_VERSION < (1 << 16 | 10 << 8 | 0))
511 light->setPosition(-5, -5, 10);
513 Ogre::SceneNode *spotLightNode = ogre.getSceneManager()->getRootSceneNode()->createChildSceneNode();
514 spotLightNode->attachObject(light);
515 spotLightNode->setPosition(Ogre::Vector3(-5, -5, 10));
517 light->setType(Ogre::Light::LT_POINT);
518 light->setAttenuation((Ogre::Real)100, (Ogre::Real)1.0, (Ogre::Real)0.045, (Ogre::Real)0.0075);
520 light->setCastShadows(
true);
523 while (ogre.continueRendering() && !grabber.
end()) {
534 for (
int i = 0; i < 4; ++i) {
536 md[i].
track(I, mcog[i]);
558 ogre.display(IC, cMo);
569 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
572 catch (Ogre::Exception &e) {
573 std::cout <<
"Catch an Ogre exception: " << e.getDescription() << std::endl;
577 std::cout <<
"Catch an exception " << std::endl;
584 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)))
585 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
587 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
588 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
589 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
590 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
592 std::cout <<
"You do not have Ogre functionalities" << std::endl;
593 std::cout <<
"Tip:" << std::endl;
594 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 ...
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 acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void setFirstFrameIndex(const long first_frame)
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)