-
Notifications
You must be signed in to change notification settings - Fork 48
[SB-20572] acceptance 9.0.0 #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
SerhiiChaban-apryse
wants to merge
7
commits into
master
Choose a base branch
from
sc/SB-20572_image_enhanser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35f6c04
add document enhancer classic example module
46705c0
add document enhancer public doc snippet
e5a24d4
add image enhancer snippets
12c4ce2
cleanup
9d9764f
cleanup
9560128
Add rtu enhancer config snippet
de1fddb
fix compiling
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| plugins { | ||
| id("com.android.application") | ||
| id("org.jetbrains.kotlin.android") | ||
| } | ||
|
|
||
| android { | ||
| namespace = project.ext.submodulesNamespace | ||
| compileSdk = project.ext.compileSdkVersion | ||
|
|
||
| defaultConfig { | ||
| applicationId = project.ext.exampleAppId | ||
| minSdk = project.ext.minSdkVersion | ||
| targetSdk = project.ext.targetSdkVersion | ||
| versionCode = 1 | ||
| versionName = "1.0" | ||
| } | ||
|
|
||
| buildTypes { | ||
| named("debug") { | ||
| // set this to `false` to allow debugging and run a "non-release" build | ||
| minifyEnabled = false | ||
| debuggable = true | ||
| } | ||
| } | ||
|
|
||
| kotlin { | ||
| jvmToolchain(project.ext.jvmToolchainVersion) | ||
| } | ||
|
|
||
| packagingOptions { | ||
| exclude 'META-INF/LICENSE.txt' | ||
| exclude 'META-INF/LICENSE' | ||
| exclude 'META-INF/NOTICE.txt' | ||
| exclude 'META-INF/NOTICE' | ||
| exclude 'META-INF/DEPENDENCIES' | ||
| } | ||
|
|
||
| buildFeatures { | ||
| viewBinding = true | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":common")) | ||
| implementation("io.scanbot:sdk-package-1:${project.ext.scanbotSdkVersion}") | ||
| implementation("androidx.appcompat:appcompat:${project.ext.androidxAppcompatVersion}") | ||
| } |
31 changes: 31 additions & 0 deletions
31
classic-components-example/document-enhancer/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| > | ||
|
|
||
| <uses-permission android:name="android.permission.CAMERA" /> | ||
| <uses-permission android:name="android.permission.VIBRATE" /> | ||
|
|
||
| <uses-feature android:name="android.hardware.camera" /> | ||
|
|
||
| <application | ||
| android:name=".ExampleApplication" | ||
| android:allowBackup="true" | ||
| android:label="@string/app_name" | ||
| android:theme="@style/AppTheme" | ||
| tools:replace="android:theme"> | ||
| <activity android:name=".DocumentCameraActivity" /> | ||
| <activity | ||
| android:name=".MainActivity" | ||
| android:label="@string/app_name" | ||
| android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
|
|
||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
|
|
||
| </application> | ||
|
|
||
| </manifest> |
189 changes: 189 additions & 0 deletions
189
...ents-example/document-enhancer/src/main/java/io/scanbot/example/DocumentCameraActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| package io.scanbot.example | ||
|
|
||
| import android.Manifest | ||
| import android.content.pm.PackageManager | ||
| import android.graphics.Bitmap | ||
| import android.graphics.BitmapFactory | ||
| import android.graphics.Color | ||
| import android.graphics.Matrix | ||
| import android.os.Bundle | ||
| import android.view.View | ||
| import android.widget.Button | ||
| import android.widget.ImageView | ||
| import android.widget.TextView | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.core.app.ActivityCompat | ||
| import androidx.core.content.ContextCompat | ||
| import androidx.core.view.WindowCompat | ||
| import io.scanbot.common.onSuccess | ||
|
|
||
|
|
||
| import io.scanbot.example.common.applyEdgeToEdge | ||
| import io.scanbot.sdk.ScanbotSDK | ||
| import io.scanbot.sdk.camera.CaptureInfo | ||
| import io.scanbot.sdk.document.DocumentScannerFrameHandler | ||
| import io.scanbot.sdk.document.ui.DocumentScannerView | ||
| import io.scanbot.sdk.document.ui.IDocumentScannerViewCallback | ||
| import io.scanbot.sdk.documentscanner.DocumentDetectionStatus | ||
| import io.scanbot.sdk.documentscanner.DocumentEnhancer | ||
| import io.scanbot.sdk.documentscanner.DocumentScanner | ||
| import io.scanbot.sdk.documentscanner.DocumentStraighteningMode | ||
| import io.scanbot.sdk.documentscanner.DocumentStraighteningParameters | ||
| import io.scanbot.sdk.geometry.AspectRatio | ||
| import io.scanbot.sdk.image.ImageRef | ||
| import io.scanbot.sdk.process.ImageProcessor | ||
| import io.scanbot.sdk.ui.camera.ShutterButton | ||
| import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode | ||
|
|
||
| class DocumentCameraActivity : AppCompatActivity() { | ||
|
|
||
| private var lastUserGuidanceHintTs = 0L | ||
| private var flashEnabled = false | ||
| private var autoSnappingEnabled = true | ||
| private val ignoreOrientationMistmatch = true | ||
|
|
||
| private lateinit var documentScannerView: DocumentScannerView | ||
|
|
||
| private lateinit var resultView: ImageView | ||
| private lateinit var userGuidanceHint: TextView | ||
| private lateinit var autoSnappingToggleButton: Button | ||
| private lateinit var shutterButton: ShutterButton | ||
|
|
||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY) | ||
|
|
||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_camera) | ||
| askPermission() | ||
| supportActionBar!!.hide() | ||
| applyEdgeToEdge(findViewById(R.id.root_view)) | ||
|
|
||
| val scanbotSdk = ScanbotSDK(this) | ||
|
|
||
| documentScannerView = findViewById(R.id.document_scanner_view) | ||
|
|
||
| resultView = findViewById<View>(R.id.result) as ImageView | ||
| val documentEnhancer = scanbotSdk.createDocumentEnhancer() | ||
| scanbotSdk.createDocumentScanner().onSuccess { documentScanner -> | ||
|
|
||
| documentScannerView.apply { | ||
| initCamera() | ||
| initScanningBehavior( | ||
| documentScanner, | ||
| { result, frame -> | ||
| // Here you are continuously notified about document scanning results. | ||
| // For example, you can show a user guidance text depending on the current scanning status. | ||
| result.onSuccess { data -> | ||
| } | ||
| false // typically you need to return false | ||
| }, | ||
| object : IDocumentScannerViewCallback { | ||
| override fun onCameraOpen() { | ||
| documentScannerView.viewController.useFlash(flashEnabled) | ||
| } | ||
|
|
||
| override fun onPictureTaken(image: ImageRef, captureInfo: CaptureInfo) { | ||
| documentEnhancer.onSuccess { documentEnhancer -> | ||
| processPictureTaken(image, documentEnhancer) | ||
| } | ||
|
|
||
|
|
||
| // continue scanning | ||
| documentScannerView.postDelayed({ | ||
| documentScannerView.viewController.startPreview() | ||
| }, 1000) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| documentScannerView.polygonConfiguration.apply { | ||
| setPolygonFillColor(POLYGON_FILL_COLOR) | ||
| setPolygonFillColorOK(POLYGON_FILL_COLOR_OK) | ||
| } | ||
|
|
||
| documentScannerView.viewController.apply { | ||
| setAcceptedAngleScore(60.0) | ||
| setAcceptedSizeScore(75.0) | ||
| setIgnoreOrientationMismatch(ignoreOrientationMistmatch) | ||
|
|
||
| // Please note: https://docs.scanbot.io/document-scanner-sdk/android/features/document-scanner/autosnapping/#sensitivity | ||
| setAutoSnappingSensitivity(0.85f) | ||
| } | ||
|
|
||
| shutterButton = findViewById(R.id.shutterButton) | ||
| shutterButton.setOnClickListener { documentScannerView.viewController.takePicture(false) } | ||
| shutterButton.visibility = View.VISIBLE | ||
|
|
||
| findViewById<View>(R.id.flashToggle).setOnClickListener { | ||
| flashEnabled = !flashEnabled | ||
| documentScannerView.viewController.useFlash(flashEnabled) | ||
| } | ||
|
|
||
| autoSnappingToggleButton = findViewById(R.id.autoSnappingToggle) | ||
| autoSnappingToggleButton.setOnClickListener { | ||
| autoSnappingEnabled = !autoSnappingEnabled | ||
| setAutoSnapEnabled(autoSnappingEnabled) | ||
| } | ||
| autoSnappingToggleButton.post { setAutoSnapEnabled(autoSnappingEnabled) } | ||
| } | ||
|
|
||
| private fun askPermission() { | ||
| if (ContextCompat.checkSelfPermission( | ||
| this, | ||
| Manifest.permission.CAMERA | ||
| ) != PackageManager.PERMISSION_GRANTED | ||
| ) { | ||
| ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 999) | ||
| } | ||
| } | ||
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| documentScannerView.viewController.onResume() | ||
| } | ||
|
|
||
| override fun onPause() { | ||
| super.onPause() | ||
| documentScannerView.viewController.onPause() | ||
| } | ||
|
|
||
| private fun processPictureTaken(image: ImageRef, documentEnhancer: DocumentEnhancer) { | ||
| // STRAIGHTEN SCANNED IMAGE ASSUMING DOCUMENT IS BENT | ||
| // Run document enhancer unwarping on original image: | ||
| val result = documentEnhancer.straighten(image, DocumentStraighteningParameters().apply { | ||
| straighteningMode = DocumentStraighteningMode.STRAIGHTEN | ||
| // uncomment if you want wo set specific aspect ratios for documents | ||
| // aspectRatios = listOf(AspectRatio(29.0, 21.0)) | ||
| }).getOrNull() | ||
|
|
||
| resultView.post { | ||
| resultView.setImageBitmap( | ||
| result?.straightenedImage?.toBitmap()?.getOrNull() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun setAutoSnapEnabled(enabled: Boolean) { | ||
| documentScannerView.viewController.apply { | ||
| autoSnappingEnabled = enabled | ||
| isFrameProcessingEnabled = enabled | ||
| } | ||
| documentScannerView.polygonConfiguration.setPolygonViewVisible(enabled) | ||
|
|
||
| autoSnappingToggleButton.text = "Automatic ${if (enabled) "ON" else "OFF"}" | ||
| if (enabled) { | ||
| shutterButton.showAutoButton() | ||
| } else { | ||
| shutterButton.showManualButton() | ||
| userGuidanceHint.visibility = View.GONE | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private val POLYGON_FILL_COLOR = Color.parseColor("#55ff0000") | ||
| private val POLYGON_FILL_COLOR_OK = Color.parseColor("#4400ff00") | ||
| } | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
...mponents-example/document-enhancer/src/main/java/io/scanbot/example/ExampleApplication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package io.scanbot.example | ||
|
|
||
| import android.app.Application | ||
| import io.scanbot.sdk.ScanbotSDK | ||
| import io.scanbot.sdk.ScanbotSDKInitializer | ||
| import io.scanbot.sdk.util.log.LoggerProvider | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.launch | ||
| import kotlin.coroutines.CoroutineContext | ||
|
|
||
| class ExampleApplication : Application(), CoroutineScope { | ||
|
|
||
| private var job: Job = Job() | ||
| override val coroutineContext: CoroutineContext | ||
| get() = Dispatchers.IO + job | ||
|
|
||
| /* | ||
| * TODO 1/2: Add the Scanbot SDK license key here. | ||
| * Please note: The Scanbot SDK will run without a license key for one minute per session! | ||
| * After the trial period is over all Scanbot SDK functions as well as the UI components will stop working. | ||
| * You can get an unrestricted "no-strings-attached" 30 day trial license key for free. | ||
| * Please submit the trial license form (https://scanbot.io/trial/) on our website by using | ||
| * the app identifier "io.scanbot.example.sdk.android" of this example app. | ||
| */ | ||
| val licenseKey = "" | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
|
|
||
| ScanbotSDKInitializer() | ||
| .withLogging(true) | ||
| // TODO 2/2: Enable the Scanbot SDK license key | ||
| //.license(this, licenseKey) | ||
| .licenseErrorHandler { status, feature, statusMessage -> | ||
| LoggerProvider.logger.d("ExampleApplication", "+++> License status: ${status.name}. Status message: $statusMessage") | ||
| LoggerProvider.logger.d("ExampleApplication", "+++> Feature not available: ${feature.name}") | ||
| } | ||
| //.sdkFilesDirectory(this, getExternalFilesDir(null)!!) | ||
| .initialize(this) | ||
|
|
||
| LoggerProvider.logger.d("ExampleApplication", "Scanbot SDK was initialized") | ||
|
|
||
| val licenseInfo = ScanbotSDK(this).licenseInfo | ||
| LoggerProvider.logger.d("ExampleApplication", "License status: ${licenseInfo.status}") | ||
| LoggerProvider.logger.d("ExampleApplication", "License isValid: ${licenseInfo.isValid}") | ||
| LoggerProvider.logger.d("ExampleApplication", "License expirationDate: ${licenseInfo.expirationDateString}") | ||
|
|
||
| launch { | ||
| // Clear all previously created documents in storage | ||
| ScanbotSDK(this@ExampleApplication).documentApi.deleteAllDocuments() | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.