1
00:00:00,090 --> 00:00:06,240
Now, let's move on to our eleventh lesson, which is countless and take take a deeper look at what

2
00:00:06,240 --> 00:00:10,290
contours are the different modes and the drawing of it on images.

3
00:00:11,190 --> 00:00:17,430
So firstly, let's just import all libraries and download images to get us out of the way and now explain

4
00:00:17,430 --> 00:00:19,300
to you what contours are, so.

5
00:00:20,260 --> 00:00:21,520
Sure, we have this done.

6
00:00:21,540 --> 00:00:22,770
So let's just here.

7
00:00:23,250 --> 00:00:24,150
Get this over with.

8
00:00:24,930 --> 00:00:26,630
This is what happens when you run this twice.

9
00:00:26,640 --> 00:00:32,910
Doctors asks you if you want to replace your images and you just put it all just because it's OK if

10
00:00:32,910 --> 00:00:34,550
we replace it, but not before.

11
00:00:34,560 --> 00:00:35,460
And it's fine.

12
00:00:35,970 --> 00:00:36,570
It's the same thing.

13
00:00:37,260 --> 00:00:45,480
So contours are basically continuous lines of curves that cover the boundary of an object in an image.

14
00:00:46,080 --> 00:00:48,630
So let's take a look at this input image here.

15
00:00:48,720 --> 00:00:51,450
So let's run this and I want you to load this image.

16
00:00:52,090 --> 00:00:56,970
You can see it's a license plate that says PC x fifty five 08.

17
00:00:58,020 --> 00:01:04,800
So if you were to draw lines or curves around boundaries of an object, let's assume the boundary we

18
00:01:04,800 --> 00:01:06,000
want to show is around p.

19
00:01:06,540 --> 00:01:11,790
A contour would be something that draws like a little Green Line around the perimeter.

20
00:01:12,720 --> 00:01:18,480
And that's exactly what it is, and it's quite useful, which I should emphasize extremely useful in

21
00:01:18,480 --> 00:01:22,240
computer vision applications to use control.

22
00:01:22,260 --> 00:01:26,610
It's not so much nowadays, though, because nowadays deep learning can do so many things.

23
00:01:27,060 --> 00:01:32,460
But previously contours was like go to function if you want to do some sort of primitive object detection

24
00:01:33,060 --> 00:01:35,370
or blood detection of something.

25
00:01:35,700 --> 00:01:38,430
So let's go on to this.

26
00:01:38,550 --> 00:01:40,910
So let's run some examples of code here.

27
00:01:40,920 --> 00:01:47,290
And this is the counter function explained just in case you wanted to have the details of what the takes.

28
00:01:47,400 --> 00:01:52,740
Basically, text input takes a retrieval mode that you want to use and the approximation method, which

29
00:01:52,740 --> 00:01:56,190
will demo all of these options afterward in this chapter.

30
00:01:56,730 --> 00:02:02,960
But for now, I'm just going to run the basic default actions a default, but a basic contour example

31
00:02:02,970 --> 00:02:06,090
so you can get your feet wet and understand what's going on.

32
00:02:06,300 --> 00:02:12,840
So firstly, this lotus image converted to agree a scale and then threshold.

33
00:02:12,840 --> 00:02:18,990
This image, and the reason we treasure this image is because contours of contouring works best when

34
00:02:18,990 --> 00:02:21,900
the images threshold and binaries like this.

35
00:02:22,020 --> 00:02:26,640
Otherwise, it's it's almost futile to even try again contour and actually might not even work.

36
00:02:27,090 --> 00:02:29,180
If it's a non-binary estimate, you have to try.

37
00:02:29,190 --> 00:02:35,190
It's been a while since I've been messing with contours, but nevertheless, let's take a look at this.

38
00:02:35,370 --> 00:02:42,570
So we run this scaled which threshold and then we passed that threshold, that image to our controls

39
00:02:42,570 --> 00:02:43,050
function.

40
00:02:43,440 --> 00:02:49,650
Using the to this, which is retrieves a list of all the contours doesn't care what the parent child

41
00:02:49,650 --> 00:02:51,180
relationships in the contours.

42
00:02:51,780 --> 00:02:57,210
And then we use the tuner proximal, which basically stores all the points for line.

43
00:02:57,330 --> 00:03:04,500
However, it creates quite a big country and then it stores it here, so it gives us the top of the

44
00:03:04,500 --> 00:03:05,730
contours and a hierarchy.

45
00:03:05,760 --> 00:03:11,040
However, we're going to ignore hierarchy right now because how we can get quite confusing sometimes,

46
00:03:11,040 --> 00:03:12,390
and it's not always.

47
00:03:12,900 --> 00:03:14,400
It's not that important to do anymore.

48
00:03:14,940 --> 00:03:15,590
It exists.

49
00:03:15,600 --> 00:03:19,980
You can check it out on the open sea view documentation to if you wanted to see it in detail.

50
00:03:20,910 --> 00:03:28,740
However, it's not that important right now for this lesson that we use to TV to draw contours, to

51
00:03:28,740 --> 00:03:32,150
take the output, which is the Contos upper tier and then draw them.

52
00:03:32,160 --> 00:03:38,850
And we just specify that we want to draw all which is the properties them to say control of what colors

53
00:03:38,850 --> 00:03:41,250
and thickness and Hollywood contours we want to draw.

54
00:03:41,910 --> 00:03:48,140
So you can draw individual contours or you can draw all of these negative one and just showing up it.

55
00:03:48,390 --> 00:03:50,070
So let's run this.

56
00:03:52,320 --> 00:03:54,370
And we can see this is the operative.

57
00:03:54,480 --> 00:03:55,710
So it's still in a bit.

58
00:03:57,810 --> 00:04:03,180
So you can see we are just said we have it in contours, which shows us that at the length of the saree,

59
00:04:03,270 --> 00:04:09,240
we have 18 elements in disarray and will inspect to control elements just now so you can take a look.

60
00:04:11,100 --> 00:04:16,950
So we can see, basically, as I said, we wanted the lines around the objects of an image here, so

61
00:04:16,950 --> 00:04:21,780
you can see if we get a green line around the piece in the little black dots into P..

62
00:04:22,560 --> 00:04:23,760
So this is quite cool.

63
00:04:24,120 --> 00:04:28,260
You can see contours being immediately useful for something like object recognition.

64
00:04:28,260 --> 00:04:30,390
If you wanted to extract each of the letters out.

65
00:04:30,960 --> 00:04:34,050
I mean, yeah, we'll see our optical character recognition, I should say.

66
00:04:35,250 --> 00:04:40,770
And you can basically isolate each character individually by using contours.

67
00:04:41,730 --> 00:04:42,720
So that's quite good.

68
00:04:42,840 --> 00:04:46,230
So now let's take a look at what the contour actually consists of.

69
00:04:46,800 --> 00:04:52,680
You can see if we take a look at the first element traumatized 18 elements misery, so we index in the

70
00:04:52,680 --> 00:04:53,370
first one.

71
00:04:53,790 --> 00:04:57,870
You can see it contains this list of points, so lots and lots of points.

72
00:04:57,870 --> 00:04:58,710
And what is that?

73
00:04:59,760 --> 00:05:03,900
Basically, it's it's a point that coordinates for every pixel in the perimeter.

74
00:05:04,410 --> 00:05:10,250
So it's just like a list of pixels that basically are the perimeter of the object here.

75
00:05:10,440 --> 00:05:12,360
So kind contours give us that out.

76
00:05:12,360 --> 00:05:13,920
But it's pretty cool, isn't it?

77
00:05:15,060 --> 00:05:19,530
So now what happens if we don't trust or I guess the contours may not even work if you don't?

78
00:05:19,540 --> 00:05:19,950
For sure.

79
00:05:19,950 --> 00:05:21,510
And that's true.

80
00:05:22,380 --> 00:05:23,010
It doesn't work.

81
00:05:23,160 --> 00:05:26,820
So all of us remember the threshold to some Gaussian blur.

82
00:05:26,820 --> 00:05:33,030
Gray scaling will actually you need to grayscale before your threshold and even kind of edges works

83
00:05:33,030 --> 00:05:36,030
quite well with contact, but to find the contours afterward.

84
00:05:37,110 --> 00:05:44,100
So remember this for fine contours work background has to be black, and foreground has to be basically

85
00:05:44,100 --> 00:05:45,300
white to anything else.

86
00:05:45,780 --> 00:05:50,870
Otherwise, you're not going to get the contours that you want if you wanted to do.

87
00:05:50,910 --> 00:05:57,150
You can use midwives not to interpret the image so that you can still use fine contours and may be reinvented

88
00:05:57,150 --> 00:05:58,650
afterward if you wanted to.

89
00:05:59,160 --> 00:06:00,780
So it's not a dealbreaker.

90
00:06:02,640 --> 00:06:05,640
So now let's take a look at using uncanny edges for contours.

91
00:06:05,640 --> 00:06:11,340
So all we do is instead of instead of thresholding, we're just going to use candy edges on the Grayscale

92
00:06:11,340 --> 00:06:17,790
imager, set some thresholds here and then take the edge output, which is a binaries image, by the

93
00:06:17,790 --> 00:06:20,400
way, kind of edges outputs of binary estimates.

94
00:06:21,060 --> 00:06:26,610
And you can just use these default parameters again, where we disregard parent-child relationships

95
00:06:26,610 --> 00:06:26,970
and rest.

96
00:06:26,970 --> 00:06:34,320
Look at all of the points we draw it again, like we did in the previous one right here and we get this

97
00:06:34,320 --> 00:06:34,800
nice out.

98
00:06:34,810 --> 00:06:42,870
But below so you can see, you know, we found 77 contours, and that's because Kanae edges creates

99
00:06:42,870 --> 00:06:43,860
a lot more noise.

100
00:06:43,860 --> 00:06:45,300
So you could have a lot more contours.

101
00:06:45,300 --> 00:06:50,880
Like if you look zoom in, you'll see that a lot these little green patches that don't look that small.

102
00:06:51,270 --> 00:06:55,670
That's because there's a multitude of contours here down here as well.

103
00:06:55,680 --> 00:06:57,870
So that's how you get 77 contours.

104
00:06:58,800 --> 00:07:01,040
So let's remember these steps when contouring.

105
00:07:01,620 --> 00:07:06,930
You do want to grayscale and you do want to trash over kind of edge to binaries to image.

106
00:07:07,290 --> 00:07:08,640
So it's important to do that.

107
00:07:09,210 --> 00:07:11,200
So now let's take a look at irretrievable.

108
00:07:11,220 --> 00:07:15,090
So you can actually, if you wanted to get the official up and to the docs and check this out from you,

109
00:07:15,090 --> 00:07:20,070
and you can see all of the sudden what hierarchy here, which isn't.

110
00:07:20,400 --> 00:07:24,650
It's a bit confusing sometimes, but you can take a look on your butt.

111
00:07:24,670 --> 00:07:28,590
Let's go back to the notebook and we can see it here.

112
00:07:29,400 --> 00:07:34,080
So what we're going to do in the hierarchy, basically hierarchy stores for values for each control

113
00:07:34,080 --> 00:07:42,270
system is an index of the next contour second term to the index of the previous contour to it in this

114
00:07:42,270 --> 00:07:43,710
apparent next parents control.

115
00:07:43,800 --> 00:07:46,440
So again, like I said, this is a bit confusing.

116
00:07:46,900 --> 00:07:49,170
Are you doing necessarily need to know all of this?

117
00:07:49,380 --> 00:07:53,520
If you wanted to just take a look into this hierarchy document here?

118
00:07:55,200 --> 00:07:57,030
So let's take a look at the red list.

119
00:07:57,480 --> 00:08:01,950
So this fretless remember, I said in the beginning that this which gives all the contours and doesn't

120
00:08:01,950 --> 00:08:03,450
create any parent child relationship.

121
00:08:03,900 --> 00:08:06,300
So what this means is that parents and kids are equal.

122
00:08:06,390 --> 00:08:08,850
Basically, there's no distinction between them.

123
00:08:09,330 --> 00:08:10,730
Everything is just contours.

124
00:08:10,740 --> 00:08:18,270
So they're all in the same hierarchy, flat level, and it's just run this and we get this up at here.

125
00:08:19,830 --> 00:08:20,700
So it's pretty cool.

126
00:08:21,300 --> 00:08:29,580
Now let's take a look at this one here because actually probably the change of plotting function, that's

127
00:08:29,580 --> 00:08:30,840
why the images end up smaller.

128
00:08:31,380 --> 00:08:36,720
If you wanted to increase the size of the image, you can assume size equal weight.

129
00:08:36,730 --> 00:08:37,770
10 something.

130
00:08:37,770 --> 00:08:39,930
Yeah, and it should keep the size bigger.

131
00:08:41,250 --> 00:08:43,500
The default size was a bit smaller initially.

132
00:08:44,850 --> 00:08:50,490
So anyway, back to this now red external isn't one of the extreme.

133
00:08:50,590 --> 00:08:53,210
Out to flags all tail concerto left behind.

134
00:08:53,720 --> 00:08:59,210
Meaning that you remember there was a concerto very strong and so to speak outside of the hollow point

135
00:08:59,210 --> 00:08:59,660
in the piece.

136
00:09:00,200 --> 00:09:01,730
You can see it previously here.

137
00:09:03,960 --> 00:09:12,440
This woman can see this green circle roughly look and think, Yeah, if you go back down to this, you

138
00:09:12,440 --> 00:09:13,670
can see it's no longer there.

139
00:09:14,060 --> 00:09:15,080
So that's interesting.

140
00:09:15,590 --> 00:09:22,100
So contours are encapsulated inside of the contours are left out when you send indirect external, which

141
00:09:22,100 --> 00:09:23,220
mean which makes sense.

142
00:09:23,240 --> 00:09:26,720
We want to get only the external contours only.

143
00:09:26,810 --> 00:09:27,920
So that's pretty cool.

144
00:09:28,610 --> 00:09:30,170
So we also print the hierarchy.

145
00:09:30,170 --> 00:09:34,730
Here you can take a look at the hockey and see for yourself what it looks like.

146
00:09:35,060 --> 00:09:38,300
And we also get the number of contours printed for you as well.

147
00:09:38,390 --> 00:09:45,710
So now moving on to read our C comp, this one retrieves all the contours and reaches them into two

148
00:09:45,710 --> 00:09:46,430
level hockey.

149
00:09:46,430 --> 00:09:52,430
So you have to have accused forces, the external hierarchy and the internal or inside hockey of just

150
00:09:52,430 --> 00:09:53,080
hockey too.

151
00:09:53,090 --> 00:09:57,140
And the first one is the external external one is hockey one.

152
00:09:57,830 --> 00:10:04,070
So let's just run this Goodacre here, which have run already, and you can see that the output is this

153
00:10:04,070 --> 00:10:04,340
here.

154
00:10:04,670 --> 00:10:08,330
So remember this this matrix is outputting here we can.

155
00:10:08,420 --> 00:10:10,490
We explain what the values were to screw up.

156
00:10:10,490 --> 00:10:14,330
Sorry for screwing the first team is the index of the next.

157
00:10:14,330 --> 00:10:18,860
Contour is a continuous index of the previous contour to a term as the index of two parent control on

158
00:10:18,860 --> 00:10:21,020
the 40mm as index of the child Kondo.

159
00:10:21,500 --> 00:10:23,480
So that's how that's what this is here.

160
00:10:23,480 --> 00:10:25,360
That's what it's telling us to Tim.

161
00:10:25,400 --> 00:10:26,900
That's a good attitude for too many.

162
00:10:27,350 --> 00:10:30,710
That's the index of the parent and index of the child control.

163
00:10:31,100 --> 00:10:34,850
So you can see when we did it at all, there was no relationship at all.

164
00:10:34,850 --> 00:10:38,840
With minus one, Redick still only gave us external contours.

165
00:10:38,840 --> 00:10:41,840
So which is why we only looked at the contours and there's nothing else.

166
00:10:42,140 --> 00:10:44,870
Why Aki after that and red?

167
00:10:44,870 --> 00:10:50,420
Come see, now we have some differences here, so you can see this is basically telling us that this

168
00:10:50,900 --> 00:10:54,440
belongs to probably a maximum, a big external contour.

169
00:10:54,920 --> 00:11:00,470
This returns to belongs to another parent to a child, so you can see the relationships of the contours

170
00:11:00,470 --> 00:11:00,770
there.

171
00:11:01,460 --> 00:11:05,900
Red Tree, which achieves all contours and creates a full of family hockey.

172
00:11:05,910 --> 00:11:08,270
This there's enough hockey one or two.

173
00:11:08,600 --> 00:11:13,130
It just has this feel connected to hockey list right here, and you could take a look at the output

174
00:11:13,130 --> 00:11:13,610
again.

175
00:11:14,480 --> 00:11:18,290
Now, let's look at something that's a little bit more important, which is contouring modes.

176
00:11:18,740 --> 00:11:20,390
So we have to contour inwards.

177
00:11:20,390 --> 00:11:21,740
We have chin approx.

178
00:11:22,160 --> 00:11:23,110
And chin approx.

179
00:11:23,120 --> 00:11:26,600
Basically, it gives us all the points in the image here.

180
00:11:27,320 --> 00:11:30,880
So this gives us like the whole list of points.

181
00:11:30,900 --> 00:11:34,690
If you run this, could we get this here now?

182
00:11:34,700 --> 00:11:40,580
Alternatively, there's something called actually, let me explain what the output of this is doing.

183
00:11:41,120 --> 00:11:45,950
So you can see four see in contours, which means that what this is doing is that we're going through

184
00:11:45,950 --> 00:11:52,700
every contour, each contour individually in our contours are list or three and printing the length

185
00:11:52,700 --> 00:11:53,030
of them.

186
00:11:53,390 --> 00:11:59,150
So you can see how much points it takes for one of these little parameter lines.

187
00:11:59,150 --> 00:12:00,530
One of its contours, we call it.

188
00:12:01,130 --> 00:12:03,850
So this one eighty seven points, this one was seventy points.

189
00:12:03,860 --> 00:12:08,600
You can see some of the one point, which means that they were at a contour around one pixel.

190
00:12:09,140 --> 00:12:10,880
The Pixel itself is just a contour.

191
00:12:11,890 --> 00:12:14,720
You can see some of 400 points, which is a quite big contour.

192
00:12:15,260 --> 00:12:17,480
So you can see filtering on contours.

193
00:12:17,480 --> 00:12:23,300
That long is a where we can extract the contours that are probably for this piece, the action.

194
00:12:23,300 --> 00:12:31,820
But these are six digits and you can actually see one two three four five six two seven seven.

195
00:12:31,820 --> 00:12:35,470
Values are quite big, so most likely these characters belong to a seven.

196
00:12:35,480 --> 00:12:37,820
Some values seven digits.

197
00:12:38,450 --> 00:12:39,750
So what is chin approx?

198
00:12:39,840 --> 00:12:41,170
Simple chin approx.

199
00:12:41,180 --> 00:12:42,620
Simple this is different.

200
00:12:42,770 --> 00:12:44,150
I'll explain to you what it is.

201
00:12:46,700 --> 00:12:47,360
Chain approx.

202
00:12:47,390 --> 00:12:53,300
Simple just stores the end points of light, so it doesn't store all of the coordinates of the stores,

203
00:12:53,300 --> 00:12:58,160
the endpoint, so it's a lot less space, but you can see some of the points, but a lot of space it

204
00:12:58,160 --> 00:12:58,790
occupies.

205
00:12:59,240 --> 00:13:00,940
That's the difference with the controls here.

206
00:13:00,950 --> 00:13:05,090
So again, in most cases, it can use chain approx.

207
00:13:05,120 --> 00:13:07,820
None, which gives us full length contours.

208
00:13:08,300 --> 00:13:13,610
Gina Brock Simple just stores the end points of each line, which is which is cool, which is important

209
00:13:13,610 --> 00:13:14,730
if you wanted to save space.

210
00:13:14,750 --> 00:13:21,190
If we have an application looking for an embedded system, so that concludes this chapter and contours

211
00:13:21,190 --> 00:13:22,310
a hope you find it useful.

212
00:13:22,880 --> 00:13:28,700
Next, we're going to move on to moments sorting and approximating and matching contours, which is

213
00:13:28,700 --> 00:13:29,870
also very important.

214
00:13:30,260 --> 00:13:30,680
Thank you.
