For an assignment for my class, I have to implement an app that scans QR codes using Android Studio. I would like for the user to scan the the QR code using their camera (as opposed to taking a picture of the QR code and then scanning it). I am using the ML Kit and CameraX libraries.
I'm following these ML kit instructions but I'm stuck on step two. More specifically, I do not know how to analyze each frame from the camera feed. I have created the InputImage but I do not know how to use the ImageAnalysis.Analyzer interface to analyze each image as suggested in the instructions.
The following is a summary of ImageAnalysis.Analyzer from the documentation:
Interface for analyzing images.
Implement Analyzer and pass it to setAnalyzer to receive images and perform custom processing by implementing the analyze function.
What does this mean??
Also, this is some sample code provided that uses ImageAnalysis.Analyzer:
private class YourAnalyzer implements ImageAnalysis.Analyzer { @Override public void analyze(ImageProxy imageProxy) { Image mediaImage = imageProxy.getImage(); if (mediaImage != null) { InputImage image = InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees()); // Pass image to an ML Kit Vision API // ... } } What I've done so far:
Note: I created an Activty class to handle all the QR code scanning. This class implements ImageAnalysis.Analyzer.
- I request the appropriate permissions from the user to access their camera
- I initialize the camera, i.e. I set the PreviewView to a cameraController in a method called startCamera
- Inside my implementation of analyze(), I get the InputImage object that will be analyzed. After that, I'm stuck.
Where do I go from here? I find the documentation to be very vague so I'm confused about how to implement analyze(), and where to actually call setAnalyzer(). What is an Analyzer object that is mentioned in the documentation? I've read it but it still doesn't make sense.
I'm assuming that I should call setAnalyzer() right before initializing the camera but I'm not sure. I would like some clarification and a point in the right direction.
Мобильная версия