Hi and welcome back to our first instructional lesson on OpenCV.
So assuming you have the code on your Google Drive now, like I showed you in the previous video, I
want you to take a look at the two folders here.
Now the code is split into two sections open CV and deep learning curve.
Those are the two schools of thought with computer vision, and it's good to have them separated because
you can do a lot of different things with open TV and then a lot of different things with deep learning,
and they're quite different in reality, which we which we will see in discourse.
So let's take a look at the open TV chapter first, because that's the intro.
However, if you don't need to want to learn this, as I said in previous videos, you can skip all
of these lessons.
It's not great, but you can still do a lot of complicated computer vision stuff without doing this
open civil chapter.
So let's open up the folder.
And now you see that all of these I Python notebooks i python sensible, interactive Python notebook.
And it's a really, really cool way of actually coding and cellblocks.
And these cellblocks allow us to prototype small bits of could quite easily, which you will see shortly.
So we can take a look and see there's a lot of lessons right here.
And then there's a section called Looking with video, which we run on a local machine, which when
we come to that, I'll show you guys how to do that.
So let's open the first chapter here called Getting Started.
And you can see you have some descriptions of the lessons of the topics and the lessons here.
All of these videos have descriptions here, so can help you in future.
When you quickly want to find something like how to do filtering colors, you can just search for their
control F..
So let's get into this first notebook.
So there we go, the first notebook is loaded.
So all of these notebooks have basically the style where getting started as a topic lesson in the beginning
here cool getting started and I usually highlight in point form or description what the lesson is about.
So this helps you just understand before you see the scroll down to everything down here, you can quickly
just see what the what the lesson encompasses right here.
So let's begin.
So the first thing we have to do before using any open CV functions is to import, to CV, to library.
Now in Python, you do that by calling the import function here and then calling the library.
We want to call it right here.
So fortunately, Google Club, which is this amazing, awesome tool for using, has so many libraries
already installed on the system, so we don't have to actually install open here.
However, if we wanted to do it, it would actually be quite easy to do and we will do some installs
in later chapters.
But for now, all you have to do is just import CB2.
So let's run that so you can run it by clicking this little play play button here, or you can see the
shortcut for a day or so.
I'm going to Mac, so I'm going to do a control center.
However, it's the same on Windows actually command into sorry, so we can do it here and in a couple
of seconds that runs and loads the library.
So just a few things about collab, which we have gone through before, but you can see around and this
usage here, you can see what different options that's going on here.
We're actually going to use those.
There's a lot of things up here you can do with moving cells and deleting cells and inserting code blocks
and text blocks.
Some functions here.
You will probably need to restart runtime or even factory reset runtime, sometimes not often, but
we want to look at that.
Yet that's not too important to be concerned with those things yet.
So let's see.
We've imported reloaded and imported open CV's library called CB2 in Python.
Now, let's see the vision to do that.
All you have to do is use two and the scores here.
Vision two underscores and we can just print it here.
We don't need to actually print.
Used a print function here because it will still display below.
But in Python cells, only the last block on the last line of code, I should say, gets printed to
the to the output here.
So if you were to actually do this twice, you'd only.
And we removed a print.
Whoops.
And then, Stuart, over here, you'll see it only printed once right now below, but if we were to
put back to print function, still, let's put back another print here.
You'll see it printed twice.
So anyway, the whole point of that exercise actually is just to see that we're using open v 4.1.2.
That's the library.
That's a vision of open C v that club is using in the background or pre-installed.
We can update to new one if you wanted.
However, we're going to use 4.1.2 for this course because it has to put all of the features we're doing.
It's probably fully compatible and tested with other libraries in Colaba, so let's stick with what
the default.
See the equation.
They use it here.
So what we're going to do now, we're going to download some images.
No, don't worry about what is lines of code are doing.
All this is doing is just getting the images of zipped in a folder on my Google Drive.
This is the link on my Google Drive.
To that folder is is grown, which is a program, a Python program actually that downloads files from
Google for Google drives, and we can use it unzip program as well.
When you have an exclamation mark, you're running files in, you're running on bash at that point.
So what that means is that you're accessing the terminal through the notebook so you can actually access
it to indulge in a book and run system commands about command that scripts inside of the column.
That book, which is actually really cool.
However, I don't want you to focus on that yet.
What we're doing here, just getting images delivered to test open CV functions so you can see the files
downloaded here.
See, this is a zip file downloaded in the first line, and these are the unzipped images here.
You can see all of these test images here.
A lot of these things are things we are going to be using in discourse, so it will probably download
this folder many, many times.
So now let's load the images here.
So let's take a look at something important here.
File parts are important.
File parts are important because beginners often always make mistakes with file parts.
It's very, very common to actually mistype something here, and that results in a very common open
copy message error messages, which you'll see later on.
However, retno, this is the file part here.
It's flowers dot jpeg.
I did it mistakenly that due to the Aegis now, but anyway, let's run this.
We can run this here control center or shift.
And so even can all come to works in Windows 10 to actually create, believe a new line delete.
Yes, it does.
And that as well.
So what are we doing now?
You simply doing another import here?
This is from not plot level, and we're importing pipe lot as Pulte.
So to explain what's happening here.
We're importing the library pipe plots as Peltier right now, but that comes from the main library here
called Matterport Lib.
So we're importing these things here and we're going to use these these these plotting functions to
plot to basically show images here, which you can see below.
It's already being should.
So you've seen the image output right here, these here starting at the top left here zero and going
down to zero here.
It's a sort of aware of the convention, but just go with it.
You can see this as the pixels actually asked what I wanted to see.
So you can see this is roughly like maybe close to a thousand by roughly maybe twelve fifty or twelve
eighty something, but we can actually see later on, we can actually see what the windows are.
So let's run this control altogether.
And you can see it displays image.
So you should be assuming all of this doing this right now.
So, you know, one notebook so you can get the hang of running you an open TV could.
So to make sense for you, you can see we have to run these two lines of code to display this image.
Actually, I didn't discuss this.
Could this line let me do that now?
So you can see something quite interesting here.
Where are you calling this function called v two dot CVT color?
Take it!
It takes two arguments to input image and then this.
This parameter here called C v two dot color BGR two RGV.
What is this icon?
Why are we using it?
Well, what's weird is that Open C doesn't treat RG be in that order.
It treated as BGR, so we often actually have to reconvicted back to RG B if we wanted to split with
my plot lib.
So let's let's see what happens if you delete this line here and we just put the image back and we run
this, it's going to look weird.
And that's where it is, because what it thinks it is, our is actually B or Mitsubishi or OpenCV and
RG B and and not plot lib.
So because of that, we have to put this function here just to convert it right here.
That's all this does.
Just conflicts to color space of the image, which we'll discuss shortly with this because how images
are stored and what color spaces are.
So don't worry if those things sound alien or scary to you yet.
So let's make this little function here.
This is little function called show just basically takes the input image as an argument and also takes
the title, which we just left blank here.
And it just put the title on top of the image here and shows the image below.
So we can actually use that function like this right now.
So this is actually pretty cool and nifty little function that we'll be using a lot in discourse.
So let's just play our first image here.
And there we go.
So now we just need to do one line to display an image and we can actually put a title, which is quite
handy if you want to actually have things a bit more neat and organized, which I like to do.
So now let's move on into saving our images.
So to save an image?
It's actually quite simple.
It's a simple, open sea view function called cfy to the M right.
You input the file name if you want to save it as output a JPEG and we just call it the input, the
image variable that we were using previously.
We use that as the input here.
So let's run this.
You see, it returns true, which is good to know means it run successfully, and you can see it as
an output file here and output is the image.
That's the full image right here that we were actually looking and loaded before.
Remember, screw up slowly.
We loaded up this image here from a folder.
And no, we used to open C v function here output.
So Emirates to create this file called output that JPEG using the image variable that we load it here
because we loaded it as and stored it as image.
You can even see that as a PNG.
So let's do that.
And you can see this refresh to here and you'll see it as a PNG if that's what creates a do.
So great.
So that's been working fine.
So now let's take a look at the image dimensions.
So before I go into image dimensions, these are how images are created and stored in arrays.
So imagine remember, we have said we have BGR and RGV.
It's the same thing.
It's just different.
Every different color spaces you remember, we need three primary colors to create any color we want,
basically.
So we have to store the values of how much red, how much green, how much blue and picture it's stored
like a grid table.
Sort of like this, like a three dimensional table.
So you can see each one here corresponds like zero zero corresponds to the top right left pixel.
Then this one is the top, the second one.
And so each one here, each zero zero each coordinate to each pixel point has three values.
Those three values correspond to three color schemes here red, green and blue.
So that's how images are stored as two dimensional areas.
So whenever you're wondering how it is, what does this look like image?
This is basically what it looks like.
So no, let's print this.
So Dutch ship is a numpy function because open sea view stores images as Nampai functions no objects.
What Nampai is Nampai is a fast numerical library in Python that we use for all sorts of metrics and
cool little linear algebra calculations.
It's quite quick, quite well optimized.
So open to these slices are to store the images.
So it's a story as an image to as a Nampai array right here, so you can see by using the Dot ship.
So shape is a function that these objects can access that outputs the pyramidal dimensions in each direction
here.
Because this is a three dimensional area, you have tree values here.
This here is the height.
This is to wit, and this is a tree tree means that each of these values has tree sequences or tree
rows of values or tree depths or values or property that makes sense to you.
I'm not sure if I'm explaining that to right, but this diagram would help a lot in understanding that
concept.
So to excessive dimension.
Just to get what we want to get a height at a weight, you can just use zero to access to this value
in the tree.
So you could take a look at it here and we go.
So that's how you get this here.
So now let's take a look and just print out all the dimensions here in this nice little format here
so we can do this using the first format.
Actually, I don't use this anymore.
I tend to use the f string format in Python, but this is fine nevertheless.
So what this is saying is that whatever is in this format variable here, if argument's placed into
these curly brackets here inside of the string.
So now we're going to print the height to wit and the depth of the image.
Quite straightforward and good.
Good practice with Python.
So that concludes our first lesson here.
Let's quickly scroll up to the top and you can see this is what we have learned in this lesson.
How to import.
Once you've open TV model or library, I should say in Python.
How to load images.
Remember, we downloaded the images.
You can upload images directly here and load them in this book.
That's actually something I should encourage you to do just to get the feel of it.
You can display your images.
You can see we show I showed you how we use my plot lib to do that.
You can save your images if you want to actually save it.
After doing some cool operation on it, and you can get the dimensions just to get an understanding
of how images are stored and us installed on power is and how got access to the different dimensions.
So thank you.
Now, let's move on to the next lesson.