File: tutorial-basic-drawings.dox

package info (click to toggle)
visp 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 119,296 kB
  • sloc: cpp: 500,914; ansic: 52,904; xml: 22,642; python: 7,365; java: 4,247; sh: 482; makefile: 237; objc: 145
file content (154 lines) | stat: -rw-r--r-- 5,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
  \page tutorial-basic-drawings Tutorial: How to modify an image to insert basic drawings
  \tableofcontents

\section basic_drawings_intro Introduction

In this tutorial you will learn how to modify the content of an image adding basic drawings without the need of an image display window. This functionality could be useful if none of the following 3rd parties are available: <a href="https://visp.inria.fr/3rdparty_gui/">X11, GDI, OpenCV, GTK, Direct3D</a>.

\section basic_drawings_draw Modify an image with basic drawings

There is the vpImageDraw class that allows to modify an image by inserting basic drawings like point, circle, line, rectangle, polygon, frame. There is also vpFont class that allows to modify an image to insert text. These classes are used in testImageDraw.cpp.

If you run the corresponding binary:
\code
$ cd $VISP_WS/visp-build/modules/core
$ ./testImageDraw
\endcode
it will create `canvas_color.png` and `canvas_gray.png` images that give a good overview.

- Content of `canvas_color.png` image that shows basic drawings inserted in a color image implemented as a `vpImage<vpRGBa>` is the following:
\image html img-tutorial-drawings-color.png
- Content of `canvas_gray.png` image that shows basic drawings inserted in a gray level image implemented as a `vpImage<unsigned char>` is the following:
\image html img-tutorial-drawings-gray.png

\subsection basic_drawings_point Draw a point in an image

The following snippet shows how to modify color image I drawing a red point at pixel location (100, 200).

\code
vpImage<vpRGBa> I(480, 640);
vpImagePoint ip(100, 200);
vpImageDraw::drawPoint(I, ip, vpColor::red);
\endcode

The following snippet shows how to modify a gray level image I drawing a white point at pixel location (100, 200).

\code
vpImage<unsigned char> I(480, 640);
vpImagePoint ip(100, 200);
unsigned char color = 255; // white
vpImageDraw::drawPoint(I, ip, color);
\endcode

\subsection line Draw a line between 2 points

The following snippet shows how to modify color image I drawing an orange line with thickness 3 between pixels with coordinates (100, 200) and (300, 400).

\code
vpImage<vpRGBa> I(480, 640);
vpImagePoint ip1(100, 200);
vpImagePoint ip2(300, 400);
vpImageDraw::drawLine(I, ip1, ip2, vpColor::orange, 3);
\endcode

The following snippet shows how to modify gray level image I drawing a black line with thickness 3 between pixels with coordinates (100, 200) and (300, 400).

\code
vpImage<unsigned char> I(480, 640);
vpImagePoint ip1(100, 200);
vpImagePoint ip2(300, 400);
unsigned char color = 0; // black
vpImageDraw::drawLine(I, ip1, ip2, color, 3);
\endcode

\subsection circle Draw a circle

The following snippet shows how to modify color image I drawing a green cercle with thickness 3, centered at pixel location (100, 200) and with radius 80 pixels.

\code
vpImage<vpRGBa> I(480, 640);
vpImagePoint ip(100, 200);
vpImageDraw::drawCircle(I, ip, 80, vpColor::green, 3);
\endcode

The following snippet shows how to modify gray level image I drawing a gray cercle with thickness 3, centered at pixel location (100, 200) and with radius 80 pixels.

\code
vpImage<unsigned char> I(480, 640);
vpImagePoint ip(100, 200);
unsigned char color = 128; // gray
vpImageDraw::drawCircle(I, ip, 80, color, 3);
\endcode

\subsection rectangle Draw a rectangle

The following snippet shows how to modify color image I drawing a yellow rectangle with thickness 3, with top left corner location (100, 200), and rectangle width and height set to 150, 80 respectively.

\code
vpImage<vpRGBa> I(480, 640);
vpImagePoint ip(100, 200);
int w = 150;
int h = 80;
vpImageDraw::drawRectangle(I, vpRect(ip, w, h), vpColor::yellow, false, 3);
\endcode

The following snippet shows how to modify gray level image I drawing a light gray rectangle with thickness 3, with top left corner location (100, 200), and rectangle width and height set to 150, 80 respectively.

\code
vpImage<unsigned char> I(480, 640);
vpImagePoint ip(100, 200);
int w = 150;
int h = 80;
unsigned char color = 200; // light gray
vpImageDraw::drawRectangle(I, vpRect(ip, w, h), color, false, 3);
\endcode

\subsection cross Draw a cross

The following snippet shows how to modify color image I drawing a blue cross with thickness 3, location (100, 200), and size 15 pixels.

\code
vpImage<vpRGBa> I(480, 640);
vpImagePoint ip(100, 200);
int w = 150;
int h = 80;
vpImageDraw::drawCross(I, ip, 15, vpColor::blue, 1);
\endcode

The following snippet shows how to modify gray level image I drawing a dark gray cross with thickness 3, location (100, 200), and size 15 pixels.

\code
vpImage<unsigned char> I(480, 640);
vpImagePoint ip(100, 200);
int w = 150;
int h = 80;
unsigned char color = 50; // dark gray
vpImageDraw::drawCross(I, ip, 15, color, 1);
\endcode

\subsection basic_drawings_adding_text Insert text in an image

The following snippet shows how to modify color image I drawing "Hello world" in white over a black background at location (100, 200).

\code
vpImage<vpRGBa> I(480, 640);
vpImagePoint ip(100, 200);
font.drawText(I, "Test...", ip, vpColor::white, vpColor::black);
\endcode

The following snippet shows how to modify gray level image I drawing "Hello world" in white over a black background at location (100, 200).

\code
vpImage<unsigned char> I(480, 640);
vpImagePoint ip(100, 200);
unsigned char color = 255; // white
unsigned char background = 0; // black
font.drawText(I, "Test...", ip, color, background);
\endcode

\section basic_drawings_next Next tutorial

You are now ready to see how to continue with \ref tutorial-grabber.

*/