Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
manGeometricFeatures.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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 */
45
46#include <visp3/core/vpConfig.h>
47#include <visp3/core/vpDebug.h>
48#include <visp3/io/vpImageIo.h>
49// For 2D image
50#include <visp3/core/vpImage.h>
51// Video device interface
52#include <visp3/gui/vpDisplayFactory.h>
53
54// For frame transformation and projection
55#include <visp3/core/vpCameraParameters.h>
56#include <visp3/core/vpHomogeneousMatrix.h>
57
58// Needed geometric features
59#include <visp3/core/vpCircle.h>
60#include <visp3/core/vpCylinder.h>
61#include <visp3/core/vpLine.h>
62#include <visp3/core/vpPoint.h>
63#include <visp3/core/vpSphere.h>
64
65#include <iostream>
66
67int main()
68{
69#ifdef ENABLE_VISP_NAMESPACE
70 using namespace VISP_NAMESPACE_NAME;
71#endif
72
73 // create a display window
74#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
75 std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay();
76#else
78#endif
79
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 = 255u; // I is a white image
86
87
88
89#if defined(VISP_HAVE_DISPLAY)
90 // initialize a display attached to image I
91 display->init(I, 100, 100, "ViSP geometric features display");
92#endif
93
94 // camera parameters to digitalize the image plane
95 vpCameraParameters cam(600, 600, width / 2, height / 2); // px,py,u0,v0
96
97 // pose of the camera with reference to the scene
98 vpTranslationVector t(0, 0, 1);
99 vpRxyzVector rxyz(-M_PI / 4, 0, 0);
100 vpRotationMatrix R(rxyz);
102
103 // scene building, geometric features definition
104 vpPoint point;
105 point.setWorldCoordinates(0, 0, 0); // (X0=0,Y0=0,Z0=0)
106 vpLine line;
107 line.setWorldCoordinates(1, 1, 0, 0, 0, 0, 1, 0); // planes:(X+Y=0)&(Z=0)
108 vpCylinder cylinder;
109 cylinder.setWorldCoordinates(1, -1, 0, 0, 0, 0,
110 0.1); // alpha=1,beta=-1,gamma=0,
111 // X0=0,Y0=0,Z0=0,R=0.1
112 vpCircle circle;
113 circle.setWorldCoordinates(0, 0, 1, 0, 0, 0,
114 0.1); // plane:(Z=0),X0=0,Y0=0,Z=0,R=0.1
115 vpSphere sphere;
116 sphere.setWorldCoordinates(0, 0, 0, 0.1); // X0=0,Y0=0,Z0=0,R=0.1
117
118 // change frame to be the camera frame and project features in the image
119 // plane
120 point.project(cMo);
121 line.project(cMo);
122 cylinder.project(cMo);
123 circle.project(cMo);
124 sphere.project(cMo);
125
126 // display the scene
127 vpDisplay::display(I); // display I
128 // draw the projections of the 3D geometric features in the image plane.
129 point.display(I, cam, vpColor::black); // draw a black cross over I
130 line.display(I, cam, vpColor::blue); // draw a blue line over I
131 cylinder.display(I, cam, vpColor::red); // draw two red lines over I
132 circle.display(I, cam, vpColor::orange); // draw an orange ellipse over I
133 sphere.display(I, cam, vpColor::black); // draw a black ellipse over I
134
135 vpDisplay::flush(I); // flush the display buffer
136 vpDisplay::displayText(I, 10, 10, "Click in the display to exit", vpColor::red);
137 vpDisplay::getClick(I); // wait for a click in the display to exit
138
139#if defined(VISP_HAVE_DISPLAY)
140 // save the drawing
142 vpDisplay::getImage(I, Ic);
143 std::cout << "ViSP creates \"./geometricFeatures.ppm\" image" << std::endl;
144 vpImageIo::write(Ic, "./geometricFeatures.ppm");
145#endif
146 }
147 catch (const vpException &e) {
148 std::cout << "Catch an exception: " << e << std::endl;
149#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
150 if (display != nullptr) {
151 delete display;
152 }
153#endif
154 return EXIT_FAILURE;
155 }
156
157#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
158 if (display != nullptr) {
159 delete display;
160 }
161#endif
162 return EXIT_SUCCESS;
163}
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:87
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1) VP_OVERRIDE
Definition vpCircle.cpp:353
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
Definition vpCircle.cpp:58
static const vpColor red
Definition vpColor.h:198
static const vpColor orange
Definition vpColor.h:208
static const vpColor blue
Definition vpColor.h:204
static const vpColor black
Definition vpColor.h:192
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
Definition vpCylinder.h:101
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1) VP_OVERRIDE
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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)
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 emitted by ViSP classes.
Definition vpException.h:60
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 of the vpImage class member functions.
Definition vpImage.h:131
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition vpLine.h:103
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1) VP_OVERRIDE
Definition vpLine.cpp:470
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:87
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1) VP_OVERRIDE
Definition vpPoint.cpp:387
void setWorldCoordinates(double oX, double oY, double oZ)
Definition vpPoint.cpp:116
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
Definition vpSphere.h:80
void display(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpColor &color=vpColor::green, unsigned int thickness=1) VP_OVERRIDE
Definition vpSphere.cpp:308
void setWorldCoordinates(const vpColVector &oP) VP_OVERRIDE
Definition vpSphere.cpp:60
Class that consider the case of a translation vector.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.