Visual Servoing Platform  version 3.1.0
manGeometricFeatures.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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/vpDisplayGTK.h>
59 
60 // For frame transformation and projection
61 #include <visp3/core/vpCameraParameters.h>
62 #include <visp3/core/vpHomogeneousMatrix.h>
63 
64 // Needed geometric features
65 #include <visp3/core/vpCircle.h>
66 #include <visp3/core/vpCylinder.h>
67 #include <visp3/core/vpLine.h>
68 #include <visp3/core/vpPoint.h>
69 #include <visp3/core/vpSphere.h>
70 
71 #include <iostream>
72 
73 int main()
74 {
75 #ifdef VISP_HAVE_GTK
76  try {
77  std::cout << "ViSP geometric features display example" << std::endl;
78  unsigned int height = 288;
79  unsigned int width = 384;
80  vpImage<unsigned char> I(height, width);
81  I = 255; // I is a white image
82 
83  // create a display window
84  vpDisplayGTK display;
85  // initialize a display attached to image I
86  display.init(I, 100, 100, "ViSP geometric features display");
87  // camera parameters to digitalize the image plane
88  vpCameraParameters cam(600, 600, width / 2, height / 2); // px,py,u0,v0
89 
90  // pose of the camera with reference to the scene
91  vpTranslationVector t(0, 0, 1);
92  vpRxyzVector rxyz(-M_PI / 4, 0, 0);
93  vpRotationMatrix R(rxyz);
94  vpHomogeneousMatrix cMo(t, R);
95 
96  // scene building, geometric features definition
97  vpPoint point;
98  point.setWorldCoordinates(0, 0, 0); // (X0=0,Y0=0,Z0=0)
99  vpLine line;
100  line.setWorldCoordinates(1, 1, 0, 0, 0, 0, 1, 0); // planes:(X+Y=0)&(Z=0)
101  vpCylinder cylinder;
102  cylinder.setWorldCoordinates(1, -1, 0, 0, 0, 0,
103  0.1); // alpha=1,beta=-1,gamma=0,
104  // X0=0,Y0=0,Z0=0,R=0.1
105  vpCircle circle;
106  circle.setWorldCoordinates(0, 0, 1, 0, 0, 0,
107  0.1); // plane:(Z=0),X0=0,Y0=0,Z=0,R=0.1
108  vpSphere sphere;
109  sphere.setWorldCoordinates(0, 0, 0, 0.1); // X0=0,Y0=0,Z0=0,R=0.1
110 
111  // change frame to be the camera frame and project features in the image
112  // plane
113  point.project(cMo);
114  line.project(cMo);
115  cylinder.project(cMo);
116  circle.project(cMo);
117  sphere.project(cMo);
118 
119  // display the scene
120  vpDisplay::display(I); // display I
121  // draw the projections of the 3D geometric features in the image plane.
122  point.display(I, cam, vpColor::black); // draw a black cross over I
123  line.display(I, cam, vpColor::blue); // draw a blue line over I
124  cylinder.display(I, cam, vpColor::red); // draw two red lines over I
125  circle.display(I, cam, vpColor::orange); // draw an orange ellipse over I
126  sphere.display(I, cam, vpColor::black); // draw a black ellipse over I
127 
128  vpDisplay::flush(I); // flush the display buffer
129  std::cout << "A click in the display to exit" << std::endl;
130  vpDisplay::getClick(I); // wait for a click in the display to exit
131 
132  // save the drawing
133  vpImage<vpRGBa> Ic;
134  vpDisplay::getImage(I, Ic);
135  std::cout << "ViSP creates \"./geometricFeatures.ppm\" B&W image " << std::endl;
136  vpImageIo::write(Ic, "./geometricFeatures.ppm");
137  return 0;
138  } catch (vpException &e) {
139  std::cout << "Catch an exception: " << e << std::endl;
140  return 1;
141  }
142 
143 #endif
144 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static const vpColor black
Definition: vpColor.h:174
void setWorldCoordinates(const double &A1, const double &B1, const double &C1, const double &D1, const double &A2, const double &B2, const double &C2, const double &D2)
Definition: vpLine.cpp:85
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpPoint.cpp:403
error that can be emited by ViSP classes.
Definition: vpException.h:71
Class that defines what is a sphere.
Definition: vpSphere.h:60
void setWorldCoordinates(const vpColVector &oP)
Definition: vpSphere.cpp:51
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:180
Class that defines what is a point.
Definition: vpPoint.h:58
static const vpColor orange
Definition: vpColor.h:190
Implementation of a rotation matrix and operations on such kind of matrices.
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:375
Class that defines a line in the object frame, the camera frame and the image plane. All the parameters must be set in meter.
Definition: vpLine.h:105
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpSphere.cpp:179
static void display(const vpImage< unsigned char > &I)
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:138
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:144
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpCircle.cpp:294
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Class that defines what is a cylinder.
Definition: vpCylinder.h:96
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Definition: vpPoint.cpp:113
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpCylinder.cpp:397
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:156
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpLine.cpp:470
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCylinder.cpp:71
Class that defines what is a circle.
Definition: vpCircle.h:58
Class that consider the case of a translation vector.
static const vpColor blue
Definition: vpColor.h:186
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCircle.cpp:61