Visual Servoing Platform version 3.5.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
46int 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 const std::string visp = "ViSP: Open source Visual Servoing Platform";
63
64 //vpRGBa
65 {
66 vpImage<vpRGBa> I(480, 640, vpRGBa(255));
67 vpImagePoint iP1, iP2;
68
69 iP1.set_i(20);
70 iP1.set_j(10);
71 iP2.set_i(20);
72 iP2.set_j(30);
73 vpImageDraw::drawArrow(I, iP1, iP2, vpColor::green, 4, 2, 3);
74
75 iP1.set_i(20);
76 iP1.set_j(60);
77 vpFont font(32);
78 font.drawText(I, "Test...", iP1, vpColor::blue);
79
80 iP1.set_i(60);
81 iP1.set_j(60);
82 font.drawText(I, "...tse", iP1, vpColor::red);
83
84 iP1.set_i(60);
85 iP1.set_j(260);
86 font.drawText(I, "&é(-è_çà)", iP1, vpColor::red);
87
88 iP1.set_i(200);
89 iP1.set_j(200);
90 font.drawText(I, "Test...", iP1, vpColor::white, vpColor::black);
91
92 vpFont font2(20);
93 vpImagePoint textSize = font2.getMeasure(visp);
94 vpImagePoint textPos = vpImagePoint(24, 620 - textSize.get_j());
95 font2.drawText(I, visp, textPos, vpColor::darkGreen);
96 vpImageDraw::drawRectangle(I, vpRect(textPos.get_u(), textPos.get_v(), textSize.get_u(), textSize.get_v()), vpColor::darkRed);
97
98 iP1.set_i(80);
99 iP1.set_j(220);
100 iP2.set_i(80);
101 iP2.set_j(480);
103
104 iP1.set_i(20);
105 iP1.set_j(220);
107
108 iP1.set_i(140);
109 iP1.set_j(10);
110 iP2.set_i(140);
111 iP2.set_j(50);
113
114 iP1.set_i(120);
115 iP1.set_j(180);
116 iP2.set_i(160);
117 iP2.set_j(250);
119
120 iP1.set_i(160);
121 iP1.set_j(280);
122 iP2.set_i(120);
123 iP2.set_j(340);
125
126 iP1.set_i(220);
127 iP1.set_j(400);
128 iP2.set_i(120);
129 iP2.set_j(400);
131
132 iP1.set_i(220);
133 iP1.set_j(480);
134 iP2.set_i(120);
135 iP2.set_j(450);
137
138 vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
139 vpCameraParameters cam(600, 600, 320, 240);
140 vpImageDraw::drawFrame(I, cMo, cam, 0.05, vpColor::none, 3);
141
142 iP1.set_i(140);
143 iP1.set_j(80);
144 iP2.set_i(140);
145 iP2.set_j(150);
146 vpImageDraw::drawLine(I, iP1, iP2, vpColor::orange, 3);
147
148 iP1.set_i(140);
149 iP1.set_j(400);
151
152 iP1.set_i(350);
153 iP1.set_j(20);
154 int w = 60;
155 int h = 50;
156 vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), vpColor::red, false, 3);
157
158 iP1.set_i(350);
159 iP1.set_j(110);
160 vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), vpColor::red, true, 3);
161
162 iP1.set_i(350);
163 iP1.set_j(200);
164 iP2.set_i(400);
165 iP2.set_j(260);
166 vpImageDraw::drawRectangle(I, vpRect(iP1, iP2), vpColor::orange, false, 3);
167
168 iP1.set_i(350);
169 iP1.set_j(290);
170 iP2.set_i(400);
171 iP2.set_j(350);
172 vpRect rectangle(iP1, iP2);
173 vpImageDraw::drawRectangle(I, rectangle, vpColor::yellow, false, 3);
174
175 std::vector<vpImagePoint> polygon;
176 polygon.push_back(vpImagePoint(250, 500));
177 polygon.push_back(vpImagePoint(350, 600));
178 polygon.push_back(vpImagePoint(450, 500));
179 polygon.push_back(vpImagePoint(350, 400));
181
182 polygon.clear();
183 polygon.push_back(vpImagePoint(300, 500));
184 polygon.push_back(vpImagePoint(350, 550));
185 polygon.push_back(vpImagePoint(400, 500));
186 polygon.push_back(vpImagePoint(350, 450));
187 vpImageDraw::drawPolygon(I, polygon, vpColor::cyan, 3, false);
188
189 if (save) {
190 std::string filename = "canvas_color.png";
191 std::cout << "Save " << filename << std::endl;
192 vpImageIo::write(I, filename);
193 }
194 }
195
196 //unsigned char
197 {
198 vpImage<unsigned char> I(480, 640, 0);
199 vpImagePoint iP1, iP2;
200 unsigned char color = 255;
201
202 iP1.set_i(20);
203 iP1.set_j(10);
204 iP2.set_i(20);
205 iP2.set_j(30);
206 vpImageDraw::drawArrow(I, iP1, iP2, color, 4, 2, 3);
207
208 iP1.set_i(20);
209 iP1.set_j(60);
210 vpFont font(32);
211 font.drawText(I, "Test...", iP1, color);
212
213 iP1.set_i(60);
214 iP1.set_j(60);
215 font.drawText(I, "...tse", iP1, color);
216
217 iP1.set_i(60);
218 iP1.set_j(260);
219 font.drawText(I, "&é(-è_çà)", iP1, color);
220
221 iP1.set_i(200);
222 iP1.set_j(200);
223 font.drawText(I, "Test...", iP1, 0, 255);
224
225 vpFont font2(20);
226 vpImagePoint textSize = font2.getMeasure(visp);
227 vpImagePoint textPos = vpImagePoint(24, 620 - textSize.get_j());
228 font2.drawText(I, visp, textPos, 255);
229 vpImageDraw::drawRectangle(I, vpRect(textPos.get_u(), textPos.get_v(), textSize.get_u(), textSize.get_v()), 255);
230
231 iP1.set_i(80);
232 iP1.set_j(220);
233 iP2.set_i(80);
234 iP2.set_j(480);
235 vpImageDraw::drawCircle(I, iP1, 30, color, 3);
236
237 iP1.set_i(20);
238 iP1.set_j(220);
239 vpImageDraw::drawCross(I, iP1, 5, color, 1);
240
241 iP1.set_i(140);
242 iP1.set_j(10);
243 iP2.set_i(140);
244 iP2.set_j(50);
245 vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
246
247 iP1.set_i(120);
248 iP1.set_j(180);
249 iP2.set_i(160);
250 iP2.set_j(250);
251 vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
252
253 iP1.set_i(160);
254 iP1.set_j(280);
255 iP2.set_i(120);
256 iP2.set_j(340);
257 vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
258
259 iP1.set_i(220);
260 iP1.set_j(400);
261 iP2.set_i(120);
262 iP2.set_j(400);
263 vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
264
265 iP1.set_i(220);
266 iP1.set_j(480);
267 iP2.set_i(120);
268 iP2.set_j(450);
269 vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
270
271 vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
272 vpCameraParameters cam(600, 600, 320, 240);
273 vpImageDraw::drawFrame(I, cMo, cam, 0.05, color, 3);
274
275 iP1.set_i(140);
276 iP1.set_j(80);
277 iP2.set_i(140);
278 iP2.set_j(150);
279 vpImageDraw::drawLine(I, iP1, iP2, color, 3);
280
281 iP1.set_i(140);
282 iP1.set_j(400);
283 vpImageDraw::drawPoint(I, iP1, color);
284
285 iP1.set_i(350);
286 iP1.set_j(20);
287 int w = 60;
288 int h = 50;
289 vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), color, false, 3);
290
291 iP1.set_i(350);
292 iP1.set_j(110);
293 vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), color, true, 3);
294
295 iP1.set_i(350);
296 iP1.set_j(200);
297 iP2.set_i(400);
298 iP2.set_j(260);
299 vpImageDraw::drawRectangle(I, vpRect(iP1, iP2), color, false, 3);
300
301 iP1.set_i(350);
302 iP1.set_j(290);
303 iP2.set_i(400);
304 iP2.set_j(350);
305 vpRect rectangle(iP1, iP2);
306 vpImageDraw::drawRectangle(I, rectangle, color, false, 3);
307
308 std::vector<vpImagePoint> polygon;
309 polygon.push_back(vpImagePoint(250, 500));
310 polygon.push_back(vpImagePoint(350, 600));
311 polygon.push_back(vpImagePoint(450, 500));
312 polygon.push_back(vpImagePoint(350, 400));
313 vpImageDraw::drawPolygon(I, polygon, color, 3);
314
315 polygon.clear();
316 polygon.push_back(vpImagePoint(300, 500));
317 polygon.push_back(vpImagePoint(350, 550));
318 polygon.push_back(vpImagePoint(400, 500));
319 polygon.push_back(vpImagePoint(350, 450));
320 vpImageDraw::drawPolygon(I, polygon, color, 3, false);
321
322 if (save) {
323 std::string filename = "canvas_gray.png";
324 std::cout << "Save " << filename << std::endl;
325 vpImageIo::write(I, filename);
326 }
327 }
328
329 return EXIT_SUCCESS;
330}
Generic class defining intrinsic camera parameters.
static const vpColor white
Definition: vpColor.h:212
static const vpColor red
Definition: vpColor.h:217
static const vpColor black
Definition: vpColor.h:211
static const vpColor cyan
Definition: vpColor.h:226
static const vpColor none
Definition: vpColor.h:229
static const vpColor orange
Definition: vpColor.h:227
static const vpColor darkRed
Definition: vpColor.h:218
static const vpColor blue
Definition: vpColor.h:223
static const vpColor darkGreen
Definition: vpColor.h:221
static const vpColor yellow
Definition: vpColor.h:225
static const vpColor green
Definition: vpColor.h:220
Font drawing functions for image.
Definition: vpFont.h:56
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void drawRectangle(vpImage< unsigned char > &I, const vpRect &rectangle, unsigned char color, bool fill=false, unsigned int thickness=1)
static void drawCircle(vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, unsigned char color, unsigned int thickness=1)
static void drawLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
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 void drawPoint(vpImage< unsigned char > &I, const vpImagePoint &ip, 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 drawPolygon(vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, unsigned char color, unsigned int thickness=1, bool closed=true)
static void drawCross(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, unsigned char color, unsigned int thickness=1)
static void drawDottedLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:293
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
void set_j(double jj)
Definition: vpImagePoint.h:177
double get_j() const
Definition: vpImagePoint.h:214
void set_i(double ii)
Definition: vpImagePoint.h:166
double get_u() const
Definition: vpImagePoint.h:262
double get_v() const
Definition: vpImagePoint.h:273
Definition: vpRGBa.h:67
Defines a rectangle in the plane.
Definition: vpRect.h:80
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:184
Class that consider the case of a translation vector.