[No audio]
Well, I hope you solve the exercise, and
I believe it was not a difficult one. My
purpose there was to get you used to
with the OpenCV code, and also why not
to practice a for loop. So, as you can
imagine, this exercise will be solved by
using a for loop. So, let me go through
the code line by line quickly. So, we
have to import OpenCV, so cv2 and the global
library. If you can recall it
what a globe does is that it finds a path names
of some files given a certain pattern.
So, in this case, for instance, I have
this jpg files here, so, 1, 2, 3, 4, 5 images,
and I said, Okay, create a list of file
names that contain everything in the
first part, and then jpg as
extension. So that will create a list such as,
say, like C and then the path
here and then galaxy.jpg, and
then the other image path and so on.
You'll get the idea, and then what we need
to do is iterate through this list for
each path, image path in the list, in this
list, we'll do these operations for each
of the list items. So first, we will
read that image path. Okay, that image
file actually as a black and white
image. So 0 is a flag is argument,
which implies an image should write as
black and white, in either grayscale
actually, and then we create a variable
where we will store the resized
images, so the image is 100 by 100. So
I'm passing the origin of the image here
and their size, the new size that the
image will get, and then we want to show the
image just for demonstration, it's not
really important, but it lets you check
all the images that are being resized,
and this is the name of the window, and
then I pass here a waitKey method, and
500 means 500 milliseconds. So each
image will show and it will wait for
half a second. So 500 milliseconds, and
then after this half a second, Python
will go to the next line and then to the
next, and then it will go to the next item
of the list and so on. So waitKey 500
milliseconds, and then we have destroyAllWindows
after this time passes, and then
we write the resized_image. So re was
a variable that holds the image object,
the resized_image object, and this here,
all this is a new name of the file. So
what we get here is so we will have
resized in the beginning of the image
name and then just after that we
will have a name of the original image.
So for instance, we would have, for
galaxy, we would have resized galaxy.jpg.
So image here would be galaxy.jpg,
which is this one here, and
yeah, because the script is inside this
folder, this list actually, the image
of the list, would look something like
galaxy.jpg, and then kangaroo,
you know, australia.jpg, and so on. So
[No audio]
this gets the relative paths of the files.
We're not getting the full path. Okay, I
hope that is clear. So resized_galaxy,
we could add underscore so that
we discriminate the resized word from the
other image name. Great, let me execute this
python script.
[No audio]
So half a second, half a
second, and yeah, its done, and let's check the
images. So from here up are the original
images and these are the image products.
So you can see here that all these are
100 by 100, and they are in a grayscale.
[No audio]
Okay, that's it. See you in the next lecture.
[No audio]