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