In the previous cooling session, we implemented the step one of the localized state, which was extracting
the background model.
Now that we have extracted the bedroom model, we can move on to detecting our car and then extracting
its location using background subtraction.
For this, we move inside the localized board function.
But after we have extracted the background, we implement the step to where it is foreground extraction.
This is for detecting our car and this will be implemented using absolute difference.
The Function of open series.
Now what this function does is simply find the difference between two images and then fix their absolute.
So for the source one, I'm going to be providing the current frame and for the source to our background
world.
This gives us change between both frames.
So we need more times change now because the current Amazon BGR space.
So the change will also be in BGR can space, but we're required in grayscale.
So we will be using the open see function of convert color to convert it into grayscale.
So once we have converted into grayscale, we now extract the mask of all the change objects in the
frame.
So that can be done by using function or thresholding.
So severe to the threshold takes an input argument of sorts.
That is our change group for the thrush.
I'm going.
I'm providing a measly value of 15 just to only ignore the values that are too small to see.
And for the Maxwell the Maxwell you will be providing to 45 because we are looking to perform binary
thresholding to get the mosque to change and type is binary thresh or thresh binary.
And because thresholding provides two outputs and we are only interested in the second output when we
are writing here one to get the second output.
So the placeholder is change mask, which was our output.
Now this change models not only contains the models of object that is the core, but also a lot of random
noise.
So because this noise is random, it will be in very small size.
So we can leverage this information and only take the largest object that is our code and remove all
the noise.
And that can be done by using a function that is present inside this file.
So we import that function that is return largest object.
After importing it.
We simply call that function of return largest object also in the chain models as input.
And this gives me the two outputs.
That is the largest object mask.
That is the car mask.
And the control is control.
Now, once we have the mask and the control of the largest object, we can now extract this location
or should as the relative location of the car to the myth.
To do that, we'll be using a function that is good car location.
Now get car location will take two inputs that it is the car control and the car mask.
So we haven't defined this function yet, so we need to define it first.
Let's define that function.
So that is great collocation.
The first is the car control.
And second, or should I say the first is the self argument and then the car control.
And the third argument is the car must.
Now for the definition of this particular function, the very first thing that you need to do to get
the location of any object, we need to find the centroid of that object.
So we have to define the function, define centroid of object.
So let's define the function that gets the centroid of any contour.
So that is named as the centroid.
What it does is simply takes a control of an object.
Finest moments devise the first moment with the zeroth moment to get the centroid in the form of a tuple.
So let's call this particular function by writing so that centroid mistakes in the input argument of
the card counter and gives us.
The centre of our board, so we name it as the center.
Now that we have the ball center in the final two ball, this is the location of the car with respect
to frame.
But we require the relative location of the car with the means.
So to get to that point, we need to perform the same transformation that we did to the myth that includes
the translation of origin from frame two to the maze, and also the rotation to get the maze entry point
on top.
So to do that, we can't use this double.
We did binary because the transformations need to be done on an entry.
So we need to convert this tuple into an array and also we need to flip this tuple from and why x format
to x y form, which is the formatting which which is used to perform all the transformations.
So let's do both these things together.
So right here we have simply converted the ball center that is a tuple to an array and also flip from
y experiment to an x y format.
We're taking the second value in the first and the first value the second.
This gives us the ball center.
Right now we have it in the format that we can now perform the transformations in the same way that
form the transformations for our maze.
So the first transformation is the translation of the origin.
So that can be done by simply creating a placeholder at this box.
Enter translated and that can be written as non point or zeros like the temporary.
So we now have the placeholder.
We simply need to do the translation.
So that is simply written as more center translated.
So we translate is force value.
That is the x.
By taking the ball central.
While central areas first value and simply subtracting this with the origin origin column.
So subtraction the more center column with the origin column simply gives us the translated more center
column in the same way we'll be translating the rule.
And once we closer to the row, we can now move on to the next step that is performing the rotation
on our translated board center.
So that we perform in the same way that we did with the translation that is using the previously saved
or updated parameters that we did on that, we did transformations on our Ms..
So that is for rotation.
We have the rotation metrics.
So we use that rotation metrics, use it to transform our ball center translator or rotate our bottom,
translate it in the same way that we rotated our means.
And then we transpose this and then transpose again to get this in the form of a nice little point.
That is what location on Miss.
So we now have the board relative location on the miss.
So.
They should completed right here.
But because of rotation, there might come a point that is negative in its value, but location can
never be negative.
This is because the origin is shifted in the negative direction.
So we want a positive value.
So we need to translate this back.
Or if it goes to negative.
So.
By simply adding the column rotation column to our core rules and adding the rules to our column, we
can simply translate the origin if it gets to negative values.
Now, once you've done this, simply need to save it inside the placeholder of the block location on
the Miss.
So that placeholder name is self-taught location GA and this stores the location of the core or relative
location of the car on the miss.
So we need to name this placeholder inside init function.
So right here.
So location, car.
And it's like this to zero.
So this will store the location of the car according to the myth.
So now we know that we have completed the function of getting our location.
We have called it right here in the localize but the main function of our localized state.
We can move on to simply join the detected car so that we can see the user can see where the car is
at any moment.
So the way we do this is simply find the enclosing circle for the car control, draw that circle, and
then simply display in the phone for a nice looking red color.
Once we have done this, we display our detected car.
So the localized car is shown on the frame display and also the foreground is being displayed clearly.
So now we run this particular file around this project to see whether we have correctly implemented
the state or the localized state for our problem solving.
What?
So we go inside the terminal.
Will the project.
Launch a simulation.
So once the simulation starts up, we run our maze solver file.
And as you can see, the male swallow part has run and it has correctly extracted a full step.
It is a cracking starter.
The males in the phone for me as entry on top and then perform just the next step that is stuck in the
foreground.
As you can see, the car has been correctly extracted from all of the noise and noise have been removed
and only the car has been removed.
And this is the mass of our car.
So if you just look at the frame display, you can see that the car has been correctly localize right
at the entry, the red circle drone on top of it.
So we have found the location of the car relative to the means and this means we have correctly implemented
the localised state of our assault and what so we can move on to the next step that is attempting the
second stage.
That is a mapping for our missile.
Not till then.
Thank you.
And by.