Welcome back.
We created the load labels and load models function.
Now we need to control the object detector class from the ViewModel.
For this purpose create a new function called Build Analyzer.
This function takes two parameters size width which is a float, and size height which is a float.
It returns the object detector instance and for this purpose we start with object detector.
We need to initialize it using the object detector class.
And if we go back to the object detector we have four parameters.
We need to specify the interpreter labels results that are view size and the listener.
The interpreter is specified, which is the interpreter that we created before.
If we go back with this late initialize and we initialize it later.
Then we have the labels, which is the label variable that we create here the size width which is result
view size result view size which is a size.
So I need to remove this size.
Create a new size object size width dot two.
Integer and size height dot two integer.
Here we are converting this which is the result view size.
We are creating a new size object with the passed parameters that the width and the height.
So here I'm converting them from float to integer and passing them as parameters.
We have two parameters.
To create the size object we need to pass the width and the height.
It's very simple.
I am passing those as parameters.
And the last parameter which is listener.
Here we need to pass the listener.
So sometimes the AI generates some errors.
Okay.
Set list.
Here we need to create a new function called set list that two columns.
Syntax in Kotlin is called a function reference or or callback reference.
It creates a reference to the set list function that can be passed as a parameter, similar to how you'd
pass a lambda function.
I love to to to show you all types of coding, all types of syntaxes, and so on.
Okay, then we need to return this object detector.
Okay.
Now I want to create this set list function for this purpose.
Create a new function here.
Set list detected object.
List it's detection object.
And then what we need to pass to create here.
If the detected object list is empty, then return.
Otherwise set the detection list dot value equals to the detected object list.
This function updates a live data object with new object detection results, receives a new detection
results from the object detector.
Updates a live data observable with the latest detections, and acts as a callback listener for the
detection events.
If you notice here, we are checking if the detected object list is empty.
Early return if no objects were detected, exit immediately avoids unnecessary live data updates and
prevents showing empty detection results in UI.
Live data update.
Here we are updating the list live data with detection list dot value updates the detection list live
data with the new detection results.
Any observers like UI component will be notified of the change.
This triggers UI updates automatically.
The last function we need to create is the update params.
So function update params params.
It's of type detection parameters.
And if you want to update the parameters like the threshold.
If we go to the detection parameters, you remember the score threshold is set to 60% 0.6 f if the user
wants to update it like you create a drag and drop slider or or anything or up and box.
Draw a drop down menu to select the sensitivity so this function will help you.
Okay so object detector dot update parameters.
Set the parameters to the params parameters that is passed as a parameter.
Okay.
This is optional okay.
Optional.
Again guys, if you want to control the sensitivity and the detection threshold of the detector, call
this function update parameters and pass the parameters you want like a score threshold, set it to
0.7 for example 0.8 and so on.
Okay, so I love to create this optional if you want to, to develop and create advanced features for
your application.
By the way this is optional.
So you can get rid of this function or keep it for later use.