Welcome back.
We created the prepare image for model function.
Now let's create the parts detection results function here under the previous function create function.
Private function pass detection results.
The returning type is a list of detection object.
Start with val detected objects.
It's a mutable list of detection object.
Then val detection count equals to output number of detections at index zero.
Output num detections at index 0.2, end dot course at most and get the maximum detection number.
Maximum detection number which is Print ln.
Number of detections.
Detection count.
This code extracts and limits the row detection results from the model output.
Read detection count gets the number of valid detections from output detections.
Output detection number array at index zero and apply safely.
Limit ensures we don't need to exceed maximum detection number.
The array bounds protection if we go up, this is included inside the companion object and set it to
ten.
So the maximum detection number is ten.
You can specify it directly like this.
But I prefer using the not not the hard coded.
I prefer using the Variables.
The initial results creates empty mutable list to store processed detections.
This is the processed detections and debugging here.
The printing the number of count for monitoring typically removed in production.
This is our first step.
Now we need that.
The key points the bounds safe uses course at most.
This is a new function that we introduced to prevent index out of bounds errors.
So let me write this node down.
The course at most prevents index out of bounds errors okay.
This is the first step in converting row model outputs into usable detections objects.
Okay.
So in this in this function we are converting row model to detection object.
Now for every detection for every integer I in zero until detection count what we need to do.
We need to start with val score equals to output score.
Get index zero at index I.
This is the two dimensional array starting from row zero and index which is the the column at index
I okay.
What we need to do we need to filter by confidence.
This is threshold we have if score less than parameters dot score threshold.
So if we go to the score threshold As we said before, it's 0.6, meaning that every detected object
with a score lower than 60%, it will be neglected, but higher every object out and and higher that
has the.
Any object has a score greater than 60%.
Go and display a box around it and set it inside our detected objects.
Okay.
So here continue.
Go and continue and make another iteration.
If not, create a val label index output classes dot to integer.
Then if the label index it's not in labels.
Dot indices is what we need to do.
We need to continue also.
So here also we need to print or without using the print.
We can make a log here but it's safe.
Okay then remove this label index val label equals to labels at label index.
Bounding box equals to output locations.
This extracts the class, label and bounding box for each detection.
Getting the label looks up the human readable class name using label index from output classes.
If the label index equals to zero, label might be person.
If we.
If we notice that the SSD here MobileNet and we have the Coco database, we we can understand it better
for from the labels and get bounding box here.
Retrieving coordinates from output locations.
It's a 2D array for a, typically a y minimum x minimum, y maximum x maximum.
As normalized values between 0 and 1.
If we go up, as I told you in the previous video, we talked about the shape here y minimum y x maximum
or x minimum, y maximum and x maximum.
This is the output array.
So if we scroll down here we have the bounding box okay.
It's very simple.
Now let's continue with the SSD mobile.
Net model that returning coordinates in the form that we have and draw the rectangle.