Search code examples
androidfirebase-mlkit

ML Kit text recognition + cyrillic


I am trying to use ML kit text recognition for cyrillic using android, but kit doesn't recognize correctly Russian language? When I used English text everything was OK. Can I improve my result? Maybe, am I doing something wrong?

P.S Thanks people who creates this Kit, It's cool.

enter image description here

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    cameraProviderFuture = ProcessCameraProvider.getInstance(context!!)

    cameraProviderFuture.addListener(Runnable {
        val cameraProvider = cameraProviderFuture.get()
        bindPreview(cameraProvider)
    }, ContextCompat.getMainExecutor(context))

    takePicture.setOnClickListener {
        imageCapture.takePicture(File(getVideoFilePath(context!!)),
                ContextCompat.getMainExecutor(context),
                object : ImageCapture.OnImageSavedCallback {
                    @RequiresApi(Build.VERSION_CODES.P)
                    override fun onImageSaved(file: File) {
                        startTextRecognition(file)
                    }
                    override fun onError() {}
                })
    }
}

private fun startTextRecognition(textImage: File) {
    val recognizer = FirebaseVision.getInstance().onDeviceTextRecognizer
    recognizer.processImage(FirebaseVisionImage.fromFilePath(context, textImage.toUri()))
            .addOnSuccessListener {
                processTextRecognitionResult(it)
            }.addOnFailureListener {
                it.printStackTrace()
            }
}

  private fun processTextRecognitionResult(text: FirebaseVisionText) {
    var str = ""
    val blocks = text.textBlocks
    blocks.forEach { textBlock ->
        textBlock.lines.forEach { line ->
            line.elements.forEach {
                str += it.text + " "
            }
        }
    }
    textResult.text = str
}

I am using CameraX for taking a photo


Solution

  • ML Kit on device currently only supports Latin character sets. More are available with the Cloud options: https://firebase.google.com/docs/ml-kit/recognize-text