Before we start creating the partial detection function, let me check the prepare image for model if
we need to do any changes here.
Preparing the exact input tensor of the model, not unit eight one 300 303.
This is for SSD.
We need to prepare it for.
For YOLO it's float 32 one 640 I am I'm repeating this because it's very important.
This is the main difference between the models between YOLO, SSD and MobileNet and other models.
So this is the bitmap.
This is the tensor image passing the tensor image bitmap and the data type.
It's not float32.
Let me use this is for mobile net SSD and this is for yolo.
YOLO use Float32 data type instead of using data type unsigned integer eight.
We're going to use float 32.
Then the image processor builder dot add resize operation the image size image size bilinear.
This is the resize method.
We can add rotation, image rotation and normalize operation and build.
For YOLO there is normalization.
So here YOLO normalization.
So here add normalize operation from zero f 2 to 155 okay.
This is the standard deviation alt plus enter to import the class.
And here we go.
Scroll down.
This is the parse detection result.
This is from the SSD MobileNet.
It's different from it in YOLO.
So let me remove this and let me start with the partial detections here.
We need to return a list of detection object.
So let's start with val results equals to mutable list of detection object.
We need to store our results in a mutable list.
Now for loop I in zero until the output size.
What we need to do.
We need to loop through this and get the boxes.
How to get the boxes.
As I told you, we have five data per detection.
We have the X center, we have Y center, we have width, we have height and we have the confidence.
Please write them down because we need to get for every detection those five Parameters to do that here.
Let me start with x center equals to output.
Output at index.
In order to get the first index we start by zero zero.
At an index I the output buffer.
Then similar to that what we've done here, the y center is the second element.
The width is the third element, the height is the fourth element, and the confidence is the fifth
element at index I.
Okay.
The confidence index we created this variable before the confidence index you can remove it or you can
use it like here.
So scroll down to here.
And instead of using four you can specify the confidence index okay.
But for making it simple this is the confidence index.
This is the height index with y center and x center.
Those are the five parameters, the five data that we get from each detection.
Now let me make some checks.
If confidence greater than parameters and the confidence threshold.
Or if the confidence thresholds the score threshold.
What we need to do.
We need to convert normalized center to pixel coordinates on preview surface.
For that start with val x equals to x center minus width over two f times result view size dot width.
Also similar to that, the y minimum for the height, the x maximum, and the y maximum.
What are x maximum, y maximum, x maximum and y maximum That x minimum is the left side of the box,
the y minimum is the top, the x maximum is the right, and the y maximum is the bottom.
Okay, we are converting them.
Convert normalized center to pixel.
We converted that normalized center.
This is the center of the detected object to pixels.
Now let's draw the rectangle for detecting for the detected object.
Rectangle equals to rect f left.
Start by left.
Curse in or curse at least zero f top at least zero f right at most.
The result view dot width dot to float and the bottom curse at most result view dot view dot to float.
This is the second step.
This is the first step and this is the second step.
The first step is to convert normalize center to pixels.
Because as I told you in YOLO we we use normalized coordinates and normalize the normalized things.
And in the second step let's draw the bounding box and applying clamping boundaries constraints to ensure
the rectangle stays within the visible screen bounds okay.
So using those curves at least and curse at most those clamps the bounding box coordinates to ensure
they don't extend beyond the view's boundary zero to width or height.
It's a safety measure to prevent drawing outside the screen.
Okay, so this is a safety measure.