zynkware / Document-Scanning-Android-SDK

Document Scanner is an Android library (kotlin based) for scanning documents based on CameraX API and a tiny version of OpenCV.
163 stars 63 forks source link

Document Scanner with tiny OpenCV

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

Features

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.zynkware:Document-Scanning-Android-SDK:1.1.1'
}

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:

<activity android:name=".AppScanActivity"  
          android:screenOrientation="portrait"  
          android:theme="@style/Theme.AppCompat.NoActionBar" />

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 3 files:

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:

Throwable can be null for some error messages like Permissions

Configuration

Thanks

License

Copyright 2020 ZynkSoftware SRL

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.