Visual Servoing Platform  version 3.2.1 under development (2019-09-17) under development (2019-09-17)
vpFeatureDisplay.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Interface with the image for feature display.
33  *
34  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #include <visp3/core/vpFeatureDisplay.h>
41 
42 // Meter/pixel conversion
43 #include <visp3/core/vpMeterPixelConversion.h>
44 
45 // display
46 #include <visp3/core/vpDisplay.h>
47 
48 // Debug trace
49 #include <visp3/core/vpDebug.h>
50 
51 // math
52 #include <visp3/core/vpMath.h>
53 
54 #include <visp3/core/vpImagePoint.h>
55 
67 void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<unsigned char> &I,
68  const vpColor &color, unsigned int thickness)
69 {
70  vpImagePoint ip; // pixel coordinates in float
72  vpDisplay::displayCross(I, ip, 15, color, thickness);
73 }
74 
85 void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam,
86  const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness)
87 {
88  // x cos(theta) + y sin(theta) - rho = 0
89  double rhop, thetap;
90  vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
91 
92  // u cos(thetap) + v sin(thetap) - rhop = 0
93  double co = cos(thetap);
94  double si = sin(thetap);
95  double c = -rhop;
96 
97  double a = si;
98  double b = co;
99  vpImagePoint ip1, ip2;
100 
101  if (fabs(a) < fabs(b)) {
102  ip1.set_ij(0, (-c) / b);
103  double h = I.getHeight() - 1;
104  ip2.set_ij(h, (-c - a * h) / b);
105  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
106  } else {
107  ip1.set_ij((-c) / a, 0);
108  double w = I.getWidth() - 1;
109  ip2.set_ij((-c - b * w) / a, w);
110  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
111  }
112 }
113 
125 void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
126  const vpCameraParameters &cam, const vpImage<unsigned char> &I,
127  const vpColor &color, unsigned int thickness)
128 {
129  displayLine(rho1, theta1, cam, I, color, thickness);
130  displayLine(rho2, theta2, cam, I, color, thickness);
131 }
132 
148 void vpFeatureDisplay::displayEllipse(double x, double y, double mu20, double mu11, double mu02,
149  const vpCameraParameters &cam, const vpImage<unsigned char> &I,
150  const vpColor &color, unsigned int thickness)
151 {
152  vpImagePoint center;
153  double mu20_p, mu11_p, mu02_p;
154  vpCircle circle;
155  circle.p[0] = x;
156  circle.p[1] = y;
157  circle.p[2] = mu20;
158  circle.p[3] = mu11;
159  circle.p[4] = mu02;
160 
161  vpMeterPixelConversion::convertEllipse(cam, circle, center, mu20_p, mu11_p, mu02_p);
162  vpDisplay::displayEllipse(I, center, mu20_p, mu11_p, mu02_p, true, color, thickness);
163 }
164 
176 void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
177  const vpColor &color, unsigned int thickness)
178 {
179  vpImagePoint ip; // pixel coordinates in float
181 
182  vpDisplay::displayCross(I, ip, 15, color, thickness);
183 }
184 
195 void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
196  const vpColor &color, unsigned int thickness)
197 {
198  // x cos(theta) + y sin(theta) - rho = 0
199  double rhop, thetap;
200  vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);
201 
202  // u cos(thetap) + v sin(thetap) - rhop = 0
203  double co = cos(thetap);
204  double si = sin(thetap);
205  double c = -rhop;
206 
207  double a = si;
208  double b = co;
209  vpImagePoint ip1, ip2;
210 
211  if (fabs(a) < fabs(b)) {
212  ip1.set_ij(0, (-c) / b);
213  double h = I.getHeight() - 1;
214  ip2.set_ij(h, (-c - a * h) / b);
215  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
216  } else {
217  ip1.set_ij((-c) / a, 0);
218  double w = I.getWidth() - 1;
219  ip2.set_ij((-c - b * w) / a, w);
220  vpDisplay::displayLine(I, ip1, ip2, color, thickness);
221  }
222 }
223 
235 void vpFeatureDisplay::displayCylinder(double rho1, double theta1, double rho2, double theta2,
236  const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
237  unsigned int thickness)
238 {
239  displayLine(rho1, theta1, cam, I, color, thickness);
240  displayLine(rho2, theta2, cam, I, color, thickness);
241 }
242 
258 void vpFeatureDisplay::displayEllipse(double x, double y, double mu20, double mu11, double mu02,
259  const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color,
260  unsigned int thickness)
261 {
262  vpImagePoint center;
263  double mu20_p, mu11_p, mu02_p;
264  vpCircle circle;
265  circle.p[0] = x;
266  circle.p[1] = y;
267  circle.p[2] = mu20;
268  circle.p[3] = mu11;
269  circle.p[4] = mu02;
270 
271  vpMeterPixelConversion::convertEllipse(cam, circle, center, mu20_p, mu11_p, mu02_p);
272  vpDisplay::displayEllipse(I, center, mu20_p, mu11_p, mu02_p, true, color, thickness);
273 }
static void displayEllipse(const vpImage< unsigned char > &I, const vpImagePoint &center, const double &coef1, const double &coef2, const double &coef3, bool use_centered_moments, const vpColor &color, unsigned int thickness=1)
static void convertEllipse(const vpCameraParameters &cam, const vpSphere &sphere, vpImagePoint &center, double &mu20_p, double &mu11_p, double &mu02_p)
static void displayEllipse(double x, double y, double mu20, double mu11, double m02, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, 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 convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static void displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
Generic class defining intrinsic camera parameters.
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
unsigned int getHeight() const
Definition: vpImage.h:186
static void displayLine(double rho, double theta, 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:88
Class that defines what is a circle.
Definition: vpCircle.h:58
unsigned int getWidth() const
Definition: vpImage.h:244
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
vpColVector p
Definition: vpTracker.h:71
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:189