ViSP  2.10.0
manGeometricFeatures.cpp
1 /****************************************************************************
2  *
3  * $Id: manGeometricFeatures.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  try {
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::write(Ic, "./geometricFeatures.ppm");
138  return 0;
139  }
140  catch(vpException e) {
141  std::cout << "Catch an exception: " << e << std::endl;
142  return 1;
143  }
144 
145 #endif
146 }
static void write(const vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:476
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
static const vpColor black
Definition: vpColor.h:161
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:98
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpPoint.cpp:309
error that can be emited by ViSP classes.
Definition: vpException.h:76
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Class that defines what is a sphere.
Definition: vpSphere.h:64
void setWorldCoordinates(const vpColVector &oP)
Definition: vpSphere.cpp:58
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
static const vpColor red
Definition: vpColor.h:167
Class that defines what is a point.
Definition: vpPoint.h:65
static const vpColor orange
Definition: vpColor.h:177
The vpRotationMatrix considers the particular case of a rotation matrix.
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:124
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpSphere.cpp:227
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
Generic class defining intrinsic camera parameters.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:145
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:328
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpCircle.cpp:331
Class that defines what is a cylinder.
Definition: vpCylinder.h:97
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpCylinder.cpp:422
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
Definition: vpRxyzVector.h:152
virtual bool getClick(bool blocking=true)=0
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, const unsigned int thickness=1)
Definition: vpLine.cpp:507
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCylinder.cpp:77
Class that defines what is a circle.
Definition: vpCircle.h:61
Class that consider the case of a translation vector.
static const vpColor blue
Definition: vpColor.h:173
void setWorldCoordinates(const vpColVector &oP)
Definition: vpCircle.cpp:66
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
Definition: vpPoint.cpp:74