Welcome back.
We created the setup interpreter function inside the Object Detector Helper class.
Now under this function let's create another function.
Name it as detect.
Taking to the parameters a bitmap object and a rotation of type integer.
Start with.
If interpreter equals to null, then set up interpreter.
Call the function set up interpreter.
If not, if the interpreter is already found.
Start with processing the image to match model input requirements.
So preprocess val image processor equals to image processor dot builder dot.
Here we have an error image processor.
Let me go up and remove this import because we don't need it anymore.
Let me scroll down and import the correct package.
Alt+ enter.
Not the Android X camera core I need from the TensorFlow Lite support image processor.
And here we solve there.
Okay, let me add some parameters here.
Resize up.
Don't worry.
We're going to clarify everything.
And the input the resize operation takes three parameters the width the height and the resize method
which is bilinear.
And here use add normalize op zero f and 255F based on your model's requirement.
Build and let me clarify everything.
Remove this image.
Pre-process or processor dot builder.
This creates a sequence of image transformation.
This comes from TensorFlow Lite support library.
You use it to preprocess images, resize, normalize, rotate before passing them into the model.
So whenever we uh we say pre-processing we mean that we resize, normalize, rotate the image before
passing them into the model.
The first add function adds a resize operation to the preprocessing pipeline.
It resizes the input image to match your model's required input size.
As we said before, for our application and for our model, it would be by default to two.
Four.
Okay, so here we are setting it to to the default input height and default input width.
And as I told you, it's by default to 24.
If the input width and input height are not available, but they are available here in the input width,
which is the global variable that we used to set here, the input width and height resize OP means it
uses bilinear interpolation as smooth high quality method for resizing images.
If your camera frame, for example, is 640 by 480, but your model expects 224 by two two for this
step, resize it.
It automatically again.
Guys, this is the image pre-processing and processing step.
And it's a very very important.
Then we used another add function adds a normalization step normalize up mean zero and standard deviation
255F applies the formula to each pixel.
So here let me write this node.
Output equals to input minus mean over standard deviation.
So with zero f mean each pixel from 0 to 255 becomes pixel over 255, scaled into the range 0 to 1.
Again guys for example, with 0F0 mean zero f gives us pixel over 255, which is the standard deviation.
Most neural networks expect input values between 0 and 1 and not 0 to 2 five five.
So for this, we need to use this important step to range and make the neural networks expect input
values between 0 and 1.
And the build function finalizes and creates the image processor object which can later use and it creates
the final processor pipeline.
Again guys what we did here image processor build start building pre-processing steps.
The first add function resize image to the model's input size.
So here resizing the image to the model's input size.
And the second step normalizing the pixels value.
Normalizing means converting 0 to 2 five five into another range from 0 to 1.