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