TranslateOCRApp is an Android application that allows users to click pictures of Swedish and German text and translate them into english. The app leverages Google ML-Kit for ML functionalities like OCR, Language identification and Translation and CameraX for camera functionality.
This is a companion repo for by blog: Android OCR Translation App using Kotlin and Google ML-Kit
You can either download the apk from the releases or build the apk yourself using Android Studio.
Point the camera at the text you want to translate and capture an image by clicking the capture button. After the capture, the app will translate the text and display an image with the translated text.
Note: The app needs wifi internet the first time it's used to download and store the translation models.
Translating an advertisement poster using the appThe TranslateOCRApp works in the following steps:
-
Capture Image: The user can capture an image of the text using the camera functionality implemented in
MainActivity. Upon capturing the image, it is saved for further processing. -
Optical Character Recognition (OCR): After the image is captured, the
PreviewActivityis launched, where the raw image is displayed. The app then utilizes Google ML Kit's OCR capabilities provided by theOcrHelperclass to extract all the text present in the image. -
Language Identification: Once the text is extracted using OCR, the
LanguageRecognizerclass is employed to identify the language of the extracted text. The app determines if the text is in Swedish, German, or an undetermined language. -
Translation: Based on the identified language, the app decides which language translation model to use. The
TextTranslatorclass handles the downloading and loading of the appropriate translation model (German if undetermined). The text is then translated into English. The class also manages translation models, such as downloading and storing them locally as needed. -
Image Transformation: The original image, along with the overlay of the translated text, is displayed to the user in the
PreviewActivity. TheBitmapAnnotatorclass takes care of overlaying the translated text on top of the original image. This is done by blurring the original text and replacing them with their translations.
Contributions to the TranslateOCRApp are welcome! If you find any issues or want to add new features, please create a pull request or open an issue in this GitHub repository.
The TranslateOCRApp is released under the MIT License. Feel free to use, modify, and distribute the code as per the terms of the license.
