Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureDisplay.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 * Interface with the image for feature display.
32 */
33
34#include <visp3/core/vpFeatureDisplay.h>
35
36// Meter/pixel conversion
37#include <visp3/core/vpMeterPixelConversion.h>
38
39// display
40#include <visp3/core/vpDisplay.h>
41
42// math
43#include <visp3/core/vpMath.h>
44
45#include <visp3/core/vpImagePoint.h>
46
60void 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
79void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam,
80 const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness)
81{
82 // --comment: x times cos(theta) plus y times sin(theta) minus rho equals 0
83 double rhop, thetap;
84 vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
85
86 // --comment: u times cos thetap plus v times sin thetap minus rhop equals 0
87 double co = cos(thetap);
88 double si = sin(thetap);
89 double c = -rhop;
90
91 double a = si;
92 double b = co;
93 vpImagePoint ip1, ip2;
94
95 if (fabs(a) < fabs(b)) {
96 ip1.set_ij(0, (-c) / b);
97 double h = I.getHeight() - 1;
98 ip2.set_ij(h, (-c - (a * h)) / b);
99 vpDisplay::displayLine(I, ip1, ip2, color, thickness);
100 }
101 else {
102 ip1.set_ij((-c) / a, 0);
103 double w = I.getWidth() - 1;
104 ip2.set_ij((-c - (b * w)) / a, w);
105 vpDisplay::displayLine(I, ip1, ip2, color, thickness);
106 }
107}
108
122void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
123 const vpCameraParameters &cam, const vpImage<unsigned char> &I,
124 const vpColor &color, unsigned int thickness)
125{
126 displayLine(rho1, theta1, cam, I, color, thickness);
127 displayLine(rho2, theta2, cam, I, color, thickness);
128}
129
152void vpFeatureDisplay::displayEllipse(double x, double y, double n20, double n11, double n02,
153 const vpCameraParameters &cam, const vpImage<unsigned char> &I,
154 const vpColor &color, unsigned int thickness)
155{
156 vpImagePoint center;
157 double n20_p, n11_p, n02_p;
158 const unsigned int index_0 = 0;
159 const unsigned int index_1 = 1;
160 const unsigned int index_2 = 2;
161 const unsigned int index_3 = 3;
162 const unsigned int index_4 = 4;
163 vpCircle circle;
164 circle.p[index_0] = x;
165 circle.p[index_1] = y;
166 circle.p[index_2] = n20;
167 circle.p[index_3] = n11;
168 circle.p[index_4] = n02;
169
170 vpMeterPixelConversion::convertEllipse(cam, circle, center, n20_p, n11_p, n02_p);
171 vpDisplay::displayEllipse(I, center, n20_p, n11_p, n02_p, true, color, thickness);
172}
173
186void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
187 const vpColor &color, unsigned int thickness)
188{
189 vpImagePoint ip; // pixel coordinates in float
191
192 vpDisplay::displayCross(I, ip, 15, color, thickness);
193}
194
206void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
207 const vpColor &color, unsigned int thickness)
208{
209 // --comment: x times cos of theta plus y times sin of theta minus rho equals 0
210 double rhop, thetap;
211 vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
212
213 // --comment: u times cos of thetap plus v times sin of thetap minus rhop equals 0
214 double co = cos(thetap);
215 double si = sin(thetap);
216 double c = -rhop;
217
218 double a = si;
219 double b = co;
220 vpImagePoint ip1, ip2;
221
222 if (fabs(a) < fabs(b)) {
223 ip1.set_ij(0, (-c) / b);
224 double h = I.getHeight() - 1;
225 ip2.set_ij(h, (-c - (a * h)) / b);
226 vpDisplay::displayLine(I, ip1, ip2, color, thickness);
227 }
228 else {
229 ip1.set_ij((-c) / a, 0);
230 double w = I.getWidth() - 1;
231 ip2.set_ij((-c - (b * w)) / a, w);
232 vpDisplay::displayLine(I, ip1, ip2, color, thickness);
233 }
234}
235
249void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
250 const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
251 unsigned int thickness)
252{
253 displayLine(rho1, theta1, cam, I, color, thickness);
254 displayLine(rho2, theta2, cam, I, color, thickness);
255}
256
279void vpFeatureDisplay::displayEllipse(double x, double y, double n20, double n11, double n02,
280 const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
281 unsigned int thickness)
282{
283 vpImagePoint center;
284 double n20_p, n11_p, n02_p;
285 const unsigned int index_0 = 0;
286 const unsigned int index_1 = 1;
287 const unsigned int index_2 = 2;
288 const unsigned int index_3 = 3;
289 const unsigned int index_4 = 4;
290 vpCircle circle;
291 circle.p[index_0] = x;
292 circle.p[index_1] = y;
293 circle.p[index_2] = n20;
294 circle.p[index_3] = n11;
295 circle.p[index_4] = n02;
296
297 vpMeterPixelConversion::convertEllipse(cam, circle, center, n20_p, n11_p, n02_p);
298 vpDisplay::displayEllipse(I, center, n20_p, n11_p, n02_p, true, color, thickness);
299}
300END_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 ...
void set_ij(double ii, double jj)
Definition of the vpImage class member functions.
Definition vpImage.h:131
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