Android Document Scanner Library, a Top 5 curated list of libraries build by developers to help you build an Android Document Scanner Application.

Need some career advice or prepping for an Android developer interview? Hit me up on Topmate.io, and let's chat!

Android Document Scanner Library

Scan Library (Java)

ScanLibrary is an Android Document Scanner Library built on top of OpenCV, using the app you will be able to select the exact edges and crop the document accordingly from the selected 4 edges and change the perspective transformation of the cropped image.

android document scanner library
Android document scanner library

Implement in project

To implement this library in your Android Studio project, first add the ‘scanlibrary’ folder inside the root of your project directory.

Then add the following line of code to your build.gradle (app) dependencies:

dependencies {
 
   implementation project(':scanlibrary')
 
}

Using the Library

In your activity or fragment when you want to give an option of document scanning to user then, first ass the following permissions to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Start the scanlibrary ScanActivity, with this the app will go to library, below is the sample code snippet:

 int REQUEST_CODE = 99;
       int preference = ScanConstants.OPEN_CAMERA;
       Intent intent = new Intent(this, ScanActivity.class);
       intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference);
       startActivityForResult(intent, REQUEST_CODE);

Note: preference can be one of OPEN_CAMERA or OPEN_MEDIA or left empty, based on the passed preference the scan library decides to open camera or media or open the scan home page.

Once the scanning is done, the application is returned from scan library to main app.

To retrieve the scanned image, add onActivityResult in your activity or fragment from where you have started startActivityForResult, below is the sample code snippet:

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT);
            Bitmap bitmap = null;
            try {
                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                getContentResolver().delete(uri, null, null);
                scannedImageView.setImageBitmap(bitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

Link to Github

Scanner WIP (Kotlin)

Skanner is an Android Document Scanner Library written in Kotlin that uses OpenCV for Android to scan a document within a given image.

Implement in Project

To include Skanner into your app using gradle just add JitPack repository to your root build.gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

and add the dependency to your app build.gradle

dependencies {

implementation 'com.github.brescia123:skanner:1.0.0-beta5'

}

You can reduce considerably the APK of your application by taking advantage of Apk Splits function of the Android Gradle plugin. You just have to add these lines to your build.gradle file:

android {
    ...
    splits {
        abi {
            enable true
            reset()
            include 'arm64-v8a', 'armeabi-v7a', 'mips', 'mips64', 'x86', 'x86_64'
            universalApk false
        }
    }
}

Link to Github

CV Scanner (Java)

An OpenCV based Android Document Scanner Library for Android to scan/crop ID documents or Passports.

Using the Library

The easiest way is to launch the DocumentScannerActivity

CVScanner.startScanner(this, isPassport, REQ_SCAN);

You’ll get the path of the scanned image in onActivityResult(int requestCode, int resultCode, Intent data)

if(requestCode == REQ_SCAN && resultCode == RESULT_OK){
  String path = data.getStringExtra(CVScanner.RESULT_IMAGE_PATH);
}

You can use the DocumentScannerFragment too

Fragment fragment = DocumentScannerFragment.instantiate(isScanningPassport);
getSupportFragmentManager().beginTransaction()
        .add(R.id.container, fragment)
        .commit();

Link to Github

Openalpr-android (Java)

OpenALPR Android Document Scanner Library is an open source Automatic License Plate Recognition library written in C++ with bindings in C#, Java, Node.js, and Python. This project ports this library to Android.

android document scanner

Implement in the project

irst, add the following to your app’s build.gradle file:

repositories {
    maven { url "https://jitpack.io" }
}

Them include the openalpr-android dependency:

dependencies {

    // ... other dependencies here.     
    implementation 'com.github.SandroMachado:openalpr-android:1.1.2'
}
 

Using the Library

Copy the OpenALPR configuration file to your android project assets directory /main/assets/runtime_data/openalpr.conf, open it and update the runtime_dir to your project directory (for instance, for the sample project the directory is: runtime_dir = /data/data/com.sandro.openalprsample/runtime_data).

After that just follow the code example below.

static final String ANDROID_DATA_DIR = "/data/data/com.sandro.openalprsample";

final String openAlprConfFile = ANDROID_DATA_DIR + File.separatorChar + "runtime_data" + File.separatorChar + "openalpr.conf";

String result = OpenALPR.Factory.create(MainActivity.this, ANDROID_DATA_DIR).recognizeWithCountryRegionNConfig("us", "", image.getAbsolutePath(), openAlprConfFile, 10);
Screencast

Link to Github

rn-doc-scanner-android (React)

Installation

react-native-git-upgrade

or delete node_modules folder

react-native upgrade

create-react-native-app rndocscannerExample
cd rndocscannerExample
yarn add https://github.com/Diastorm/rn-doc-scanner-android.git
yarn eject

select React Native: first option

react-native link

open android/build.gradle

inside allprojects->repositories

allprojects {
    repositories {
        ...
        mavenCentral()
        maven {
            url 'https://maven.google.com'
        }
        maven {
            url "http://dl.bintray.com/steveliles/maven"
        }
        maven {
            url "https://jitpack.io"
        }
    }
}

open android/app/src/main/AndroidManifest.xml

inside manifest tag

<manifest ...
    xmlns:tools="http://schemas.android.com/tools"
>

inside application tag

<application
    ...
    tools:replace="android:allowBackup"
>

open android/app/build.gradle

change compileSdkVersion xx to

compileSdkVersion 26

run react-native run-android --deviceId xxxx

where xxxx is from adb devices

Using the Library

import { RNDocScanner } from 'rn-doc-scanner'
import { Text, TouchableOpacity, Platform } from 'react-native'

const ScanButton = (props) => {
   const onPressScan = async () => {
    if (Platform.OS === 'android') {
        try {
            const image = await RNDocScanner.getDocumentCrop(true)
            console.log(image)
            } catch (err) {
            console.log(err)
            }
        }
    }

  return (
        <TouchableOpacity onPress={onPressScan}>
          <Text>Scan</Text>
        </TouchableOpacity>
    )
}

export default ScanButton

Link to Github

Check more Top 25 Curated list of Android Camera Libraries here…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like