Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class TextAnalyzer(private val onTextDetected: (MLText) -> Unit) : ImageAnalysis.Analyzer {
private val setting = MLLocalTextSetting.Factory()
.setOCRMode(MLLocalTextSetting.OCR_TRACKING_MODE)
.setLanguage("en")
.create()
private val analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting)
@SuppressLint("UnsafeOptInUsageError")
override fun analyze(imageProxy: ImageProxy) {
imageProxy.image?.let { image ->
analyzer.asyncAnalyseFrame(MLFrame.fromMediaImage(image, imageProxy.imageInfo.rotationDegrees))
.addOnSuccessListener { mlText ->
mlText?.let {
onTextDetected.invoke(it)
}
imageProxy.close()
}.addOnFailureListener {
imageProxy.close()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment