And welcome to the 14th lesson.
We take a look at counting circles, ellipses and finding Waldo using template matching.
So go ahead and open up this notebook and let's get started.
So firstly, just let's just import or libraries and create our initial function and download images,
which I've already done.
So you can go ahead and do this now.
So we're going to move on to the code, which is like a mini project, a call to call it a mini project
because there's a lot of different there's a lot more code than our usual cell blocks.
So explain this code for you.
So firstly, what we're doing, we're loading our test image here and showing our sample image initially.
Then we're creating something called a simple blood detector.
That's an open TV function that's used to find blobs.
Basically, the same clubs that we use before it gives us key points.
So we get the key points here and then we should as key points onto the image here.
And then we just output the number of blobs in the image and put that text in the image itself.
So then what we're going to do, we're going to display that image to bubs and then we're going to do
something else.
We're going to use another symbol of the doctor here.
And then we're going to set some parameters of these parameters here of parameters that define a circularity.
Because let's take a look at the image and I'll tell you why we're doing that.
So this remember this block of code?
Yeah.
So you can see, you know, sample image.
We have cycles and ellipses and similarly ellipses here, but you see some circles scattered about right
now.
So we want to figure out a way to differentiate which blobs are circles in which blobs are not.
And that's how we actually use these parameters here.
So we're going to take these parameters.
It was set the parameters in simple blood detected by doing params dot filter by area equal.
True.
These are all set in the params file here.
If I run, this can take a look and see Whoops, what params hasn't it?
So this is creating new params here.
If you press tub.
Yeah, there we go, so if you press tab, you'll get all of these functions here just takes a little
while, sometimes because of the internet connection.
But you can see this.
It's the parameters we can set, you know, a simple blood detector here.
So it's quite quite useful and quite cool.
So we're going to use these prompts to set security measures here.
So and then said the minimum convexity as well and then filter by inertia, which is basically filtering
by sort of some of the orientation.
It's a bit it's a bit tricky to understand, but there's an image I found on StackOverflow that helps
quite a bit.
So Alice Pierce that image into this file here and you can take a look.
There we go.
So you can see what these filters actually mean here when we're setting these parameters.
So that's pretty cool.
So now what do we do here?
So using this new filtering promises now that we just create and get a new bunch of key points here.
Schroeder's key points here.
However, the key points we have now are basically only going to be the circular blobs.
So that's how we actually filter on circular loops here.
So you can see and get to get to come to this actually this get the length of the array.
And let's put this into this text, this text string here.
So we have a length of two key points number of blocks.
So in the first instance here, let's just get this nice and smooth.
We have 22 points blobs in the image.
However, we only want to filter in circles so you can see now in the second image, we've only got
eight circles in image, so that's a pretty cool way of filtering blobs.
So now let's move one onto the template matching, which is a very cool function and open TV that allows
us to match pieces of the images together.
So what does that mean?
Pieces of images?
It means that if there's a block that we need that we know exists in this image instead of instead of
like trying to brute force method just to see where that block fits into this image, we can use template
matching, which takes an argument here, takes the template wall to wall argument.
So let's just take a look and see what those are.
So this is the wall, the image we know of right now, but let's see what this image looks like.
Template image?
So this is called call this template here and.
We'll show this image, and you can see this is quite hard to actually see.
Let's actually just make this color image might help be helpful.
So this is what we're looking for.
This is a boulder.
The bid zoomed in.
Definitely a lot zoomed in.
But this is a patch, the tiny patch we're looking for in this image here.
So what this does, we take the green, skilled patch that we've been showing shown above, and we just
use the template here.
So the images, the good would greyscale.
So we take so we take the greyscale image and the template and just use this term --.
This is just this is a method we're looking for using to look up, look up that will match the tablets.
And then we get the results and the results here.
We can put us into minimax look, and that gives us to actually buy the rectangle of the image.
So this is a top left is equal to marks look, and we just get the bottom rates as well by using some
of the calculations.
The deductions we use is just actually just to get the permit area of the image just a little larger
than it actually is.
So we can actually see it because it's actually quite small where Waldo is.
So we just expanded the Red Dot Red Square to Red Square lit and we run this, I mean sort of output,
but it's good to run the school and make sure it works all the time.
And you can see it right here.
So that is pretty cool.
Hope you enjoyed this lesson using matching templates, and we'll move on to the next chapter, which
is finding corners.
So stay tuned for that.