Last updated: February 5, 2025

<span aria-hidden="true" id="implementing-ocr-in-android-and-ios-apps-with-open-source-sdks"></span>

# Implementing OCR in Android and iOS apps with open-source SDKs

![Tim Koschützki](/assets/images/teammates/avatar-tim-kos-1.jpg?dpl=dpl_BY7TrZQKuzkQ5PseorQMAAVfrV9b)

#### Tim Koschützki

Co-founder · Berlin, Germany · Show bio

[](https://x.com/tim%5Fkos)[](https://github.com/tim-kos)

Adding OCR capabilities to your Android and iOS apps can significantly enhance functionality by enabling text extraction from images. This guide walks you through integrating Tesseract OCR—a widely used open-source SDK—into your mobile applications for robust text recognition.

<span aria-hidden="true" id="introduction-to-ocr-in-mobile-apps"></span>

## Introduction to OCR in mobile apps

Optical Character Recognition (OCR) technology extracts text from digital images. Implementing OCR in mobile apps opens up possibilities for document scanning, text extraction, and improved user experiences by converting images into editable text.

<span aria-hidden="true" id="prerequisites"></span>

## Prerequisites

Before integrating OCR in your mobile apps, ensure you meet these requirements:

* Android: API 21+ (Android 5.0+)
* iOS: iOS 9.0+
* Appropriate tessdata files for your target languages
* For Android API 29+, tessdata files must reside in the app's private directories

<span aria-hidden="true" id="overview-of-open-source-ocr-sdks"></span>

## Overview of open-source OCR SDKs

Tesseract OCR is a leading open-source engine known for its powerful text recognition capabilities. The latest version (5.5.0) offers improved accuracy and performance. For mobile platforms, we use platform-specific wrappers: Tesseract4Android for Android and TesseractOCRiOS for iOS.

<span aria-hidden="true" id="setting-up-tesseract-ocr-in-android"></span>

## Setting up Tesseract OCR in Android

To integrate Tesseract OCR into your Android app, follow these steps:

1. Add Tesseract4Android to your project by including the dependency in your Gradle file:

```groovy
dependencies {  
    implementation 'cz.adaptech.tesseract4android:tesseract4android:4.8.0'  
    // For multi-threaded support, use:  
    // implementation 'cz.adaptech.tesseract4android:tesseract4android-openmp:4.8.0'  
}  
```

2. Include the trained data files:\
   Download the appropriate `*.traineddata` files from the[Tesseract OCR Data GitHub repository⁠](https://github.com/tesseract-ocr/tessdata) and place them in your app's assets directory under `tessdata/`.

<span aria-hidden="true" id="implementing-ocr-in-an-android-app"></span>

## Implementing OCR in an Android app

Below is an example of how to implement OCR functionality in your Android application:

```java
public class OCRManager {
    private TessBaseAPI tessBaseAPI;
    private Context context;

    public OCRManager(Context context) {
        this.context = context;
        initTesseract();
    }

    private void initTesseract() {
        tessBaseAPI = new TessBaseAPI();
        String dataPath = context.getFilesDir() + "/tesseract/";
        // Initialize with English language
        if (!tessBaseAPI.init(dataPath, "eng")) {
            tessBaseAPI.recycle();
            throw new RuntimeException("Failed to initialize Tesseract");
        }
    }

    public String extractTextFromImage(Bitmap bitmap) {
        tessBaseAPI.setImage(bitmap);
        return tessBaseAPI.getUTF8Text();
    }

    public void release() {
        if (tessBaseAPI != null) {
            tessBaseAPI.recycle();
            tessBaseAPI = null;
        }
    }
}

```

Ensure that OCR operations run on a background thread to avoid blocking the UI.

<span aria-hidden="true" id="setting-up-tesseract-ocr-in-ios"></span>

## Setting up Tesseract OCR in iOS

To integrate Tesseract OCR into your iOS app, follow these steps:

1. Add TesseractOCRiOS via CocoaPods by updating your Podfile:

```ruby
platform :ios, '9.0'  
use_frameworks!  
target 'YourApp' do  
  pod 'TesseractOCRiOS', '5.0.1'  
end  
```

2. Install the dependencies by running:

```bash
pod install  
```

<span aria-hidden="true" id="implementing-ocr-in-an-ios-app"></span>

## Implementing OCR in an iOS app

The following Objective-C example demonstrates how to implement OCR functionality in your iOS app:

```objective-c
@interface OCRManager : NSObject

@property (nonatomic, strong) G8Tesseract *tesseract;

- (instancetype)init;
- (NSString *)extractTextFromImage:(UIImage *)image;

@end

@implementation OCRManager

- (instancetype)init {
    self = [super init];
    if (self) {
        _tesseract = [[G8Tesseract alloc] initWithLanguage:@"eng"];
        _tesseract.engineMode = G8OCREngineModeTesseractOnly;
        _tesseract.pageSegmentationMode = G8PageSegmentationModeAuto;
    }
    return self;
}

- (NSString *)extractTextFromImage:(UIImage *)image {
    self.tesseract.image = [image g8_blackAndWhite];
    [self.tesseract recognize];
    return self.tesseract.recognizedText;
}

@end

```

As with Android, perform OCR operations on a background thread to maintain a responsive user interface.

<span aria-hidden="true" id="tips-for-optimizing-ocr-performance"></span>

## Tips for optimizing OCR performance

To achieve optimal OCR performance in your mobile apps, consider the following best practices:

1. Image Preprocessing:
   * Convert images to grayscale.
   * Apply adaptive thresholding or binarization.
   * Reduce noise using filters such as Gaussian blur.
   * Ensure image resolution is around 300-400 DPI for best results.
2. Resource Management:
   * Reuse TessBaseAPI or G8Tesseract instances if processing multiple images.
   * Release resources properly once OCR processing is complete.
   * Cache results for frequently processed images to improve performance.
3. Threading Considerations:
   * TessBaseAPI and G8Tesseract are not thread-safe; use separate instances for concurrent operations.
   * Run all OCR tasks on background threads to prevent UI blocking.
4. Performance Optimization:
   * Choose appropriate page segmentation modes for your specific use case.
   * Limit recognition to expected character sets to reduce processing time.

<span aria-hidden="true" id="conclusion"></span>

## Conclusion

Integrating OCR capabilities into your mobile apps with open-source SDKs like Tesseract OCR unlocks powerful text recognition features. By following these implementation guidelines and optimization tips, you can build efficient and accurate OCR functionality in your applications.

For advanced file processing, including image processing and document processing, consider exploring [Transloadit's services](/index.md).

\#mobile-ocr-sdk#android-ocr-sdk#ios-ocr-sdk#tesseract-ocr#integrate-ocr-in-mobile-apps#open-source-ocr-sdk#ocr-in-android#ocr-in-ios#text-recognition#image-processing#artificial-intelligence-service

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
