Visual Servoing Platform  version 3.4.0
testImageDraw.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  * Test for vpImageDraw class.
33  *
34  *****************************************************************************/
41 #include <iostream>
42 #include <visp3/core/vpImageDraw.h>
43 #include <visp3/core/vpFont.h>
44 #include <visp3/io/vpImageIo.h>
45 
46 int main(int argc ,char *argv[])
47 {
48  bool save = false;
49  for (int i = 1; i < argc; i++) {
50  if (std::string(argv[i]) == "--save") {
51  save = true;
52  }
53  else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
54  std::cout << "\nUsage: " << argv[0]
55  << " [--save] [--help] [-h]\n"
56  << std::endl;
57  return 0;
58  }
59  }
60  std::cout << "Save: " << save << std::endl;
61 
62  //vpRGBa
63  {
64  vpImage<vpRGBa> I(480, 640, vpRGBa(255));
65  vpImagePoint iP1, iP2;
66 
67  iP1.set_i(20);
68  iP1.set_j(10);
69  iP2.set_i(20);
70  iP2.set_j(30);
71  vpImageDraw::drawArrow(I, iP1, iP2, vpColor::green, 4, 2, 3);
72 
73  iP1.set_i(20);
74  iP1.set_j(60);
75  vpFont font(32);
76  font.drawText(I, "Test...", iP1, vpColor::blue);
77 
78  iP1.set_i(200);
79  iP1.set_j(200);
80  font.drawText(I, "Test...", iP1, vpColor::white, vpColor::black);
81 
82  iP1.set_i(80);
83  iP1.set_j(220);
84  iP2.set_i(80);
85  iP2.set_j(480);
86  vpImageDraw::drawCircle(I, iP1, 30, vpColor::red, 3);
87 
88  iP1.set_i(20);
89  iP1.set_j(220);
91 
92  iP1.set_i(140);
93  iP1.set_j(10);
94  iP2.set_i(140);
95  iP2.set_j(50);
97 
98  iP1.set_i(120);
99  iP1.set_j(180);
100  iP2.set_i(160);
101  iP2.set_j(250);
103 
104  iP1.set_i(160);
105  iP1.set_j(280);
106  iP2.set_i(120);
107  iP2.set_j(340);
109 
110  iP1.set_i(220);
111  iP1.set_j(400);
112  iP2.set_i(120);
113  iP2.set_j(400);
115 
116  iP1.set_i(220);
117  iP1.set_j(480);
118  iP2.set_i(120);
119  iP2.set_j(450);
121 
122  vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
123  vpCameraParameters cam(600, 600, 320, 240);
124  vpImageDraw::drawFrame(I, cMo, cam, 0.05, vpColor::none, 3);
125 
126  iP1.set_i(140);
127  iP1.set_j(80);
128  iP2.set_i(140);
129  iP2.set_j(150);
130  vpImageDraw::drawLine(I, iP1, iP2, vpColor::orange, 3);
131 
132  iP1.set_i(140);
133  iP1.set_j(400);
135 
136  iP1.set_i(350);
137  iP1.set_j(20);
138  int w = 60;
139  int h = 50;
140  vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), vpColor::red, false, 3);
141 
142  iP1.set_i(350);
143  iP1.set_j(110);
144  vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), vpColor::red, true, 3);
145 
146  iP1.set_i(350);
147  iP1.set_j(200);
148  iP2.set_i(400);
149  iP2.set_j(260);
150  vpImageDraw::drawRectangle(I, vpRect(iP1, iP2), vpColor::orange, false, 3);
151 
152  iP1.set_i(350);
153  iP1.set_j(290);
154  iP2.set_i(400);
155  iP2.set_j(350);
156  vpRect rectangle(iP1, iP2);
157  vpImageDraw::drawRectangle(I, rectangle, vpColor::yellow, false, 3);
158 
159  std::vector<vpImagePoint> polygon;
160  polygon.push_back(vpImagePoint(250, 500));
161  polygon.push_back(vpImagePoint(350, 600));
162  polygon.push_back(vpImagePoint(450, 500));
163  polygon.push_back(vpImagePoint(350, 400));
165 
166  polygon.clear();
167  polygon.push_back(vpImagePoint(300, 500));
168  polygon.push_back(vpImagePoint(350, 550));
169  polygon.push_back(vpImagePoint(400, 500));
170  polygon.push_back(vpImagePoint(350, 450));
171  vpImageDraw::drawPolygon(I, polygon, vpColor::cyan, 3, false);
172 
173  if (save) {
174  std::string filename = "canvas_color.png";
175  std::cout << "Save " << filename << std::endl;
176  vpImageIo::write(I, filename);
177  }
178  }
179 
180  //unsigned char
181  {
182  vpImage<unsigned char> I(480, 640, 0);
183  vpImagePoint iP1, iP2;
184  unsigned char color = 255;
185 
186  iP1.set_i(20);
187  iP1.set_j(10);
188  iP2.set_i(20);
189  iP2.set_j(30);
190  vpImageDraw::drawArrow(I, iP1, iP2, color, 4, 2, 3);
191 
192  iP1.set_i(20);
193  iP1.set_j(60);
194  vpFont font(32);
195  font.drawText(I, "Test...", iP1, color);
196 
197  iP1.set_i(200);
198  iP1.set_j(200);
199  font.drawText(I, "Test...", iP1, 0, 255);
200 
201  iP1.set_i(80);
202  iP1.set_j(220);
203  iP2.set_i(80);
204  iP2.set_j(480);
205  vpImageDraw::drawCircle(I, iP1, 30, color, 3);
206 
207  iP1.set_i(20);
208  iP1.set_j(220);
209  vpImageDraw::drawCross(I, iP1, 5, color, 1);
210 
211  iP1.set_i(140);
212  iP1.set_j(10);
213  iP2.set_i(140);
214  iP2.set_j(50);
215  vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
216 
217  iP1.set_i(120);
218  iP1.set_j(180);
219  iP2.set_i(160);
220  iP2.set_j(250);
221  vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
222 
223  iP1.set_i(160);
224  iP1.set_j(280);
225  iP2.set_i(120);
226  iP2.set_j(340);
227  vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
228 
229  iP1.set_i(220);
230  iP1.set_j(400);
231  iP2.set_i(120);
232  iP2.set_j(400);
233  vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
234 
235  iP1.set_i(220);
236  iP1.set_j(480);
237  iP2.set_i(120);
238  iP2.set_j(450);
239  vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
240 
241  vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
242  vpCameraParameters cam(600, 600, 320, 240);
243  vpImageDraw::drawFrame(I, cMo, cam, 0.05, color, 3);
244 
245  iP1.set_i(140);
246  iP1.set_j(80);
247  iP2.set_i(140);
248  iP2.set_j(150);
249  vpImageDraw::drawLine(I, iP1, iP2, color, 3);
250 
251  iP1.set_i(140);
252  iP1.set_j(400);
253  vpImageDraw::drawPoint(I, iP1, color);
254 
255  iP1.set_i(350);
256  iP1.set_j(20);
257  int w = 60;
258  int h = 50;
259  vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), color, false, 3);
260 
261  iP1.set_i(350);
262  iP1.set_j(110);
263  vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), color, true, 3);
264 
265  iP1.set_i(350);
266  iP1.set_j(200);
267  iP2.set_i(400);
268  iP2.set_j(260);
269  vpImageDraw::drawRectangle(I, vpRect(iP1, iP2), color, false, 3);
270 
271  iP1.set_i(350);
272  iP1.set_j(290);
273  iP2.set_i(400);
274  iP2.set_j(350);
275  vpRect rectangle(iP1, iP2);
276  vpImageDraw::drawRectangle(I, rectangle, color, false, 3);
277 
278  std::vector<vpImagePoint> polygon;
279  polygon.push_back(vpImagePoint(250, 500));
280  polygon.push_back(vpImagePoint(350, 600));
281  polygon.push_back(vpImagePoint(450, 500));
282  polygon.push_back(vpImagePoint(350, 400));
283  vpImageDraw::drawPolygon(I, polygon, color, 3);
284 
285  polygon.clear();
286  polygon.push_back(vpImagePoint(300, 500));
287  polygon.push_back(vpImagePoint(350, 550));
288  polygon.push_back(vpImagePoint(400, 500));
289  polygon.push_back(vpImagePoint(350, 450));
290  vpImageDraw::drawPolygon(I, polygon, color, 3, false);
291 
292  if (save) {
293  std::string filename = "canvas_gray.png";
294  std::cout << "Save " << filename << std::endl;
295  vpImageIo::write(I, filename);
296  }
297  }
298 
299  return EXIT_SUCCESS;
300 }
static void drawRectangle(vpImage< unsigned char > &I, const vpRect &rectangle, unsigned char color, bool fill=false, unsigned int thickness=1)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static const vpColor black
Definition: vpColor.h:211
static void drawCircle(vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, unsigned char color, unsigned int thickness=1)
static void drawFrame(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, unsigned char color, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
static void drawArrow(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static const vpColor none
Definition: vpColor.h:229
static void drawDottedLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
static const vpColor green
Definition: vpColor.h:220
Definition: vpRGBa.h:66
static const vpColor red
Definition: vpColor.h:217
static const vpColor orange
Definition: vpColor.h:227
Implementation of a rotation matrix and operations on such kind of matrices.
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:445
static const vpColor cyan
Definition: vpColor.h:226
void set_i(double ii)
Definition: vpImagePoint.h:166
static void drawPoint(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned char color, unsigned int thickness=1)
Generic class defining intrinsic camera parameters.
Font drawing functions for image.
Definition: vpFont.h:55
void set_j(double jj)
Definition: vpImagePoint.h:177
static void drawCross(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, unsigned char color, unsigned int thickness=1)
static void drawPolygon(vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, unsigned char color, unsigned int thickness=1, bool closed=true)
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
Defines a rectangle in the plane.
Definition: vpRect.h:79
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
static const vpColor yellow
Definition: vpColor.h:225
static const vpColor white
Definition: vpColor.h:212
static void drawLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
Class that consider the case of a translation vector.
static const vpColor blue
Definition: vpColor.h:223