WEBVTT

00:00.080 --> 00:01.000
Welcome back.

00:01.040 --> 00:05.120
We created the load labels and load models function.

00:05.160 --> 00:10.480
Now we need to control the object detector class from the ViewModel.

00:10.480 --> 00:16.160
For this purpose create a new function called Build Analyzer.

00:16.200 --> 00:25.480
This function takes two parameters size width which is a float, and size height which is a float.

00:25.560 --> 00:33.760
It returns the object detector instance and for this purpose we start with object detector.

00:33.760 --> 00:37.920
We need to initialize it using the object detector class.

00:38.160 --> 00:44.160
And if we go back to the object detector we have four parameters.

00:44.160 --> 00:51.240
We need to specify the interpreter labels results that are view size and the listener.

00:51.280 --> 00:57.520
The interpreter is specified, which is the interpreter that we created before.

00:57.520 --> 01:04.320
If we go back with this late initialize and we initialize it later.

01:04.560 --> 01:15.720
Then we have the labels, which is the label variable that we create here the size width which is result

01:15.760 --> 01:18.720
view size result view size which is a size.

01:18.880 --> 01:21.400
So I need to remove this size.

01:21.440 --> 01:26.200
Create a new size object size width dot two.

01:26.240 --> 01:31.240
Integer and size height dot two integer.

01:31.280 --> 01:36.480
Here we are converting this which is the result view size.

01:36.520 --> 01:43.640
We are creating a new size object with the passed parameters that the width and the height.

01:43.920 --> 01:50.760
So here I'm converting them from float to integer and passing them as parameters.

01:50.760 --> 01:52.400
We have two parameters.

01:52.400 --> 01:57.960
To create the size object we need to pass the width and the height.

01:58.000 --> 01:59.000
It's very simple.

01:59.000 --> 02:01.750
I am passing those as parameters.

02:01.910 --> 02:05.630
And the last parameter which is listener.

02:05.830 --> 02:08.270
Here we need to pass the listener.

02:08.470 --> 02:12.790
So sometimes the AI generates some errors.

02:12.990 --> 02:13.430
Okay.

02:13.670 --> 02:14.830
Set list.

02:14.870 --> 02:21.910
Here we need to create a new function called set list that two columns.

02:22.030 --> 02:28.710
Syntax in Kotlin is called a function reference or or callback reference.

02:28.870 --> 02:37.870
It creates a reference to the set list function that can be passed as a parameter, similar to how you'd

02:37.870 --> 02:39.790
pass a lambda function.

02:39.830 --> 02:48.150
I love to to to show you all types of coding, all types of syntaxes, and so on.

02:48.190 --> 02:52.990
Okay, then we need to return this object detector.

02:53.030 --> 02:53.630
Okay.

02:53.670 --> 02:58.630
Now I want to create this set list function for this purpose.

02:58.870 --> 03:00.950
Create a new function here.

03:01.070 --> 03:04.470
Set list detected object.

03:04.470 --> 03:07.510
List it's detection object.

03:07.510 --> 03:11.350
And then what we need to pass to create here.

03:11.350 --> 03:16.750
If the detected object list is empty, then return.

03:16.790 --> 03:24.030
Otherwise set the detection list dot value equals to the detected object list.

03:24.070 --> 03:33.270
This function updates a live data object with new object detection results, receives a new detection

03:33.270 --> 03:35.510
results from the object detector.

03:35.550 --> 03:43.990
Updates a live data observable with the latest detections, and acts as a callback listener for the

03:43.990 --> 03:45.430
detection events.

03:45.430 --> 03:50.630
If you notice here, we are checking if the detected object list is empty.

03:50.830 --> 03:59.470
Early return if no objects were detected, exit immediately avoids unnecessary live data updates and

03:59.470 --> 04:04.030
prevents showing empty detection results in UI.

04:04.150 --> 04:05.870
Live data update.

04:05.870 --> 04:13.350
Here we are updating the list live data with detection list dot value updates the detection list live

04:13.390 --> 04:16.150
data with the new detection results.

04:16.190 --> 04:22.510
Any observers like UI component will be notified of the change.

04:22.670 --> 04:25.750
This triggers UI updates automatically.

04:25.870 --> 04:30.310
The last function we need to create is the update params.

04:30.550 --> 04:34.270
So function update params params.

04:34.470 --> 04:37.070
It's of type detection parameters.

04:37.070 --> 04:42.910
And if you want to update the parameters like the threshold.

04:42.910 --> 04:51.790
If we go to the detection parameters, you remember the score threshold is set to 60% 0.6 f if the user

04:51.830 --> 05:00.740
wants to update it like you create a drag and drop slider or or anything or up and box.

05:00.780 --> 05:07.820
Draw a drop down menu to select the sensitivity so this function will help you.

05:07.860 --> 05:12.340
Okay so object detector dot update parameters.

05:12.340 --> 05:17.300
Set the parameters to the params parameters that is passed as a parameter.

05:17.460 --> 05:17.940
Okay.

05:18.180 --> 05:20.020
This is optional okay.

05:20.260 --> 05:21.020
Optional.

05:21.060 --> 05:26.900
Again guys, if you want to control the sensitivity and the detection threshold of the detector, call

05:26.900 --> 05:35.020
this function update parameters and pass the parameters you want like a score threshold, set it to

05:35.300 --> 05:38.380
0.7 for example 0.8 and so on.

05:38.420 --> 05:46.940
Okay, so I love to create this optional if you want to, to develop and create advanced features for

05:46.940 --> 05:48.500
your application.

05:48.500 --> 05:50.420
By the way this is optional.

05:50.420 --> 05:55.020
So you can get rid of this function or keep it for later use.
