Created
August 11, 2021 09:11
-
-
Save pengj/10d8d4015e4f947ebef25c589d8ed9f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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