ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
manGeometricFeatures.cpp
1 /****************************************************************************
2  *
3  * $Id: manGeometricFeatures.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Geometric features example.
36  *
37  * Authors:
38  * Anthony Saunier
39  * Fabien Spindler
40  *
41  *****************************************************************************/
56 #include <visp/vpDebug.h>
57 #include <visp/vpImageIo.h>
58 // For 2D image
59 #include <visp/vpImage.h>
60 // Video device interface
61 #include <visp/vpDisplay.h>
62 #include <visp/vpDisplayGTK.h>
63 
64 // For frame transformation and projection
65 #include <visp/vpHomogeneousMatrix.h>
66 #include <visp/vpCameraParameters.h>
67 
68 // Needed geometric features
69 #include <visp/vpPoint.h>
70 #include <visp/vpLine.h>
71 #include <visp/vpCylinder.h>
72 #include <visp/vpCircle.h>
73 #include <visp/vpSphere.h>
74 
75 #include <iostream>
76 
77 int main()
78 {
79 #ifdef VISP_HAVE_GTK
80 
81  std::cout << "ViSP geometric features display example" <<std::endl;
82  unsigned int height = 288;
83  unsigned int width = 384;
84  vpImage<unsigned char> I(height,width);
85  I = 255; // I is a white image
86 
87  // create a display window
88  vpDisplayGTK display;
89  // initialize a display attached to image I
90  display.init(I,100,100,"ViSP geometric features display");
91  // camera parameters to digitalize the image plane
92  vpCameraParameters cam(600,600,width/2,height/2); // px,py,u0,v0
93 
94  // pose of the camera with reference to the scene
95  vpTranslationVector t(0,0,1);
96  vpRxyzVector rxyz(-M_PI/4,0,0);
97  vpRotationMatrix R(rxyz);
98  vpHomogeneousMatrix cMo(t, R);
99 
100  // scene building, geometric features definition
101  vpPoint point;
102  point.setWorldCoordinates(0,0,0);// (X0=0,Y0=0,Z0=0)
103  vpLine line;
104  line.setWorldCoordinates(1,1,0,0,0,0,1,0); // planes:(X+Y=0)&(Z=0)
105  vpCylinder cylinder;
106  cylinder.setWorldCoordinates(1,-1,0,0,0,0,0.1); // alpha=1,beta=-1,gamma=0,
107  // X0=0,Y0=0,Z0=0,R=0.1
108  vpCircle circle;
109  circle.setWorldCoordinates(0,0,1,0,0,0,0.1); // plane:(Z=0),X0=0,Y0=0,Z=0,R=0.1
110  vpSphere sphere;
111  sphere.setWorldCoordinates(0,0,0,0.1); // X0=0,Y0=0,Z0=0,R=0.1
112 
113  // change frame to be the camera frame and project features in the image plane
114  point.project(cMo);
115  line.project(cMo);
116  cylinder.project(cMo);
117  circle.project(cMo);
118  sphere.project(cMo);
119 
120  // display the scene
121  vpDisplay::display(I); // display I
122  // draw the projections of the 3D geometric features in the image plane.
123  point.display(I,cam,vpColor::black); // draw a black cross over I
124  line.display(I,cam,vpColor::blue); // draw a blue line over I
125  cylinder.display(I,cam,vpColor::red); // draw two red lines over I
126  circle.display(I,cam,vpColor::orange); // draw an orange ellipse over I
127  sphere.display(I,cam,vpColor::black); // draw a black ellipse over I
128 
129  vpDisplay::flush(I); // flush the display buffer
130  std::cout << "A click in the display to exit" << std::endl;
131  vpDisplay::getClick(I); // wait for a click in the display to exit
132 
133  // save the drawing
134  vpImage<vpRGBa> Ic;
135  vpDisplay::getImage(I,Ic);
136  std::cout << "ViSP creates \"./geometricFeatures.ppm\" B&W image "<< std::endl;
137  vpImageIo::writePPM(Ic, "./geometricFeatures.ppm");
138 
139 #endif
140  return 0;
141 }