1
00:00:00,330 --> 00:00:02,070
And welcome to the 14th lesson.

2
00:00:02,280 --> 00:00:07,890
We take a look at counting circles, ellipses and finding Waldo using template matching.

3
00:00:08,340 --> 00:00:12,270
So go ahead and open up this notebook and let's get started.

4
00:00:12,330 --> 00:00:17,850
So firstly, just let's just import or libraries and create our initial function and download images,

5
00:00:17,850 --> 00:00:18,700
which I've already done.

6
00:00:18,720 --> 00:00:20,070
So you can go ahead and do this now.

7
00:00:20,760 --> 00:00:25,980
So we're going to move on to the code, which is like a mini project, a call to call it a mini project

8
00:00:25,980 --> 00:00:29,960
because there's a lot of different there's a lot more code than our usual cell blocks.

9
00:00:30,000 --> 00:00:31,590
So explain this code for you.

10
00:00:32,070 --> 00:00:38,010
So firstly, what we're doing, we're loading our test image here and showing our sample image initially.

11
00:00:38,610 --> 00:00:41,880
Then we're creating something called a simple blood detector.

12
00:00:42,330 --> 00:00:45,180
That's an open TV function that's used to find blobs.

13
00:00:45,840 --> 00:00:49,530
Basically, the same clubs that we use before it gives us key points.

14
00:00:49,530 --> 00:00:53,610
So we get the key points here and then we should as key points onto the image here.

15
00:00:54,150 --> 00:01:00,150
And then we just output the number of blobs in the image and put that text in the image itself.

16
00:01:00,810 --> 00:01:07,500
So then what we're going to do, we're going to display that image to bubs and then we're going to do

17
00:01:07,500 --> 00:01:08,160
something else.

18
00:01:08,220 --> 00:01:10,470
We're going to use another symbol of the doctor here.

19
00:01:11,130 --> 00:01:17,430
And then we're going to set some parameters of these parameters here of parameters that define a circularity.

20
00:01:17,970 --> 00:01:21,030
Because let's take a look at the image and I'll tell you why we're doing that.

21
00:01:21,030 --> 00:01:22,790
So this remember this block of code?

22
00:01:23,250 --> 00:01:23,550
Yeah.

23
00:01:25,050 --> 00:01:27,630
So you can see, you know, sample image.

24
00:01:27,630 --> 00:01:34,200
We have cycles and ellipses and similarly ellipses here, but you see some circles scattered about right

25
00:01:34,200 --> 00:01:34,470
now.

26
00:01:35,010 --> 00:01:38,910
So we want to figure out a way to differentiate which blobs are circles in which blobs are not.

27
00:01:39,360 --> 00:01:41,890
And that's how we actually use these parameters here.

28
00:01:42,300 --> 00:01:44,070
So we're going to take these parameters.

29
00:01:44,510 --> 00:01:50,250
It was set the parameters in simple blood detected by doing params dot filter by area equal.

30
00:01:50,260 --> 00:01:50,700
True.

31
00:01:51,330 --> 00:01:54,120
These are all set in the params file here.

32
00:01:55,530 --> 00:02:03,260
If I run, this can take a look and see Whoops, what params hasn't it?

33
00:02:03,270 --> 00:02:04,980
So this is creating new params here.

34
00:02:07,260 --> 00:02:08,160
If you press tub.

35
00:02:12,900 --> 00:02:17,850
Yeah, there we go, so if you press tab, you'll get all of these functions here just takes a little

36
00:02:17,850 --> 00:02:19,860
while, sometimes because of the internet connection.

37
00:02:20,430 --> 00:02:21,270
But you can see this.

38
00:02:21,360 --> 00:02:24,540
It's the parameters we can set, you know, a simple blood detector here.

39
00:02:25,080 --> 00:02:27,000
So it's quite quite useful and quite cool.

40
00:02:27,510 --> 00:02:30,960
So we're going to use these prompts to set security measures here.

41
00:02:31,860 --> 00:02:40,560
So and then said the minimum convexity as well and then filter by inertia, which is basically filtering

42
00:02:40,560 --> 00:02:42,240
by sort of some of the orientation.

43
00:02:42,240 --> 00:02:48,150
It's a bit it's a bit tricky to understand, but there's an image I found on StackOverflow that helps

44
00:02:48,150 --> 00:02:48,750
quite a bit.

45
00:02:48,760 --> 00:02:52,830
So Alice Pierce that image into this file here and you can take a look.

46
00:02:57,530 --> 00:02:58,020
There we go.

47
00:02:58,040 --> 00:03:01,700
So you can see what these filters actually mean here when we're setting these parameters.

48
00:03:02,390 --> 00:03:03,350
So that's pretty cool.

49
00:03:03,830 --> 00:03:05,390
So now what do we do here?

50
00:03:05,420 --> 00:03:12,230
So using this new filtering promises now that we just create and get a new bunch of key points here.

51
00:03:12,690 --> 00:03:13,790
Schroeder's key points here.

52
00:03:14,210 --> 00:03:19,400
However, the key points we have now are basically only going to be the circular blobs.

53
00:03:19,850 --> 00:03:22,790
So that's how we actually filter on circular loops here.

54
00:03:23,210 --> 00:03:28,250
So you can see and get to get to come to this actually this get the length of the array.

55
00:03:28,280 --> 00:03:31,100
And let's put this into this text, this text string here.

56
00:03:31,640 --> 00:03:34,370
So we have a length of two key points number of blocks.

57
00:03:35,000 --> 00:03:38,420
So in the first instance here, let's just get this nice and smooth.

58
00:03:39,290 --> 00:03:42,320
We have 22 points blobs in the image.

59
00:03:42,650 --> 00:03:47,990
However, we only want to filter in circles so you can see now in the second image, we've only got

60
00:03:47,990 --> 00:03:51,440
eight circles in image, so that's a pretty cool way of filtering blobs.

61
00:03:52,130 --> 00:03:58,250
So now let's move one onto the template matching, which is a very cool function and open TV that allows

62
00:03:58,250 --> 00:04:00,800
us to match pieces of the images together.

63
00:04:01,610 --> 00:04:02,380
So what does that mean?

64
00:04:02,390 --> 00:04:03,200
Pieces of images?

65
00:04:03,590 --> 00:04:09,410
It means that if there's a block that we need that we know exists in this image instead of instead of

66
00:04:09,410 --> 00:04:17,180
like trying to brute force method just to see where that block fits into this image, we can use template

67
00:04:17,180 --> 00:04:21,500
matching, which takes an argument here, takes the template wall to wall argument.

68
00:04:22,220 --> 00:04:24,080
So let's just take a look and see what those are.

69
00:04:24,590 --> 00:04:31,220
So this is the wall, the image we know of right now, but let's see what this image looks like.

70
00:04:31,460 --> 00:04:32,240
Template image?

71
00:04:34,730 --> 00:04:39,980
So this is called call this template here and.

72
00:04:45,630 --> 00:04:49,830
We'll show this image, and you can see this is quite hard to actually see.

73
00:04:50,430 --> 00:04:54,120
Let's actually just make this color image might help be helpful.

74
00:04:54,600 --> 00:04:55,780
So this is what we're looking for.

75
00:04:55,800 --> 00:04:56,640
This is a boulder.

76
00:04:56,760 --> 00:04:57,720
The bid zoomed in.

77
00:04:58,020 --> 00:04:59,490
Definitely a lot zoomed in.

78
00:04:59,850 --> 00:05:03,090
But this is a patch, the tiny patch we're looking for in this image here.

79
00:05:03,780 --> 00:05:10,590
So what this does, we take the green, skilled patch that we've been showing shown above, and we just

80
00:05:10,590 --> 00:05:11,790
use the template here.

81
00:05:12,210 --> 00:05:15,070
So the images, the good would greyscale.

82
00:05:15,510 --> 00:05:21,630
So we take so we take the greyscale image and the template and just use this term --.

83
00:05:21,680 --> 00:05:26,310
This is just this is a method we're looking for using to look up, look up that will match the tablets.

84
00:05:27,030 --> 00:05:29,250
And then we get the results and the results here.

85
00:05:29,250 --> 00:05:34,200
We can put us into minimax look, and that gives us to actually buy the rectangle of the image.

86
00:05:34,710 --> 00:05:40,200
So this is a top left is equal to marks look, and we just get the bottom rates as well by using some

87
00:05:40,200 --> 00:05:41,190
of the calculations.

88
00:05:42,070 --> 00:05:48,690
The deductions we use is just actually just to get the permit area of the image just a little larger

89
00:05:49,050 --> 00:05:49,890
than it actually is.

90
00:05:49,890 --> 00:05:53,250
So we can actually see it because it's actually quite small where Waldo is.

91
00:05:53,640 --> 00:06:01,470
So we just expanded the Red Dot Red Square to Red Square lit and we run this, I mean sort of output,

92
00:06:02,010 --> 00:06:04,530
but it's good to run the school and make sure it works all the time.

93
00:06:05,760 --> 00:06:07,180
And you can see it right here.

94
00:06:07,830 --> 00:06:09,420
So that is pretty cool.

95
00:06:09,510 --> 00:06:15,570
Hope you enjoyed this lesson using matching templates, and we'll move on to the next chapter, which

96
00:06:15,570 --> 00:06:17,250
is finding corners.

97
00:06:17,490 --> 00:06:18,630
So stay tuned for that.
