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