Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

STUDENT ARTHUR R.

COSTA: COMPUTER VISION ASSIGNMENT – SEPTEMBER 5, 2018 1

000
001
002
Demonstrative Project 1
003
004 Arthur Reichert Costa - 16/0024277 Departamento de Ciência da
005 arreico@gmail.com Comptutação
006
Universidade de Brasília
007
Campus Darcy Ribeiro, Asa Norte
Brasília-DF, CEP 70910-900, Brazil,
008
009
010
011
Abstract
012
013 In this project a software tool capable of marking all pixels in an image, video frames
014 or video stream from a camera less than 13 shades apart from another pixel chosen by
015 the user in the color space was developed, according to four requirements stipulated.
016
017
018 1 Introduction
019
020 The work here presented aims to demonstrate the possibilities of image manipulation soft-
021 ware and the developments already accomplished by others to make the writing process of
022 such software as straightforward as possible. In order to attain this, there were four require-
023 ments specifying the behaviour of the software that was implemented, aiming to demonstrate
024 basic operations often performed while working with image processing and machine vision.
025 At last but not least, it is important to mention OpenCV, and open source software library
026 heavily used in the present work to achieve the goals set by the requirements.
027
028
029
1.1 Requirements
030 The software was required to:
031
032 • 1) Be capable of opening an image file and allow the user to click on any pixel of
033 the image and be informed of its coordinates and RGB values (or intensity, if it is a
034 grayscale image) on the console.
035
036 • 2) Upon selection of a pixel by the user, the software must check the image and mark
037 red all pixels which are less than 13 shades apart from the selected pixel in the color
038 space.
039
040 • 3) Display a video and do the same operations described in requirements 1 and 2 to all
041 of its frames.
042
043 • 4) perform the same operations required on item 3 to the stream of a webcam.
044
c 2018. The copyright of this document resides with its authors.
045 It may be distributed unchanged freely in print or electronic forms.
2 STUDENT ARTHUR R. COSTA: COMPUTER VISION ASSIGNMENT – SEPTEMBER 5, 2018

1.2 OpenCV 046


047
2 Methodology 048
049
Aiming to carry out the tasks proposed in the requirements, the code for the software was 050
written in C++ (due to the previous familiarity of the author with it) using classes and code 051
from the OpenCV library. The first requirement was to open an image and be able to identify 052
the position and color coordinates of every pixel within it that the user selected. 053
To perform this, OpenCV already has functions and classes to store, read and manipulate 054
images. The most used class to store an image is the Mat, whose objects can actually be 055
used to store any matrix, however it is particularly handful when it comes to storing images. 056
Reading an image from a file and assigning it to a Mat object is as simple as using: 057
058
Mat imagem; 059
imagem=imread("image file source", 1); 060
061
Identifying the position and color of a pixel on an image upon clicking on it (satisfying 062
the second requirement) is also painless, since upon creating a namedWindow object and
063
displaying an image in it, one can set a callback function that is executed every time a mouse
064
action occurs. Scanning the image looking for pixels at a specified range from a previously
065
chosen one in the color space is a bit lengthier than the previous tasks, but pretty much
066
elementary, since it is very simple and straightforward. The OpenCV library even has a
067
class specifically designed for that, the MatIterator , which provides iterator objects with
068
which one can sweep an image going through each pixel effortlessly. Being able to scan
every pixel in a matrix, to calculate the distance in the RGB color space between two given 069
pixels P1=(R1, G1, B1) and P2=(R2, G2, B2) the standard definition of distance from linear 070
algebra can be used, that is, the norm of the difference between two vectors, which is just 071
072
q
073
(R1 − R2)2 + (G1 − G2)2 + (B1 − B2)2 (1)
074
075
The third and fourth requirements are very similar to the first and second, except the
076
above described procedure has to be performed for every frame of a video file or camera
077
stream. Again, the OpenCV library got us covered, providing us with the VideoCapture
078
class, through which one can capture images from a webcam stream or a video file and put
079
them in Mat objects, reducing the third and fourth requirements to the same procedures done
080
in the first and second.
081
082
083
3 Results 084
085
The software developed to satisfy the goals of this work has a very crude interface: upon
086
calling the program, one or two parameters must be passed in the program’s call in the
terminal, the first is the operation mode, and accepts the values 1, 3 and 4, and the second, 087
when needed, is the name of a video or image file to be opened. I operation mode 1, the 088
program performs the actions described in requirements 1 and 2, whilst in operation modes 089
3 and 4 the program executes the operations and interactions specified in requirements 3 and 090
4. Some images of it in action: 091
STUDENT ARTHUR R. COSTA: COMPUTER VISION ASSIGNMENT – SEPTEMBER 5, 2018 3

092
093
094
095
096
097
098
099
100
101
102
103 Figure 1: Program marking wih red all pixels within a range of 13 from a selected pixel in
104 color space
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Figure 2: Program marking wih red all pixels within a range of 13 from a selected pixel in
119
color space from a video
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 Figure 3: Program marking wih red all pixels within a range of 13 from a selected pixel in
135 color space
136
137
4 STUDENT ARTHUR R. COSTA: COMPUTER VISION ASSIGNMENT – SEPTEMBER 5, 2018

4 Conclusions 138
139
The implementation of the software to comply with the requirements proposed was pretty 140
straightforward, using the classes and methods provided by the OpenCV library, since the 141
tasks were very simple. However, even using such a simple software as a tool and playing 142
with many images in it, one can notice a few interesting things. The author itself, for ex- 143
ample, tested many pictures with areas seemingly uniform in color, however, due to light 144
conditions and the very tight range adopted (13 out of 255 shades for each coordinate), the 145
software showed that such areas were not as uniform as previously thought, marking only a
146
small section of the area that the author thought was uniform.
147
148
References 149
150
1. https://docs.opencv.org/3.0-beta/doc/tutorials/core/how_to_151
scan_images/how_to_scan_images.html#howtoscanimagesopencv, 152
accessed at August 31st , 2018, by opencv.org 153
154
2. urlhttps://www.opencv-srf.com/2017/12/play-video-from-file-or-camera.html, accessed
155
at August 31st , 2018, by Shermal Fernando
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

You might also like