And welcome to Lesson 17, where we take a look at using a vehicle and pedestrian detectors, which
are actually also our cascade classifiers, which I mentioned in the previous lesson.
So go ahead and open your vehicle and pedestrian in Python notebook.
And let's first let us run.
This could load all our classifiers and look at all the images and load libraries of a function.
So get to get it out of the way.
And while that loads, I'm just going to tell you what we're going to do differently in this lesson
is that we're going to run a pre-trained hard cascade classifier to detect pedestrians and then actually
use it, use it on a video so you can actually see it on a video within CoLab.
So this lesson doubles as the teaching method of how to use, how to load videos and show videos and
up.
So let's scroll down and we'll see how that works.
So firstly, what I'm going to do before before I move on to the videos, I want to illustrate how we
actually how videos are processed in computer vision videos on processed differently to images.
That's because the video is to treat it as a sequence of images.
So remember, videos have frame rates.
A frame rate is essentially how much images it captures per second.
So standard videos are 24 20 frames per second.
Most webcam and digital cameras do 30 frames per second, but movie cameras tend to do 24.
But most things do to do most videos.
You would have come to online at 30 frames per second.
So how this works, you actually use to capture video capture function, and you pointed to your video.
So this video was downloaded above you in case you're wondering where it came from for my Google Drive
using genome.
So you can see the file is here walking thought and before and before sunset impactful, which is a
video format along with Evi and MTV and bunch of others.
We wouldn't get into video formats here.
What I'll tell you do is open TV directly opens and before FBI FBI files, and it can load images directly
from that video as a sequence.
So what we do here?
We use something called Cap Doc read.
Remember, we point we created this object called cap that's pointing to a video captured.
Reid allows us to read the first frame of a video, so and read it basically returns true or false if
it was successfully read.
So if we use if RET is true, we can run this car cascade classifier and hide out.
But for you, just so you can can see it afterwards and converting to grayscale that runs it into our
body detection or people detector whatever you want to call it, and then draws a bounding boxes on
it.
And then we have kept at release, which basically ends to hold like tells the program that we're no
longer looking at that video.
So we released a video.
So we basically stop all of the programming that that allowed us to open that video and then we showed
a frame after we draw upon the box on it.
So let's run this block of code and you can see it got two of the pedestrians here when these yellow
boxes have missed this one.
But this is pretty good for for such an old technology in terms of like our classical classifiers are
quite outdated right now.
There are YOLO and all the others will do in this course later on a much more advanced and state of
the art because they take advantage of deep learning.
This still does work pretty well.
Her cascade classifiers can actually work fairly well for singular objects, as that is one class of
objects that doesn't change, that doesn't have too much variation in them.
People are deformable class, which means that they can be in different positions.
And it does work fairly well on this screenshot here, but not it misses this person here.
So, no, let's run this on a 15 second clip.
So to do that, we're going to use something called CV to a writer.
What that does is let me run this because this block of code takes about a minute to run.
So we run this on a while.
We're waiting for the output.
I'll explain the score to you.
So when we're using we, we use the same CV to capture a function just to load a video and what we do
here, we use cup or get to get the width and height of that image.
That's so that we can actually create our video writer with that information.
You can see it here.
The W and H.
What this does see a YouTube video, right?
It allows us to write a sequence of images to a video, which is a pretty cool.
So if you have some process that's creating a whole sequence of images, you can actually use the C
V to the video writer to create that video.
So what we do, we specify the output and.
Over here in the first parameter, second parameter, we specify what format we're going to do, so
it's a bit odd.
I'm not even sure why it's coded like this, but we specify that it's going to be MJG peg.
OK, that's that's due.
That's the video right to encoder that we're using.
2D is the frames per second.
So that's how you do the timing of the video.
And then that's it for now that will use the out object later on in this thing, in this phone, in
this loop, I should say, shouldn't call a thing, even though this thing isn't it?
Well, moving on.
So we have the body detector, which we have seen this before in the previous lessons where we just
create this using CVT cascade classifier and low end point to the body detector, which is what we would
have done up here as well.
I guess you missed it.
And then we just wrote about the boxes here and now you can see we're doing something called output
right out.
The right allows us to rate each frame while the is run.
Each frame has been written to our dot right.
And we do do cabinet release.
All that released saved video.
So while we do this, actually it finished.
It's 42 seconds, 47 seconds and you can see the walking, I believe, if I was dead.
So let's take a look and see how he played this file within color.
So CoLab is a bit weird.
It doesn't play EVF files.
It plays only MPEG four files.
It consists of a property of UFO, so we have to use something called FFmpeg, which is a very cool
to minimal tool to video conversion, file formats and editing and splicing.
I use it quite quite a bit.
It's very efficient.
So what we do, we run this and it it basically converts this file to a MPEG4 file.
So let's go ahead and run this.
We use the Dash wife argument here because just two sometimes these terminal programs, you prompt you
two types.
So there's automatically to us type.
Yes, so it can proceed with the execution of it, and it takes seven seconds to run.
So that's pretty quick.
And then what we do know, this is how I python well in this clever book plays videos.
So we just import these these functions here from the HTML so we can get the remote controls for video
and then we'll do it over video here by doing open, pointing to the file and using it to create it
to read it.
You don't actually have to understand all of this code.
This is this code is a lot of it's scored as boilerplate code.
You just have to know how to use it if when you want to double your computer vision applications.
So we set the data.
You are, it's just here.
This is what this is.
What points to it here, right?
You actually can see it here.
So this is this brings up the controls for the video.
So let's run this now.
I know that's a lot of the controls or video player essentially or each demo video player.
Which should come up shortly.
There it is.
So if you press play, no took a little while to come up, but you can see it plays a video where we
get to pedestrians.
So this is pretty cool.
So now you can do a lot of testing within call up and testing videos here.
So you don't always have to go through this messy and sort of set of these things on your local system
can use a free processing powers offered by Google for you.
So now let's move on to vehicle detection.
So I'm not going to go through all of the code again, line by line like I did because it's the same
standard.
Could all we do differently is going to cause video and then point to the horror cascade car model.
And we load this and you can see we just get it onto the car right here.
This is just one of the causes identified in this, a bunch of them.
So the vehicle that isn't too great.
So let's also test this on the 15 second clip of the cause.
I actually believe this wasn't 15 seconds.
Actually, it was maybe this isn't 15 seconds and we have just pasted the title in, but we'll soon
find out.
Now that's convert to video.
Let's load up and create a video each, you know, bring up the issue mode controls.
There we go.
So it's loaded 12 second video.
OK, close enough so you can see it.
It's not too bad, actually.
It gets to cause in most cases all the time, but it generally works decently well.
So that concludes this lesson when using horror classic classifiers for pedestrian detection, as well
as using them on videos within CoLab, which I think is pretty cool.
So we'll stop now and then we'll move on to the next lesson where we take a look at perspective transforms,
which is a bit more advanced concept.
It's a bit more of an advance on this concept in open TV.
So I'll see you in the next lesson.
Thank you.