1
00:00:00,060 --> 00:00:04,670
Hi and welcome back to our first instructional lesson on OpenCV.

2
00:00:05,460 --> 00:00:10,830
So assuming you have the code on your Google Drive now, like I showed you in the previous video, I

3
00:00:10,830 --> 00:00:13,080
want you to take a look at the two folders here.

4
00:00:13,110 --> 00:00:17,820
Now the code is split into two sections open CV and deep learning curve.

5
00:00:18,420 --> 00:00:22,890
Those are the two schools of thought with computer vision, and it's good to have them separated because

6
00:00:22,890 --> 00:00:27,690
you can do a lot of different things with open TV and then a lot of different things with deep learning,

7
00:00:27,690 --> 00:00:32,820
and they're quite different in reality, which we which we will see in discourse.

8
00:00:33,330 --> 00:00:36,960
So let's take a look at the open TV chapter first, because that's the intro.

9
00:00:37,290 --> 00:00:42,600
However, if you don't need to want to learn this, as I said in previous videos, you can skip all

10
00:00:42,600 --> 00:00:43,400
of these lessons.

11
00:00:43,410 --> 00:00:49,350
It's not great, but you can still do a lot of complicated computer vision stuff without doing this

12
00:00:49,350 --> 00:00:50,460
open civil chapter.

13
00:00:51,000 --> 00:00:52,410
So let's open up the folder.

14
00:00:53,040 --> 00:00:59,550
And now you see that all of these I Python notebooks i python sensible, interactive Python notebook.

15
00:00:59,970 --> 00:01:03,750
And it's a really, really cool way of actually coding and cellblocks.

16
00:01:04,200 --> 00:01:09,870
And these cellblocks allow us to prototype small bits of could quite easily, which you will see shortly.

17
00:01:10,080 --> 00:01:14,820
So we can take a look and see there's a lot of lessons right here.

18
00:01:15,360 --> 00:01:19,410
And then there's a section called Looking with video, which we run on a local machine, which when

19
00:01:19,410 --> 00:01:21,420
we come to that, I'll show you guys how to do that.

20
00:01:22,020 --> 00:01:25,410
So let's open the first chapter here called Getting Started.

21
00:01:25,860 --> 00:01:30,270
And you can see you have some descriptions of the lessons of the topics and the lessons here.

22
00:01:30,900 --> 00:01:34,080
All of these videos have descriptions here, so can help you in future.

23
00:01:34,380 --> 00:01:39,450
When you quickly want to find something like how to do filtering colors, you can just search for their

24
00:01:39,870 --> 00:01:40,650
control F..

25
00:01:41,220 --> 00:01:43,590
So let's get into this first notebook.

26
00:01:48,320 --> 00:01:50,180
So there we go, the first notebook is loaded.

27
00:01:50,630 --> 00:01:56,600
So all of these notebooks have basically the style where getting started as a topic lesson in the beginning

28
00:01:56,600 --> 00:02:03,150
here cool getting started and I usually highlight in point form or description what the lesson is about.

29
00:02:03,170 --> 00:02:09,490
So this helps you just understand before you see the scroll down to everything down here, you can quickly

30
00:02:09,500 --> 00:02:12,770
just see what the what the lesson encompasses right here.

31
00:02:13,670 --> 00:02:15,140
So let's begin.

32
00:02:16,070 --> 00:02:23,150
So the first thing we have to do before using any open CV functions is to import, to CV, to library.

33
00:02:23,570 --> 00:02:29,090
Now in Python, you do that by calling the import function here and then calling the library.

34
00:02:29,090 --> 00:02:30,290
We want to call it right here.

35
00:02:30,920 --> 00:02:38,690
So fortunately, Google Club, which is this amazing, awesome tool for using, has so many libraries

36
00:02:38,690 --> 00:02:44,510
already installed on the system, so we don't have to actually install open here.

37
00:02:44,930 --> 00:02:49,130
However, if we wanted to do it, it would actually be quite easy to do and we will do some installs

38
00:02:49,460 --> 00:02:50,510
in later chapters.

39
00:02:50,510 --> 00:02:54,410
But for now, all you have to do is just import CB2.

40
00:02:54,770 --> 00:02:59,870
So let's run that so you can run it by clicking this little play play button here, or you can see the

41
00:02:59,870 --> 00:03:01,040
shortcut for a day or so.

42
00:03:01,040 --> 00:03:03,380
I'm going to Mac, so I'm going to do a control center.

43
00:03:03,860 --> 00:03:11,060
However, it's the same on Windows actually command into sorry, so we can do it here and in a couple

44
00:03:11,060 --> 00:03:13,070
of seconds that runs and loads the library.

45
00:03:14,660 --> 00:03:20,780
So just a few things about collab, which we have gone through before, but you can see around and this

46
00:03:20,780 --> 00:03:24,770
usage here, you can see what different options that's going on here.

47
00:03:25,640 --> 00:03:26,840
We're actually going to use those.

48
00:03:27,980 --> 00:03:35,180
There's a lot of things up here you can do with moving cells and deleting cells and inserting code blocks

49
00:03:35,180 --> 00:03:36,590
and text blocks.

50
00:03:37,520 --> 00:03:38,450
Some functions here.

51
00:03:38,450 --> 00:03:44,810
You will probably need to restart runtime or even factory reset runtime, sometimes not often, but

52
00:03:44,810 --> 00:03:45,800
we want to look at that.

53
00:03:45,800 --> 00:03:48,890
Yet that's not too important to be concerned with those things yet.

54
00:03:49,490 --> 00:03:50,810
So let's see.

55
00:03:51,050 --> 00:03:56,150
We've imported reloaded and imported open CV's library called CB2 in Python.

56
00:03:56,810 --> 00:03:58,680
Now, let's see the vision to do that.

57
00:03:58,700 --> 00:04:01,100
All you have to do is use two and the scores here.

58
00:04:01,460 --> 00:04:04,480
Vision two underscores and we can just print it here.

59
00:04:04,490 --> 00:04:05,720
We don't need to actually print.

60
00:04:06,140 --> 00:04:08,660
Used a print function here because it will still display below.

61
00:04:09,140 --> 00:04:16,760
But in Python cells, only the last block on the last line of code, I should say, gets printed to

62
00:04:16,760 --> 00:04:17,960
the to the output here.

63
00:04:18,500 --> 00:04:21,350
So if you were to actually do this twice, you'd only.

64
00:04:24,310 --> 00:04:25,420
And we removed a print.

65
00:04:26,900 --> 00:04:27,320
Whoops.

66
00:04:30,980 --> 00:04:38,900
And then, Stuart, over here, you'll see it only printed once right now below, but if we were to

67
00:04:38,900 --> 00:04:43,280
put back to print function, still, let's put back another print here.

68
00:04:43,910 --> 00:04:45,110
You'll see it printed twice.

69
00:04:45,120 --> 00:04:51,260
So anyway, the whole point of that exercise actually is just to see that we're using open v 4.1.2.

70
00:04:51,770 --> 00:04:52,580
That's the library.

71
00:04:52,580 --> 00:04:56,920
That's a vision of open C v that club is using in the background or pre-installed.

72
00:04:57,620 --> 00:04:59,840
We can update to new one if you wanted.

73
00:05:00,200 --> 00:05:05,510
However, we're going to use 4.1.2 for this course because it has to put all of the features we're doing.

74
00:05:05,960 --> 00:05:11,510
It's probably fully compatible and tested with other libraries in Colaba, so let's stick with what

75
00:05:11,510 --> 00:05:12,170
the default.

76
00:05:12,320 --> 00:05:13,280
See the equation.

77
00:05:13,280 --> 00:05:14,660
They use it here.

78
00:05:16,380 --> 00:05:19,870
So what we're going to do now, we're going to download some images.

79
00:05:19,910 --> 00:05:23,070
No, don't worry about what is lines of code are doing.

80
00:05:23,070 --> 00:05:27,750
All this is doing is just getting the images of zipped in a folder on my Google Drive.

81
00:05:28,260 --> 00:05:29,490
This is the link on my Google Drive.

82
00:05:29,490 --> 00:05:36,090
To that folder is is grown, which is a program, a Python program actually that downloads files from

83
00:05:36,300 --> 00:05:41,220
Google for Google drives, and we can use it unzip program as well.

84
00:05:41,670 --> 00:05:47,820
When you have an exclamation mark, you're running files in, you're running on bash at that point.

85
00:05:48,510 --> 00:05:54,390
So what that means is that you're accessing the terminal through the notebook so you can actually access

86
00:05:54,390 --> 00:06:00,010
it to indulge in a book and run system commands about command that scripts inside of the column.

87
00:06:00,010 --> 00:06:01,530
That book, which is actually really cool.

88
00:06:02,070 --> 00:06:04,470
However, I don't want you to focus on that yet.

89
00:06:04,620 --> 00:06:12,630
What we're doing here, just getting images delivered to test open CV functions so you can see the files

90
00:06:12,750 --> 00:06:13,470
downloaded here.

91
00:06:13,950 --> 00:06:18,330
See, this is a zip file downloaded in the first line, and these are the unzipped images here.

92
00:06:19,140 --> 00:06:20,820
You can see all of these test images here.

93
00:06:21,240 --> 00:06:26,340
A lot of these things are things we are going to be using in discourse, so it will probably download

94
00:06:26,340 --> 00:06:27,900
this folder many, many times.

95
00:06:28,890 --> 00:06:31,190
So now let's load the images here.

96
00:06:31,200 --> 00:06:33,150
So let's take a look at something important here.

97
00:06:33,570 --> 00:06:35,070
File parts are important.

98
00:06:37,050 --> 00:06:41,340
File parts are important because beginners often always make mistakes with file parts.

99
00:06:41,880 --> 00:06:47,070
It's very, very common to actually mistype something here, and that results in a very common open

100
00:06:47,070 --> 00:06:49,830
copy message error messages, which you'll see later on.

101
00:06:50,400 --> 00:06:52,730
However, retno, this is the file part here.

102
00:06:52,740 --> 00:06:54,240
It's flowers dot jpeg.

103
00:06:54,390 --> 00:06:59,460
I did it mistakenly that due to the Aegis now, but anyway, let's run this.

104
00:06:59,490 --> 00:07:02,850
We can run this here control center or shift.

105
00:07:02,850 --> 00:07:09,290
And so even can all come to works in Windows 10 to actually create, believe a new line delete.

106
00:07:09,300 --> 00:07:10,110
Yes, it does.

107
00:07:10,110 --> 00:07:11,610
And that as well.

108
00:07:12,390 --> 00:07:14,370
So what are we doing now?

109
00:07:15,090 --> 00:07:16,920
You simply doing another import here?

110
00:07:16,980 --> 00:07:21,390
This is from not plot level, and we're importing pipe lot as Pulte.

111
00:07:21,990 --> 00:07:23,760
So to explain what's happening here.

112
00:07:24,600 --> 00:07:30,840
We're importing the library pipe plots as Peltier right now, but that comes from the main library here

113
00:07:30,870 --> 00:07:31,950
called Matterport Lib.

114
00:07:32,490 --> 00:07:37,800
So we're importing these things here and we're going to use these these these plotting functions to

115
00:07:37,800 --> 00:07:40,800
plot to basically show images here, which you can see below.

116
00:07:40,800 --> 00:07:42,060
It's already being should.

117
00:07:43,940 --> 00:07:50,770
So you've seen the image output right here, these here starting at the top left here zero and going

118
00:07:50,770 --> 00:07:51,490
down to zero here.

119
00:07:51,920 --> 00:07:56,750
It's a sort of aware of the convention, but just go with it.

120
00:07:58,190 --> 00:08:01,100
You can see this as the pixels actually asked what I wanted to see.

121
00:08:01,490 --> 00:08:09,290
So you can see this is roughly like maybe close to a thousand by roughly maybe twelve fifty or twelve

122
00:08:09,290 --> 00:08:13,850
eighty something, but we can actually see later on, we can actually see what the windows are.

123
00:08:14,210 --> 00:08:16,260
So let's run this control altogether.

124
00:08:16,670 --> 00:08:18,200
And you can see it displays image.

125
00:08:18,200 --> 00:08:20,720
So you should be assuming all of this doing this right now.

126
00:08:21,470 --> 00:08:27,320
So, you know, one notebook so you can get the hang of running you an open TV could.

127
00:08:27,950 --> 00:08:34,070
So to make sense for you, you can see we have to run these two lines of code to display this image.

128
00:08:34,550 --> 00:08:35,750
Actually, I didn't discuss this.

129
00:08:35,750 --> 00:08:37,490
Could this line let me do that now?

130
00:08:38,060 --> 00:08:40,580
So you can see something quite interesting here.

131
00:08:41,540 --> 00:08:46,070
Where are you calling this function called v two dot CVT color?

132
00:08:46,880 --> 00:08:47,600
Take it!

133
00:08:48,020 --> 00:08:50,960
It takes two arguments to input image and then this.

134
00:08:51,200 --> 00:08:56,390
This parameter here called C v two dot color BGR two RGV.

135
00:08:56,840 --> 00:08:58,500
What is this icon?

136
00:08:58,670 --> 00:08:59,510
Why are we using it?

137
00:09:00,170 --> 00:09:06,560
Well, what's weird is that Open C doesn't treat RG be in that order.

138
00:09:06,920 --> 00:09:14,000
It treated as BGR, so we often actually have to reconvicted back to RG B if we wanted to split with

139
00:09:14,060 --> 00:09:14,840
my plot lib.

140
00:09:15,620 --> 00:09:22,910
So let's let's see what happens if you delete this line here and we just put the image back and we run

141
00:09:22,910 --> 00:09:24,770
this, it's going to look weird.

142
00:09:25,160 --> 00:09:33,080
And that's where it is, because what it thinks it is, our is actually B or Mitsubishi or OpenCV and

143
00:09:33,080 --> 00:09:36,350
RG B and and not plot lib.

144
00:09:36,830 --> 00:09:40,640
So because of that, we have to put this function here just to convert it right here.

145
00:09:40,670 --> 00:09:41,600
That's all this does.

146
00:09:41,600 --> 00:09:46,460
Just conflicts to color space of the image, which we'll discuss shortly with this because how images

147
00:09:46,460 --> 00:09:48,050
are stored and what color spaces are.

148
00:09:48,050 --> 00:09:52,460
So don't worry if those things sound alien or scary to you yet.

149
00:09:53,240 --> 00:09:55,370
So let's make this little function here.

150
00:09:56,270 --> 00:10:02,660
This is little function called show just basically takes the input image as an argument and also takes

151
00:10:02,660 --> 00:10:04,790
the title, which we just left blank here.

152
00:10:05,510 --> 00:10:10,280
And it just put the title on top of the image here and shows the image below.

153
00:10:10,760 --> 00:10:14,630
So we can actually use that function like this right now.

154
00:10:15,230 --> 00:10:20,690
So this is actually pretty cool and nifty little function that we'll be using a lot in discourse.

155
00:10:21,440 --> 00:10:23,930
So let's just play our first image here.

156
00:10:24,320 --> 00:10:25,010
And there we go.

157
00:10:25,460 --> 00:10:31,010
So now we just need to do one line to display an image and we can actually put a title, which is quite

158
00:10:31,010 --> 00:10:35,630
handy if you want to actually have things a bit more neat and organized, which I like to do.

159
00:10:36,350 --> 00:10:40,610
So now let's move on into saving our images.

160
00:10:41,330 --> 00:10:42,480
So to save an image?

161
00:10:42,500 --> 00:10:43,460
It's actually quite simple.

162
00:10:43,460 --> 00:10:46,850
It's a simple, open sea view function called cfy to the M right.

163
00:10:47,360 --> 00:10:53,360
You input the file name if you want to save it as output a JPEG and we just call it the input, the

164
00:10:53,360 --> 00:10:55,460
image variable that we were using previously.

165
00:10:55,820 --> 00:10:57,440
We use that as the input here.

166
00:10:57,740 --> 00:10:58,750
So let's run this.

167
00:10:59,030 --> 00:11:03,620
You see, it returns true, which is good to know means it run successfully, and you can see it as

168
00:11:03,620 --> 00:11:07,020
an output file here and output is the image.

169
00:11:07,460 --> 00:11:12,650
That's the full image right here that we were actually looking and loaded before.

170
00:11:13,100 --> 00:11:15,050
Remember, screw up slowly.

171
00:11:15,710 --> 00:11:17,990
We loaded up this image here from a folder.

172
00:11:18,440 --> 00:11:22,090
And no, we used to open C v function here output.

173
00:11:22,930 --> 00:11:29,000
So Emirates to create this file called output that JPEG using the image variable that we load it here

174
00:11:29,120 --> 00:11:31,670
because we loaded it as and stored it as image.

175
00:11:32,630 --> 00:11:33,890
You can even see that as a PNG.

176
00:11:34,220 --> 00:11:35,070
So let's do that.

177
00:11:36,470 --> 00:11:42,020
And you can see this refresh to here and you'll see it as a PNG if that's what creates a do.

178
00:11:42,260 --> 00:11:42,960
So great.

179
00:11:43,010 --> 00:11:44,270
So that's been working fine.

180
00:11:45,110 --> 00:11:49,760
So now let's take a look at the image dimensions.

181
00:11:49,910 --> 00:11:56,240
So before I go into image dimensions, these are how images are created and stored in arrays.

182
00:11:56,810 --> 00:12:00,950
So imagine remember, we have said we have BGR and RGV.

183
00:12:01,520 --> 00:12:02,240
It's the same thing.

184
00:12:02,270 --> 00:12:02,930
It's just different.

185
00:12:02,930 --> 00:12:08,870
Every different color spaces you remember, we need three primary colors to create any color we want,

186
00:12:08,870 --> 00:12:09,410
basically.

187
00:12:10,280 --> 00:12:16,400
So we have to store the values of how much red, how much green, how much blue and picture it's stored

188
00:12:16,400 --> 00:12:17,720
like a grid table.

189
00:12:17,720 --> 00:12:19,760
Sort of like this, like a three dimensional table.

190
00:12:20,600 --> 00:12:26,420
So you can see each one here corresponds like zero zero corresponds to the top right left pixel.

191
00:12:26,960 --> 00:12:29,060
Then this one is the top, the second one.

192
00:12:29,330 --> 00:12:35,930
And so each one here, each zero zero each coordinate to each pixel point has three values.

193
00:12:35,990 --> 00:12:42,200
Those three values correspond to three color schemes here red, green and blue.

194
00:12:43,220 --> 00:12:46,580
So that's how images are stored as two dimensional areas.

195
00:12:46,970 --> 00:12:51,320
So whenever you're wondering how it is, what does this look like image?

196
00:12:51,800 --> 00:12:53,480
This is basically what it looks like.

197
00:12:53,930 --> 00:12:56,740
So no, let's print this.

198
00:12:56,750 --> 00:13:05,120
So Dutch ship is a numpy function because open sea view stores images as Nampai functions no objects.

199
00:13:05,600 --> 00:13:13,460
What Nampai is Nampai is a fast numerical library in Python that we use for all sorts of metrics and

200
00:13:13,970 --> 00:13:16,040
cool little linear algebra calculations.

201
00:13:16,050 --> 00:13:17,930
It's quite quick, quite well optimized.

202
00:13:18,380 --> 00:13:20,960
So open to these slices are to store the images.

203
00:13:21,020 --> 00:13:28,910
So it's a story as an image to as a Nampai array right here, so you can see by using the Dot ship.

204
00:13:29,090 --> 00:13:38,300
So shape is a function that these objects can access that outputs the pyramidal dimensions in each direction

205
00:13:38,300 --> 00:13:38,570
here.

206
00:13:39,170 --> 00:13:42,440
Because this is a three dimensional area, you have tree values here.

207
00:13:43,010 --> 00:13:45,680
This here is the height.

208
00:13:46,220 --> 00:13:55,490
This is to wit, and this is a tree tree means that each of these values has tree sequences or tree

209
00:13:55,490 --> 00:14:01,400
rows of values or tree depths or values or property that makes sense to you.

210
00:14:01,670 --> 00:14:07,580
I'm not sure if I'm explaining that to right, but this diagram would help a lot in understanding that

211
00:14:07,580 --> 00:14:08,090
concept.

212
00:14:08,990 --> 00:14:10,610
So to excessive dimension.

213
00:14:10,940 --> 00:14:16,490
Just to get what we want to get a height at a weight, you can just use zero to access to this value

214
00:14:16,490 --> 00:14:17,000
in the tree.

215
00:14:18,470 --> 00:14:21,350
So you could take a look at it here and we go.

216
00:14:21,680 --> 00:14:23,630
So that's how you get this here.

217
00:14:25,040 --> 00:14:30,290
So now let's take a look and just print out all the dimensions here in this nice little format here

218
00:14:31,280 --> 00:14:34,040
so we can do this using the first format.

219
00:14:34,070 --> 00:14:35,390
Actually, I don't use this anymore.

220
00:14:35,750 --> 00:14:42,140
I tend to use the f string format in Python, but this is fine nevertheless.

221
00:14:42,560 --> 00:14:49,480
So what this is saying is that whatever is in this format variable here, if argument's placed into

222
00:14:49,670 --> 00:14:52,370
these curly brackets here inside of the string.

223
00:14:52,610 --> 00:14:56,690
So now we're going to print the height to wit and the depth of the image.

224
00:14:57,140 --> 00:14:59,300
Quite straightforward and good.

225
00:14:59,450 --> 00:15:00,440
Good practice with Python.

226
00:15:01,130 --> 00:15:03,800
So that concludes our first lesson here.

227
00:15:04,130 --> 00:15:08,570
Let's quickly scroll up to the top and you can see this is what we have learned in this lesson.

228
00:15:09,140 --> 00:15:09,980
How to import.

229
00:15:10,130 --> 00:15:13,820
Once you've open TV model or library, I should say in Python.

230
00:15:14,720 --> 00:15:15,890
How to load images.

231
00:15:16,070 --> 00:15:17,420
Remember, we downloaded the images.

232
00:15:17,420 --> 00:15:20,770
You can upload images directly here and load them in this book.

233
00:15:20,780 --> 00:15:23,750
That's actually something I should encourage you to do just to get the feel of it.

234
00:15:25,280 --> 00:15:26,630
You can display your images.

235
00:15:26,630 --> 00:15:31,130
You can see we show I showed you how we use my plot lib to do that.

236
00:15:31,400 --> 00:15:33,560
You can save your images if you want to actually save it.

237
00:15:33,950 --> 00:15:40,850
After doing some cool operation on it, and you can get the dimensions just to get an understanding

238
00:15:40,850 --> 00:15:47,540
of how images are stored and us installed on power is and how got access to the different dimensions.

239
00:15:48,200 --> 00:15:48,980
So thank you.

240
00:15:49,160 --> 00:15:50,930
Now, let's move on to the next lesson.
