Friday, 21 October 2022

MlKitAnalyzer for Android CameraX is slow for text-recognition

I am implementing the new MlKitAnalalyzer based on the description and links of CameraX 1.2 found here.

Following the example I made an analyzer for Barcode scanning, and this works very well. But if I try to implement a text-scanner with MlKitAnalyzer the processing gets very slow. It takes over 4 seconds for each frame to be processed. Same code but with a manual implementation of ImageAnalysis.Analyzer processes a frame in about 600ms. Any help as to what is making MlKitAnalyzer so slow with text-recognition would be nice!

My code for creating the analyzer:

private fun clearAndSetAnalyzer() {
    cameraController?.clearImageAnalysisAnalyzer()
    
    val startMs = SystemClock.elapsedRealtime()
    val scanner = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)

    val analyzer = MlKitAnalyzer(
        listOf(scanner), 
        ImageAnalysis.COORDINATE_SYSTEM_ORIGINAL, 
        mainThreadExecutor()
    ) { result ->
        result.getValue(scanner)?.let { resultText ->
            Log.i(TAG, "Scan complete net. Time: ${SystemClock.elapsedRealtime() - startMs}ms.")
        }
    }
    
    cameraController?.setImageAnalysisAnalyzer(mainThreadExecutor(), analyzer)
}


from MlKitAnalyzer for Android CameraX is slow for text-recognition

No comments:

Post a Comment