Welcome back.
We created this data class called Detection result and this interface detection listener.
Now let's create a new package.
Name it as screens.
And inside the screens create a new Kotlin file.
Name it as box detection.
And inside this box detection file let me create a new composable function.
Name it as box with detection overlay.
This box with detection overlay takes camera controller.
It's of type, life cycle, camera controller and detection results.
It's a list of detection result.
The purpose of using camera controller is the high level controller that manages the camera lifecycle
and the provides easy to use camera functionality with minimal code.
Okay, so this is the main purpose of using the camera controller.
It automatically handles camera, start up, resume pose, stop ties, camera, life cycle to your activity
or fragment life cycle or composable lifecycle.
No manual camera resource management needed.
And this is very useful because we are not, uh, handling the camera and displaying cameras as and
this is not the aim as much as adding and uh, and detecting object using ML.
So this is the camera controller that we're going to use.
And this component makes it much easier to integrate camera functionality with your TensorFlow object
detection compared to manual managing camera sessions and lifecycle.
So this is a very important a very important.
And we've added from the lifecycle camera controller and from camera X okay.
Inside this composable start with Android View.
And this factory equals to that context preview view apply fill center.
Why we use Android View.
And uh, what is Android View?
Android view allows you to use traditional Android views with Jetpack Compose.
But why we use the traditional Android views instead of using Composables and Jetpack Composables?
Because camera X, which is the library that we've added before for the camera, uses only views, so
we need to include it inside an Android view.
Android view allows you to use a traditional Android views with Jetpack Compose, and the Camerax uses
the views in Jetpack Compose app.
Android view is a very good solution for using camera X in Jetpack Compose.
Factory equals to context.
This lambda that creates the preview view instance and set the context in Android provided by compose.
Called once, when the composable is first composed and the preview view creates the camera x camera
preview view that displays camera feed.
This is the actual view that shows the camera preview and apply is.
Used to configure the preview view.
The controller camera controller connects the view to your lifecycle, camera controller and scale type.
Sets.
The camera preview is scaled within the view.
We use the fill center means the preview container maintains aspect ratio, fills the entire preview
view while centering the content, and may crop the preview slightly to fill the view.
Okay, and let me remove this.
And here we go.
Okay.
So this is the camera preview view the camera view that we're going to use with camera X.
So again guys we use the Android View with with camera X.
Because camera X only uses views in Jetpack Compose.
And we need to use the Android View to allow the camera preview.
Okay.
I want from you to remember this point.