When the response is success, we loaded the file, the model correctly and we returned a list of detected
objects.
We need to display them.
So here I want from you to understand that we are going to draw boxes and use the composables that we
created before.
For this purpose, start with box with constraints.
This is the composable in in Kotlin modifier dot fill or modifier equals to modifier dot fill maximum
size inside it create val box constraint equals to this val density equals to local density dot current
val Lys width equals to with density.
Set the box constraint dot maximum width dot two pixel size height equals to.
With.
Similar to what we've done before.
Box constraint dot maximum height to pixels.
Here we are creating the dimensions for the box.
Now let me call the camera preview composable function that we created before, and pass the image analysis
as a parameter and set the image analysis dot set analyzer.
We need to pass two parameters.
If you remember from the camera preview go up we have the modifier and the image analysis.
Those are for the camera preview.
And if we scroll down we need the image analyzer.
So um go up see the image analysis and its returning type unit.
This lambda expression would be called here.
So set image analysis dot set analyzer.
Set the context compat dot get main executor.
Pass the context and the second parameter is ViewModel dot build analyzer.
Size, width and size height variables that we created before.
Let me explain.
Here we have the camera preview and we have two parameters.
That modifier can be passed and can't be passed.
So it's optional because we initialize it by this.
And the second parameter is on image analysis.
On image analysis is a lambda expression that takes an image analysis as a parameter and returns unit.
This is what I created.
It's the parameter image analysis and returns null and returns unit.
Here I just I just creating and setting the image analysis and setting the analyzer to those the context
the compat the context compat get main executor I am passing the executor and the analyzer.
If we go back to the view model we have the analyzer.
So go up or scroll down to the build analyzer function.
So here we are calling the ViewModel dot build analyzer function that we created previously.
Okay so again guys this build analyzer returns an object detector.
And as I told you we have this, um, this, uh, creation for the object detector class that we created
before.
And we pass the size width and size height as parameters for this build analyzer function.
The last screen we need to make use of it is drill boxes.
You see it's in gray.
We didn't use it before.
So under this camera preview go and create a drill boxes.
Set the paint to paint objects that we created before.
Path colors the path colors list that we created before.
Up.
You see guys here the colors.
Remember green, cyan, red and others.
If we go to drill boxes, we don't.
We can specify the modifier.
It's optional.
We need to specify the paint path color and detection list object.
So here remove those parameters.
Detection list object view model dot detection list dot value Okay.
You see, guys, how we get the latest detected objects, the latest updated list of the detected objects
from the ViewModel detection list.
Okay, so back to the detection ViewModel.
You see guys here, the object detector and the detection list.
We are using the ViewModel, the LiveData to update the screen and try to get the latest updated models
and the objects detected.
Okay, so this is the detection screen that uses and that link the UI with the view model.