Welcome back to the course, so the next chapter we take a look at is it involves object tracking by
color.
So let's open this notebook already have it open here.
So this for this, I'll give you a warning.
This lesson isn't it isn't well-done, mainly because I couldn't find a test video to use in club that
actually worked fairly well.
I should have just recorded a video with my webcam to demonstrate this, which I might do later on.
However, for now, I tried to find a video where we can filter on the color yellow and track a yellow
BMW in the see in a scene and demonstrate the track in a color.
However, it doesn't look entirely perfectly to well, it does with briefly for a moment so we can demonstrate
that.
So let's luto images.
Actually, this is the image for the video.
You'll probably not see this.
We can delete this box here.
So this is the code here.
So all this stuff is good.
Well, let me show you the output of this goodness.
This is a fairly long involve code, but it's actually not that complicated.
And this is the output video here where truly we track BMW hopes to go back to this.
So the video resolution is a bit high, so it doesn't fit the whole thing on screen.
So initially, we initialize a random spot here and it's tracking some objects, something hidden in
the film's colorful, too.
However, luckily it does grab on to the yellow car here, and you can see it follows this yellow call.
That's right here.
But then it loses it.
I'm not even sure where here it is.
It loses it for a bit and then tracks some random objects here.
Now, this can probably be improved by improving the HSV color filter.
But what we're actually doing here is we're filtering on a color.
The color filtering as yellow sits between 20 and 40 and HSV each.
I should say the hue and what we're doing, we're creating an empty area for points.
Now this is the points that are being tracked so that you can see that line.
There's a historical line of tracking points.
We just keep appending that to the disarray.
We create our video writer and then all of let's move into the core of the code here.
So like I said, we are tracking one color.
So remember the HSV method to filter and color?
That's what we're doing.
And then after that, we're running fine contours on that output.
So fine contours should only be able to, in theory, fill a get a box.
The largest box around one of the yellow objects on screen.
That's how we have it set here.
So we are creating them to read a story to centroid.
That's the center of the ground control.
So that's how we get contours for filter contours at the center of the control.
If we have contours, this is what we do.
Get the largest contour, get the area, the radius.
That's a minimum closing circle for the contour.
It's a function we haven't discussed before, but basically it takes an input of a cognitive control
and gives you the ex-wife position of the center and the radius.
Then we get the moments here with him.
So this is how we actually get the and using movements, we get the center of the circle as well.
So we can actually use that to plot the circle, plot the point here.
That's how we actually get the trail.
And if the radius is of a 25, which means if it's over a certain size, that's when we actually do
grow in the circle.
So we don't.
We were drawing a circle at a point, a circle around the point.
So one is supposed to be the center of the object.
One is the little circle in closing the object.
And then this is the area here where we just keep track of our points.
So once the radius is over 25, we just store all the points here and then draw a line.
So that line is basically the historical tracking.
So this is a pretty cool system, pretty cool.
Could, I should say.
So we took the output that it produces from our trade frame converted into an empty before then played
back here and we get the output video, which you saw previously.
So that's just video here.
So we can actually play it.
Yeah, there we go.
It's playing.
So that's it for this lesson.
What is a good exercise for you to do is if you want or if you do have open TV installed, you can run
this locally and you can use a webcam and tweak these parameters.
It's going to be much easier to tweak it in a live video running the court locally than on collab.
And that's one of the disadvantages of collab in in terms of working with webcam video, but otherwise
collab is a godsend for so many things.
So I hope you enjoy this lesson.
And then we'll move on now to the 27th lesson, which gets into a very cool topic, which is facial
unlock detection using the dylib library.
So I'll see you in the next lesson.
Thank you.