Visual Servoing Platform  version 3.0.1
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Geometric features example.
32  *
33  * Authors:
34  * Anthony Saunier
35  * Fabien Spindler
36  *
37  *****************************************************************************/
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/vpHomogeneousMatrix.h>
62 #include <visp3/core/vpCameraParameters.h>
63 
64 // Needed geometric features
65 #include <visp3/core/vpPoint.h>
66 #include <visp3/core/vpLine.h>
67 #include <visp3/core/vpCylinder.h>
68 #include <visp3/core/vpCircle.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,0.1); // alpha=1,beta=-1,gamma=0,
103  // X0=0,Y0=0,Z0=0,R=0.1
104  vpCircle circle;
105  circle.setWorldCoordinates(0,0,1,0,0,0,0.1); // plane:(Z=0),X0=0,Y0=0,Z=0,R=0.1
106  vpSphere sphere;
107  sphere.setWorldCoordinates(0,0,0,0.1); // X0=0,Y0=0,Z0=0,R=0.1
108 
109  // change frame to be the camera frame and project features in the image plane
110  point.project(cMo);
111  line.project(cMo);
112  cylinder.project(cMo);
113  circle.project(cMo);
114  sphere.project(cMo);
115 
116  // display the scene
117  vpDisplay::display(I); // display I
118  // draw the projections of the 3D geometric features in the image plane.
119  point.display(I,cam,vpColor::black); // draw a black cross over I
120  line.display(I,cam,vpColor::blue); // draw a blue line over I
121  cylinder.display(I,cam,vpColor::red); // draw two red lines over I
122  circle.display(I,cam,vpColor::orange); // draw an orange ellipse over I
123  sphere.display(I,cam,vpColor::black); // draw a black ellipse over I
124 
125  vpDisplay::flush(I); // flush the display buffer
126  std::cout << "A click in the display to exit" << std::endl;
127  vpDisplay::getClick(I); // wait for a click in the display to exit
128 
129  // save the drawing
130  vpImage<vpRGBa> Ic;
131  vpDisplay::getImage(I,Ic);
132  std::cout << "ViSP creates \"./geometricFeatures.ppm\" B&W image "<< std::endl;
133  vpImageIo::write(Ic, "./geometricFeatures.ppm");
134  return 0;
135  }
136  catch(vpException &e) {
137  std::cout << "Catch an exception: " << e << std::endl;
138  return 1;
139  }
140 
141 #endif
142 }
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:157
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:94
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpPoint.cpp:428
error that can be emited by ViSP classes.
Definition: vpException.h:73
Class that defines what is a sphere.
Definition: vpSphere.h:60
void setWorldCoordinates(const vpColVector &oP)
Definition: vpSphere.cpp:54
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:163
Class that defines what is a point.
Definition: vpPoint.h:59
static const vpColor orange
Definition: vpColor.h:173
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:368
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:224
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:155
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpCircle.cpp:327
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:93
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Definition: vpPoint.cpp:111
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpCylinder.cpp:431
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:154
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpLine.cpp:503
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCylinder.cpp:73
Class that defines what is a circle.
Definition: vpCircle.h:57
Class that consider the case of a translation vector.
static const vpColor blue
Definition: vpColor.h:169
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCircle.cpp:62