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"
88 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
90 #if VISP_HAVE_DATASET_VERSION >= 0x030600
91 std::string ext(
"png");
93 std::string ext(
"pgm");
96 Test augmented reality using the vpAROgre class.\n\
99 %s [-i <test image path>] [-p <personal image path>]\n\
104 -i <input image path> %s\n\
105 Set image input path.\n\
106 From this path read images \n\
107 \"mire-2/image.%%04d.%s\". These \n\
108 images come from ViSP-images-x.y.z.tar.gz available \n\
109 on the ViSP website.\n\
110 Setting the VISP_INPUT_IMAGE_PATH environment\n\
111 variable produces the same behaviour than using\n\
114 -p <personal image path> %s\n\
115 Specify a personal sequence containing images \n\
117 By image sequence, we mean one file per image.\n\
118 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
119 %%04d is for the image numbering.\n\
122 Disable the mouse click. Useful to automate the \n\
123 execution of this program without human intervention.\n\
127 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str());
130 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
145 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed)
153 click_allowed =
false;
162 usage(argv[0],
nullptr, ipath, ppath);
167 usage(argv[0], optarg_, ipath, ppath);
173 if ((c == 1) || (c == -1)) {
175 usage(argv[0],
nullptr, ipath, ppath);
176 std::cerr <<
"ERROR: " << std::endl;
177 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
196 bool opt_display =
true;
199 #if defined(VISP_HAVE_X11) && !(defined(__APPLE__) && defined(__MACH__))
205 #elif defined(VISP_HAVE_GTK)
207 #elif defined(VISP_HAVE_GDI)
209 #elif defined(HAVE_OPENCV_HIGHGUI)
211 #elif defined(VISP_HAVE_D3D9)
215 for (
unsigned int i = 0; i < 4; i++) {
227 display.init(I, 100, 100,
"Preliminary Pose Calculation");
244 std::cout <<
"*************************************************************"
245 "***********************"
247 std::cout <<
"*************************** Preliminary Pose Calculation "
248 "***************************"
250 std::cout <<
"****************************** Click on the 4 dots "
251 "*******************************"
253 std::cout <<
"********Dot1 : (-x,-y,0), Dot2 : (x,-y,0), Dot3 : (x,y,0), "
254 "Dot4 : (-x,y,0)**********"
256 std::cout <<
"*************************************************************"
257 "***********************"
262 if (!opt_click_allowed) {
273 for (
unsigned int i = 0; i < 4; i++) {
283 for (
unsigned int j = 0; j < i; j++)
289 if (opt_click_allowed) {
337 for (
unsigned int i = 0; i < 4; i++)
360 for (
unsigned int i = 0; i < 4; i++) {
374 for (
unsigned int i = 0; i < 4; i++) {
393 int main(
int argc,
const char **argv)
395 #if VISP_HAVE_DATASET_VERSION >= 0x030600
396 std::string ext(
"png");
398 std::string ext(
"pgm");
401 std::string env_ipath;
402 std::string opt_ipath;
404 std::string opt_ppath;
406 std::string filename;
407 bool opt_click_allowed =
true;
414 if (!env_ipath.empty())
418 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed) ==
false) {
423 if (!opt_ipath.empty())
428 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
429 if (ipath != env_ipath) {
430 std::cout << std::endl <<
"WARNING: " << std::endl;
431 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
432 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
433 <<
" we skip the environment variable." << std::endl;
438 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
439 usage(argv[0],
nullptr, ipath, opt_ppath);
440 std::cerr << std::endl <<
"ERROR:" << std::endl;
441 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
442 <<
" environment variable to specify the location of the " << std::endl
443 <<
" image path where test images are located." << std::endl
444 <<
" Use -p <personal image path> option if you want to " << std::endl
445 <<
" use personal images." << std::endl
451 std::ostringstream s;
453 if (opt_ppath.empty()) {
459 s.setf(std::ios::right, std::ios::adjustfield);
465 filename = opt_ppath;
493 vpCTRACE <<
"Load: " << filename << std::endl;
494 grabber.
open(Idisplay);
498 computeInitialPose(&mcamTmp, Idisplay, &mPose, md, mcog, &cMo, mP, opt_click_allowed);
507 std::cerr << std::endl <<
"ERROR:" << std::endl;
508 std::cerr <<
" Cannot read " << filename << std::endl;
509 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
510 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
518 ogre.load(
"Robot",
"robot.mesh");
519 ogre.setScale(
"Robot", 0.001f, 0.001f, 0.001f);
523 Ogre::Light *light = ogre.getSceneManager()->createLight();
524 light->setDiffuseColour(1, 1, 1);
525 light->setSpecularColour(1, 1, 1);
526 light->setPosition(-5, -5, 10);
527 light->setType(Ogre::Light::LT_POINT);
530 while (ogre.continueRendering() && !grabber.
end()) {
541 for (
int i = 0; i < 4; i++) {
543 md[i].
track(I, mcog[i]);
564 ogre.display(IC, cMo);
574 std::cout <<
"Catch a ViSP exception: " << e << std::endl;
577 catch (Ogre::Exception &e) {
578 std::cout <<
"Catch an Ogre exception: " << e.getDescription() << std::endl;
582 std::cout <<
"Catch an exception " << std::endl;
589 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)))
590 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
592 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
593 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
594 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
595 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
597 std::cout <<
"You do not have Ogre functionalities" << std::endl;
598 std::cout <<
"Tip:" << std::endl;
599 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.
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)
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)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
VISP_EXPORT int wait(double t0, double t)