Skip to content

entropyconquers/android-document-scanner-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android Document Scanner Library

A powerful and efficient Android library that leverages the capabilities of OpenCV and MLKit to provide fast and precise document scanning functionality.

Please ⭐ this library if you found it useful and/or want to support its development.

Features

  • Fast and accurate document detection
  • Perspective correction
  • Image enhancement
  • Cropping support

Installation

Method 1: Clone the demo app

  1. Clone the repository using the following command:
git clone https://github.com/entropyconquers/android-document-scanner-library.git
  1. Open the project in Android Studio and run the app module.

Method 2: Add the scanLib module to your project

  1. Clone the repository using the following command:
git clone https://github.com/entropyconquers/android-document-scanner-library.git
  1. Open your project in Android Studio and select File -> New -> Import Module

  2. Select the scanLib module from the cloned repository and click Finish

  3. Add the following lines to your app's build.gradle file:

dependencies {
    implementation project(':scanLib')
}
  1. Add mavencentral and jitpack repositories to your project's build.gradle | settings.gradle files:
// build.gradle
allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

// settings.gradle
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}
  1. Sync your project with gradle files

Usage

1. Initialize the Activity as BaseScannerActivity

class MainActivity : BaseScannerActivity() {
    override fun onError(throwable: Throwable) {
        Log.d(ContentValues.TAG, "ERROR A")
        when (throwable) {
            is NullCorners -> Toast.makeText(
                this,
                "R.string.null_corners", Toast.LENGTH_LONG
            )
                .show()
            else -> Toast.makeText(this, throwable.message, Toast.LENGTH_LONG).show()
        }
    }

    override fun onDocumentAccepted(bitmap: Bitmap) {
    }

    override fun onClose() {
        finish()
    }
}

The BaseScannerActivity class provides the following abstract methods that you need to implement:

abstract fun onError(throwable: Throwable) // Called when an error occurs
abstract fun onDocumentAccepted(bitmap: Bitmap) // Called when a document is accepted, returns the scanned bitmap
abstract fun onClose() // Called when the user presses the close button

Credits

This library has been built on top of the work of:

Kuama-IT, Android Document Scanner

License

MIT License

About

A powerful and efficient Android library that leverages the capabilities of OpenCV and MLKit to provide fast and precise document scanning functionality.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages