Welcome back.
We have two functions.
Parse image for model and parse detection results.
We need to create them.
So here create a new function private function.
Prepare image for model parsing image proxy as a parameter.
And the returning type is tensor image alt plus enter to import this class.
And here we're going to write the logic of this function.
Val bit map equals to image proxy dot to bitmap.
And if it is not success go and through illegal state exception pass the the message failed to convert
image proxy to bitmap.
Okay here we have this step.
We are going to convert the image proxy to bitmap.
So the first one is converting image proxy to bitmap.
The second step is using unit or or unsigned integer eight data type, not Float32.
Here critical we're going to use use unit or unsigned integer eight data type and not float 32 val tensor
image.
Tensor image that's of data type unit or unsigned integer eight.
There are a lot of data types.
Integer 16.
Integer 3264.
Unsigned integer eight.
Integer eight.
String.
But as I told you in the previous video, and when we talked about the input, we said that our model
expects a unsigned integer eight, so the input is unsigned integer eight.
This is a very important and critical.
I said to you that it is critical because if you set it to, for example, 16, nothing.
Uh, will, uh, will work and the app will crash, or maybe it will not display any detection.
So this is a very important you should pay attention to the input and output of the shape.
Okay guys.
Tensor image dot load the bitmap.
So we convert the image proxy to bitmap bitmap.
Then we set it to unsigned integer eight.
Then we loaded the image to a bitmap.
Now the third step is process the image only resize and rotate as I told you, no normalization.
So here there are.
There is no normalization.
It's very important and make it as critical.
No normalization for an for unsigned integer data types or input val image process processor dot build.
This is the builder and we talked about it in the previous videos.
Dot add resize op which is operation the image size which is the target height.
Image size.
This is the target height.
Then we need to pass another parameter which is the image size again which is the image width.
The third parameter is resize op dot resize method dot by linear.
Okay.
Here we have this bilinear and use add rotate rotate 90 degrees up the image.
Degrees over 90 and dot built.
We missed here to close the parentheses.
And here we go.
This is not the image size.
We need to use the fixed one, which is the image size from the object that we created before.
Go up and here the companion object the image size which is 300.
Or you can type 300 by.
But I don't prefer it.
If you change the model you should change everything.
No, if you change the model, you should change this companion object the image size, the maximum
detection number and the default maximum results.
Okay, so this is the image processor.
Okay.
Let me return it.
And let's explain what we've done here.
Return image processor, dot process that tensor image.
Okay.
Close this and replace it with this parentheses.
Curly braces okay.
Now let me explain what we've done here.
This prepare image for model function Pre-processes camera frames for the object detection model.
Converting to bitmap.
This is the first step.
Transforms image proxy the camera format to map.
So the image proxy is the camera format.
So this camera format is the image proxy and create unsigned integer.
A tensor called tensor image uses data type dot unit eight or u integer eight to match modal requirements
from 0 to 255 pixel values apply.
Processes and processing only resizes the model to input size and rotates for orientation and without
normalization.
Again guys.
No normalization for unsigned integer eight input.
This prepares the exact input format that your model expects.
So here we are preparing the preparing the exact input input tensor of the model, which is unsigned
integer eight and the array one 300 303.