Visual Servoing Platform version 3.5.0
manGeometricFeatures.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See http://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Geometric features example.
33 *
34 * Authors:
35 * Anthony Saunier
36 * Fabien Spindler
37 *
38 *****************************************************************************/
52#include <visp3/core/vpDebug.h>
53#include <visp3/io/vpImageIo.h>
54// For 2D image
55#include <visp3/core/vpImage.h>
56// Video device interface
57#include <visp3/core/vpDisplay.h>
58#include <visp3/gui/vpDisplayGDI.h>
59#include <visp3/gui/vpDisplayGTK.h>
60#include <visp3/gui/vpDisplayOpenCV.h>
61#include <visp3/gui/vpDisplayX.h>
62
63// For frame transformation and projection
64#include <visp3/core/vpCameraParameters.h>
65#include <visp3/core/vpHomogeneousMatrix.h>
66
67// Needed geometric features
68#include <visp3/core/vpCircle.h>
69#include <visp3/core/vpCylinder.h>
70#include <visp3/core/vpLine.h>
71#include <visp3/core/vpPoint.h>
72#include <visp3/core/vpSphere.h>
73
74#include <iostream>
75
76int main()
77{
78 try {
79 std::cout << "ViSP geometric features display example" << std::endl;
80 unsigned int height = 288;
81 unsigned int width = 384;
82 vpImage<unsigned char> I(height, width);
83 I = 255; // I is a white image
84
85 // create a display window
86#if defined(VISP_HAVE_X11)
87 vpDisplayX display;
88#elif defined(VISP_HAVE_GDI)
89 vpDisplayGDI display;
90#elif defined(VISP_HAVE_OPENCV)
91 vpDisplayOpenCV display;
92#elif defined(VISP_HAVE_GTK)
93 vpDisplayGTK display;
94#else
95 std::cout << "Please install X11, GDI, OpenCV or GTK to see the result of this example" << std::endl;
96#endif
97
98
99#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
100 // initialize a display attached to image I
101 display.init(I, 100, 100, "ViSP geometric features display");
102#endif
103
104 // camera parameters to digitalize the image plane
105 vpCameraParameters cam(600, 600, width / 2, height / 2); // px,py,u0,v0
106
107 // pose of the camera with reference to the scene
108 vpTranslationVector t(0, 0, 1);
109 vpRxyzVector rxyz(-M_PI / 4, 0, 0);
110 vpRotationMatrix R(rxyz);
111 vpHomogeneousMatrix cMo(t, R);
112
113 // scene building, geometric features definition
114 vpPoint point;
115 point.setWorldCoordinates(0, 0, 0); // (X0=0,Y0=0,Z0=0)
116 vpLine line;
117 line.setWorldCoordinates(1, 1, 0, 0, 0, 0, 1, 0); // planes:(X+Y=0)&(Z=0)
118 vpCylinder cylinder;
119 cylinder.setWorldCoordinates(1, -1, 0, 0, 0, 0,
120 0.1); // alpha=1,beta=-1,gamma=0,
121 // X0=0,Y0=0,Z0=0,R=0.1
122 vpCircle circle;
123 circle.setWorldCoordinates(0, 0, 1, 0, 0, 0,
124 0.1); // plane:(Z=0),X0=0,Y0=0,Z=0,R=0.1
125 vpSphere sphere;
126 sphere.setWorldCoordinates(0, 0, 0, 0.1); // X0=0,Y0=0,Z0=0,R=0.1
127
128 // change frame to be the camera frame and project features in the image
129 // plane
130 point.project(cMo);
131 line.project(cMo);
132 cylinder.project(cMo);
133 circle.project(cMo);
134 sphere.project(cMo);
135
136 // display the scene
137 vpDisplay::display(I); // display I
138 // draw the projections of the 3D geometric features in the image plane.
139 point.display(I, cam, vpColor::black); // draw a black cross over I
140 line.display(I, cam, vpColor::blue); // draw a blue line over I
141 cylinder.display(I, cam, vpColor::red); // draw two red lines over I
142 circle.display(I, cam, vpColor::orange); // draw an orange ellipse over I
143 sphere.display(I, cam, vpColor::black); // draw a black ellipse over I
144
145 vpDisplay::flush(I); // flush the display buffer
146 vpDisplay::displayText(I, 10, 10, "Click in the display to exit", vpColor::red);
147 vpDisplay::getClick(I); // wait for a click in the display to exit
148
149#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
150 // save the drawing
152 vpDisplay::getImage(I, Ic);
153 std::cout << "ViSP creates \"./geometricFeatures.ppm\" image" << std::endl;
154 vpImageIo::write(Ic, "./geometricFeatures.ppm");
155#endif
156 } catch (const vpException &e) {
157 std::cout << "Catch an exception: " << e << std::endl;
158 return EXIT_FAILURE;
159 }
160
161 return EXIT_SUCCESS;
162}
Generic class defining intrinsic camera parameters.
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Definition: vpCircle.h:92
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCircle.cpp:60
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1)
Definition: vpCircle.cpp:313
static const vpColor red
Definition: vpColor.h:217
static const vpColor black
Definition: vpColor.h:211
static const vpColor orange
Definition: vpColor.h:227
static const vpColor blue
Definition: vpColor.h:223
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
Definition: vpCylinder.h:103
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1)
Definition: vpCylinder.cpp:412
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCylinder.cpp:65
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:135
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...
Definition: vpDisplayX.h:135
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:144
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emited by ViSP classes.
Definition: vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:293
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition: vpLine.h:105
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1)
Definition: vpLine.cpp:465
void setWorldCoordinates(const double &oA1, const double &oB1, const double &oC1, const double &oD1, const double &oA2, const double &oB2, const double &oC2, const double &oD2)
Definition: vpLine.cpp:85
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:82
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1)
Definition: vpPoint.cpp:430
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:113
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:184
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
Definition: vpSphere.h:83
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1)
Definition: vpSphere.cpp:287
void setWorldCoordinates(const vpColVector &oP)
Definition: vpSphere.cpp:62
Class that consider the case of a translation vector.