1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Ogre example.
*/
/*!
\example HelloWorldOgre.cpp
\brief Example that shows how to exploit the vpAROgre class.
*/
#include <iostream>
#include <visp3/core/vpConfig.h>
//! [Undef grabber]
// Comment / uncomment following lines to use the specific 3rd party compatible with your camera
// #undef VISP_HAVE_V4L2
// #undef VISP_HAVE_DC1394
// #undef HAVE_OPENCV_HIGHGUI
// #undef HAVE_OPENCV_VIDEOIO
//! [Undef grabber]
#include <visp3/ar/vpAROgre.h>
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpImage.h>
#include <visp3/sensor/vp1394TwoGrabber.h>
#include <visp3/sensor/vpV4l2Grabber.h>
#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)
#include <opencv2/highgui/highgui.hpp> // for cv::VideoCapture
#elif defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)
#include <opencv2/videoio/videoio.hpp> // for cv::VideoCapture
#endif
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
try {
#if defined(VISP_HAVE_OGRE)
#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394) || defined(VISP_HAVE_OPENCV) && \
(((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
// Image to stock gathered data
// Here we acquire a color image. The consequence will be that
// the background texture used in Ogre renderer will be also in color.
vpImage<vpRGBa> I;
// Now we try to find an available framegrabber
#if defined(VISP_HAVE_V4L2)
// Video for linux 2 grabber
vpV4l2Grabber grabber;
grabber.open(I);
grabber.acquire(I);
#elif defined(VISP_HAVE_DC1394)
// libdc1394-2
vp1394TwoGrabber grabber;
grabber.open(I);
grabber.acquire(I);
#elif defined(VISP_HAVE_OPENCV) && \
(((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
// OpenCV to gather images
cv::VideoCapture grabber(0); // open the default camera
if (!grabber.isOpened()) { // check if we succeeded
std::cout << "Failed to open the camera" << std::endl;
return EXIT_FAILURE;
}
cv::Mat frame;
grabber >> frame; // get a new frame from camera
vpImageConvert::convert(frame, I);
#endif
// Parameters of our camera
double px = 565;
double py = 565;
double u0 = I.getWidth() / 2;
double v0 = I.getHeight() / 2;
vpCameraParameters cam(px, py, u0, v0);
// The matrix with our pose
// Defines the pose of the object in the camera frame
vpHomogeneousMatrix cMo;
// Our object
// A simulator with the camera parameters defined above,
// a grey level background image and of the good size
vpAROgre ogre(cam, I.getWidth(), I.getHeight());
// Initialisation
// Here we load the requested plugins specified in the "plugins.cfg" file
// and the resources specified in the "resources.cfg" file
// These two files can be found respectively in
// ViSP_HAVE_OGRE_PLUGINS_PATH and ViSP_HAVE_OGRE_RESOURCES_PATH folders
ogre.init(I);
// Create a basic scene
// -----------------------------------
// Loading things
// -----------------------------------
// As you will see in section 5, our
// application knows locations where
// it can search for medias.
// Here we use a mesh included in
// the installation files : a robot.
// -----------------------------------
// Here we load the "robot.mesh" model that is found thanks to the
// resources locations specified in the "resources.cfg" file
ogre.load("Robot", "robot.mesh");
// Modify robot scale and orientation
// - downscale the size to have something completly visible in the image
// - rotation of 180 deg along robot x axis to have head over feet
// - rotation of -90 deg along y axis to have robot facing the camera
ogre.setScale("Robot", 0.001f, 0.001f, 0.001f);
ogre.setRotation("Robot", vpRotationMatrix(vpRxyzVector(M_PI, -M_PI / 2, 0)));
// Update projection matrix
cMo[2][3] = 0.5; // Z = 0.5 meter
std::cout << "cMo:\n" << cMo << std::endl;
// Rendering loop, ended with on escape
while (ogre.continueRendering()) {
// Acquire a new image
#if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394)
grabber.acquire(I);
#elif defined(VISP_HAVE_OPENCV) && \
(((VISP_HAVE_OPENCV_VERSION < 0x030000) && defined(HAVE_OPENCV_HIGHGUI)) || \
((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(HAVE_OPENCV_VIDEOIO)))
grabber >> frame;
vpImageConvert::convert(frame, I);
#endif
// Pose computation
// ...
// cMo updated
// Display the robot at the position specified by cMo with vpAROgre
ogre.display(I, cMo);
}
#else
std::cout << "You need an available framegrabber to run this example" << std::endl;
#endif
#else
std::cout << "You need Ogre3D to run this example" << std::endl;
#endif
return EXIT_SUCCESS;
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_FAILURE;
}
catch (...) {
std::cout << "Catch an exception " << std::endl;
return EXIT_FAILURE;
}
}
|