An Android library for scanning documents based on CameraX API and a tiny version of OpenCV

Overview

Document Scanner with tiny OpenCV

example1.mp4

Document Scanner is an Android library (kotlin based) for scanning documents based on CameraX API and a tiny version of OpenCV.

This library was taken and modified from Document-Scanning-Android-SDK. Improved logic of image processing, now the processing time is increased by more than 5 times. Scanning a document under ideal scanning conditions takes approximately 5 seconds.

Features

  • tiny version of OpenCV 4.4.0:
    • armeabi-v7a: 3.1 MB (original: 10.1 MB)
    • arm64-v8a: 5.6 MB (original: 18.8 MB)
    • x86: 16.7 MB (original: 38.6 MB)
    • x86_64: 25.1 MB (original: 53.7 MB)
  • live detection (also detect rectangle with one bent angle)
  • auto scan and flash support
  • edit detected rectangle
  • configure size of results using Compressor

Getting started

Document Scanner is supported on Android devices starting from SDK 21 (Lollipop)

Installation

in root project build.gradle:

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

in app build.gradle:

android {
    ...
    compileOptions {
	sourceCompatibility JavaVersion.VERSION_1_8
	targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
	    ...
    implementation 'com.github.Krobys:document-scanner-fast:1.0.0'
}

Usage

Initialization

In your Application class:

class MyCustomApplication: Application() {  
    override fun onCreate() {  
        ...
        val configuration = DocumentScanner.Configuration()  
    	configuration.imageQuality = 100  
    	configuration.imageSize = 1000000 // 1 MB  
    	configuration.imageType = Bitmap.CompressFormat.JPEG  
    	DocumentScanner.init(this, configuration) // or simply DocumentScanner.init(this)
    }   
}

Create an Activity (e.g. AppScanActivity) that extends ScanActivity

In manifest:

">

  

AppScanActivity:

class AppScanActivity: ScanActivity() {  
    override fun onCreate(savedInstanceState: Bundle?) {  
        super.onCreate(savedInstanceState)  
        setContentView(R.layout.app_scan_activity_layout)  
        addFragmentContentLayout()
    }  
  
    override fun onError(error: DocumentScannerErrorModel) {  
        
    }
  
    override fun onSuccess(scannerResults: ScannerResults) {  
        
    }
  
    override fun onClose() {  
        finish()  
    }

ScannerResults

Document Scanner library will return image files using fun onSuccess(scannerResults: ScannerResults). ScannerResults contains 1 file:

  • imageFile

Error Handling

All errors are returned to app using fun onError(error: DocumentScannerErrorModel)

data class DocumentScannerErrorModel(  
     var errorMessage: ErrorMessage? = null,  
     var throwable: Throwable? = null  
)

ErrorMessage is an enum containing the following error types:

  • TAKE_IMAGE_FROM_GALLERY_ERROR
  • PHOTO_CAPTURE_FAILED
  • CAMERA_USE_CASE_BINDING_FAILED
  • DETECT_LARGEST_QUADRILATERAL_FAILED
  • INVALID_IMAGE
  • CAMERA_PERMISSION_REFUSED_WITHOUT_NEVER_ASK_AGAIN
  • CAMERA_PERMISSION_REFUSED_GO_TO_SETTINGS
  • STORAGE_PERMISSION_REFUSED_WITHOUT_NEVER_ASK_AGAIN
  • STORAGE_PERMISSION_REFUSED_GO_TO_SETTINGS
  • CROPPING_FAILED

Throwable can be null for some error messages like Permissions

Configuration

  • imageQuality:
    • From 0 to 100
    • Default value is 100
  • imageSize:
    • Image size in bytes
    • No default value
  • imageType:
    • imageType can be Bitmap.CompressFormat.JPEG, Bitmap.CompressFormat.PNG or Bitmap.CompressFormat.WEBP
    • Default value is Bitmap.CompressFormat.JPEG

Thanks

License

Copyright 2021 Krobys

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You might also like...
Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image selection.

Awesome Image Picker Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image sel

Android library project for cropping images
Android library project for cropping images

I guess people are just cropping out all the sadness An Android library project that provides a simple image cropping Activity, based on code from AOS

An android image compression library.
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

A simple image cropping library for Android.
A simple image cropping library for Android.

SimpleCropView The SimpleCropView is an image cropping library for Android. It simplifies your code for cropping image and provides an easily customiz

An image resizing library for Android
An image resizing library for Android

Resizer Inspired by zetbaitsu's Compressor, Resizer is a lightweight and easy-to-use Android library for image scaling. It allows you to resize an ima

Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.
Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.

ChiliPhotoPicker Made with ❤️ by Chili Labs. Library made without DataBinding, RxJava and image loading libraries, to give you opportunity to use it w

Simple android image popup Library
Simple android image popup Library

Android Image Popup Show image as a popup on a click event or any event. Simply set the image as drawable and thats it!!!. And also you can set width,

Image loading library for Android

Image Loader Image loader library for Android. Deprecated. See Glide. Features Image transformations Automatic memory and storage caching Ability to l

SVG rendering library for Android

AndroidSVG AndroidSVG is a SVG parser and renderer for Android. It has almost complete support for the static visual elements of the SVG 1.1 and SVG 1

Comments
  • LiveDetection doesn't work

    LiveDetection doesn't work

    Hi,

    Thank you for nice library.

    I've got problems with liveDetection. It doesn't work. I cannot see the rectangle and also autoCapture is not working. Any suggestions?

    Best regards

    opened by swiech-applover 2
  • Gradle - Failed to resolve dependancy

    Gradle - Failed to resolve dependancy

    When adding this library into gradle, i get an error Failed to resolve dependency. when I used AAR of the library it worked fine.

    I haven't found much help online, but I assume this happens because of the difference in gradle version, I'm on 7.1.1 and this library is on 4.x.x

    would you consider updating gradle and releasing a new version?

    opened by Ahmed-AlHahsimi-SEDRA 2
Releases(1.0.0)
Owner
null
A simple implementation of rectangle detector on Android using OpenCV.

A simple implementation of rectangle detector on Android using OpenCV.

SmartBank, Inc. 4 Oct 7, 2022
OpenGLES - an embedded version of the OpenGL cross-platform API which is used to render 2D/3D texture

OpenGLES is an embedded version of the OpenGL cross-platform API which is used to render 2D/3D texture. This sample code contains the implementation of shape rendering using OpenGLES.

MindInventory 5 Sep 20, 2022
Pixel Boom is a Java-based Android software, featuring image super-resolution and colorization

Pixel Boom is a Java-based Android software, featuring image super-resolution and colorization.

Zaitian 1 Jul 3, 2022
Android filters based on OpenGL (idea from GPUImage for iOS)

GPUImage for Android Idea from: iOS GPUImage framework Goal is to have something as similar to GPUImage as possible. Vertex and fragment shaders are e

CATS Open Source Softwares 8.6k Dec 28, 2022
An image board client based on Gelbooru for android, made from Jetpack Compose 🚀 .

Mejiboard An image board client based on Gelbooru for android, made from Jetpack Compose ?? . Features Material Design UI Easy one-handed operation Li

Agung Watanabe 59 Dec 30, 2022
🐶 Simple app which shows random dog image from Dog API

?? Doggy App ?? ?? Simple app which shows random dog image from Dog API with Retrofit2 and Glide ?? ❤️ Retrofit @GET Request YouTube Tutorial! (Stevdz

Yağmur Erdoğan 10 Nov 1, 2022
Library to save image locally and shows options to open and share !

Image Save and Share Library to save image locally and shows options to open and share ! Download Demo APK from HERE Kindly use the following links to

Prabhakar Thota 27 Apr 18, 2022
Customizable Android full screen image viewer for Fresco library supporting "pinch to zoom" and "swipe to dismiss" gestures. Made by Stfalcon

This project is no longer supported. If you're able to switch from Fresco to any other library that works with the Android's ImageView, please migrate

Stfalcon LLC 1.8k Dec 19, 2022
Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.

Dali Dali is an image blur library for Android. It is easy to use, fast and extensible. Dali contains several modules for either static blurring, live

Patrick Favre-Bulle 1k Dec 1, 2022
An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.

An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.

Daichi Furiya 257 Jan 2, 2023