Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpFeatureDisplay.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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  * Interface with the image for feature display.
32  *
33 *****************************************************************************/
34 
35 #include <visp3/core/vpFeatureDisplay.h>
36 
37 // Meter/pixel conversion
38 #include <visp3/core/vpMeterPixelConversion.h>
39 
40 // display
41 #include <visp3/core/vpDisplay.h>
42 
43 // math
44 #include <visp3/core/vpMath.h>
45 
46 #include <visp3/core/vpImagePoint.h>
47 
48 BEGIN_VISP_NAMESPACE
60 void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<unsigned char> &I,
61  const vpColor &color, unsigned int thickness)
62 {
63  vpImagePoint ip; // pixel coordinates in float
65  vpDisplay::displayCross(I, ip, 15, color, thickness);
66 }
67 
78 void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam,
79  const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness)
80 {
81  // --comment: x times cos(theta) plus y times sin(theta) minus rho equals 0
82  double rhop, thetap;
83  vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
84 
85  // --comment: u times cos thetap plus v times sin thetap minus rhop equals 0
86  double co = cos(thetap);
87  double si = sin(thetap);
88  double c = -rhop;
89 
90  double a = si;
91  double b = co;
92  vpImagePoint ip1, ip2;
93 
94  if (fabs(a) < fabs(b)) {
95  ip1.set_ij(0, (-c) / b);
96  double h = I.getHeight() - 1;
97  ip2.set_ij(h, (-c - (a * h)) / b);
98  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
99  }
100  else {
101  ip1.set_ij((-c) / a, 0);
102  double w = I.getWidth() - 1;
103  ip2.set_ij((-c - (b * w)) / a, w);
104  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
105  }
106 }
107 
119 void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
120  const vpCameraParameters &cam, const vpImage<unsigned char> &I,
121  const vpColor &color, unsigned int thickness)
122 {
123  displayLine(rho1, theta1, cam, I, color, thickness);
124  displayLine(rho2, theta2, cam, I, color, thickness);
125 }
126 
144 void vpFeatureDisplay::displayEllipse(double x, double y, double n20, double n11, double n02,
145  const vpCameraParameters &cam, const vpImage<unsigned char> &I,
146  const vpColor &color, unsigned int thickness)
147 {
148  vpImagePoint center;
149  double n20_p, n11_p, n02_p;
150  const unsigned int index_0 = 0;
151  const unsigned int index_1 = 1;
152  const unsigned int index_2 = 2;
153  const unsigned int index_3 = 3;
154  const unsigned int index_4 = 4;
155  vpCircle circle;
156  circle.p[index_0] = x;
157  circle.p[index_1] = y;
158  circle.p[index_2] = n20;
159  circle.p[index_3] = n11;
160  circle.p[index_4] = n02;
161 
162  vpMeterPixelConversion::convertEllipse(cam, circle, center, n20_p, n11_p, n02_p);
163  vpDisplay::displayEllipse(I, center, n20_p, n11_p, n02_p, true, color, thickness);
164 }
165 
177 void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
178  const vpColor &color, unsigned int thickness)
179 {
180  vpImagePoint ip; // pixel coordinates in float
182 
183  vpDisplay::displayCross(I, ip, 15, color, thickness);
184 }
185 
196 void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
197  const vpColor &color, unsigned int thickness)
198 {
199  // --comment: x times cos of theta plus y times sin of theta minus rho equals 0
200  double rhop, thetap;
201  vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
202 
203  // --comment: u times cos of thetap plus v times sin of thetap minus rhop equals 0
204  double co = cos(thetap);
205  double si = sin(thetap);
206  double c = -rhop;
207 
208  double a = si;
209  double b = co;
210  vpImagePoint ip1, ip2;
211 
212  if (fabs(a) < fabs(b)) {
213  ip1.set_ij(0, (-c) / b);
214  double h = I.getHeight() - 1;
215  ip2.set_ij(h, (-c - (a * h)) / b);
216  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
217  }
218  else {
219  ip1.set_ij((-c) / a, 0);
220  double w = I.getWidth() - 1;
221  ip2.set_ij((-c - (b * w)) / a, w);
222  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
223  }
224 }
225 
237 void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
238  const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
239  unsigned int thickness)
240 {
241  displayLine(rho1, theta1, cam, I, color, thickness);
242  displayLine(rho2, theta2, cam, I, color, thickness);
243 }
244 
262 void vpFeatureDisplay::displayEllipse(double x, double y, double n20, double n11, double n02,
263  const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
264  unsigned int thickness)
265 {
266  vpImagePoint center;
267  double n20_p, n11_p, n02_p;
268  const unsigned int index_0 = 0;
269  const unsigned int index_1 = 1;
270  const unsigned int index_2 = 2;
271  const unsigned int index_3 = 3;
272  const unsigned int index_4 = 4;
273  vpCircle circle;
274  circle.p[index_0] = x;
275  circle.p[index_1] = y;
276  circle.p[index_2] = n20;
277  circle.p[index_3] = n11;
278  circle.p[index_4] = n02;
279 
280  vpMeterPixelConversion::convertEllipse(cam, circle, center, n20_p, n11_p, n02_p);
281  vpDisplay::displayEllipse(I, center, n20_p, n11_p, n02_p, true, color, thickness);
282 }
283 END_VISP_NAMESPACE
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
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayEllipse(const vpImage< unsigned char > &I, const vpImagePoint &center, const double &coef1, const double &coef2, const double &coef3, bool use_normalized_centered_moments, const vpColor &color, unsigned int thickness=1, bool display_center=false, bool display_arc=false)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void displayCylinder(double rho1, double theta1, double rho2, double theta2, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static void displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static void displayEllipse(double x, double y, double n20, double n11, double n02, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static void displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
void set_ij(double ii, double jj)
Definition: vpImagePoint.h:320
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
static void convertEllipse(const vpCameraParameters &cam, const vpSphere &sphere, vpImagePoint &center_p, double &n20_p, double &n11_p, double &n02_p)
vpColVector p
Definition: vpTracker.h:69