Welcome back.
We created those variables the object detector, the object detector listener and detection results
and the camera controller.
Now I want from you to focus with me.
This is a very important step we need to do here.
We need to create the image analyzer that processes camera frames for object detection.
Let's start with var analyzer equals to remember and set by using the image analyzer, passing image
analyzer and pass.
Here the parameter of the lambda expression.
The image proxy remember is used to create a stable analyzer instance that survives recomposition,
preventing recreating the analyzer on every frame, which could be inefficient.
The image analysis and analyzer that receives camera frames.
The image proxy contains the camera frame data and metadata called for every new camera frame frequency
depends on camera configuration.
So let me, um, add some notes here.
Please write them down.
Let's start by using the try and catch block.
Try val bit map equals to image proxy dot to bitmap.
Then we need the object detector instance that we create and get the detect function.
Did you remember the detect function that we created before?
Here we have two parameters to be passed the bitmap and the rotation.
So passing the first parameter is the bitmap.
And the second parameter is the rotation which is image proxy, image info and rotation degrees.
Set the catch for e as exception log dot e e failed to analyze image.
Then you can use finally block to set the image proxy dot.
Close the val bitmap.
Converting here the camera frame to a bitmap, convert image to bitmap, or you can set the camera frame.
Camera frame.
The image proxy image to bitmap.
Here we are converting it.
So you see guys, the image proxy is the camera frame that we get on every camera frame.
And we are converting this image proxy into bitmap using the two bitmap function.
Why?
Because the object detector detect function takes the bitmap object and not an image, proxy or image
or camera frame.
It takes bitmap as the first parameter.
This conversion has a performance cost.
Consider alternatives for high efficiency analysis.
But since our application is small and contains only two labels and, um, this is, uh, good, this
is good, but there are better implementations and conversion.
Okay.
The rotation here and the object detector detect the bitmap through, uh, through an object detection
model.
A passes the image rotation.
This is the rotation passes the image rotation.
So detection can account for device orientation.
Typically returns detection results, bounding boxes, labels, confidence scores and so on.
Uh, try block attempts.
The risky image processing operation catch handles failures gracefully without crashing the app.
And finally crucial ensures image proxy close is always called.
So here ensuring image proxy dot close is always called why we need it.
Because releasing the camera frame buffer back to the camera system.
Without this, the camera would stop producing new frames.
And finally block ensures this run even if processing failed.
Okay, this is all about the image analyzer.