Skip to content

Commit

Permalink
Merge pull request #156 from newlogic/feature/ocr-scanner
Browse files Browse the repository at this point in the history
Add OCR feature
  • Loading branch information
jlduragos authored Nov 10, 2023
2 parents 507ce07 + 8e2aec5 commit 227d969
Show file tree
Hide file tree
Showing 34 changed files with 867 additions and 173 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ID scanning Android app and library. Supports MRZ, NFC, Barcodes, and [ID PASS L
- Scan NFC
- Scan Barcode
- Scan [ID PASS Lite](https://github.com/idpass/idpass-lite)
- Scan OCR
- Supports Intent Call Out (ODK & Non-ODK)

This repository also includes an Android [demo app](app) to test what the library can do.
Expand Down Expand Up @@ -42,13 +43,14 @@ If you want to build this library from source, instructions to do so can be foun

The following table shows the intent actions available for each operation available in the library, both in ODK and Non-ODK:

| Scan Operation | ODK | Non-ODK |
| -------------- | ---------------------------------------------- | ------------------------------------------ |
| Scan Operation | ODK | Non-ODK |
|----------------|------------------------------------------------|--------------------------------------------|
| MRZ | `org.idpass.smartscanner.odk.MRZ_SCAN` | `org.idpass.smartscanner.MRZ_SCAN` |
| NFC | `org.idpass.smartscanner.odk.NFC_SCAN` | `org.idpass.smartscanner.NFC_SCAN` |
| Barcode | `org.idpass.smartscanner.odk.BARCODE_SCAN` | `org.idpass.smartscanner.BARCODE_SCAN` |
| QR code | `org.idpass.smartscanner.odk.QRCODE_SCAN` | `org.idpass.smartscanner.QRCODE_SCAN` |
| ID PASS Lite | `org.idpass.smartscanner.odk.IDPASS_LITE_SCAN` | `org.idpass.smartscanner.IDPASS_LITE_SCAN` |
| OCR | `org.idpass.smartscanner.odk.OCR_SCAN` | `org.idpass.smartscanner.OCR_SCAN` |

To perform an operation, create an intent for the desired operation. This example shows how to call an intent to scan an MRZ (ODK):

Expand Down Expand Up @@ -97,6 +99,8 @@ Refer to the [Result fields reference](https://github.com/idpass/smartscanner-co

Refer to the [API Reference](https://github.com/idpass/smartscanner-core/wiki/API-Reference) for complete information about each scan operation and the different options available.

Refer to the [SmartScanner intent extra reference](https://github.com/newlogic/smartscanner-core/wiki/SmartScannerActivity-Intent-extra-reference) for examples on how to pass different options intent extra to SmartScanner.

Finally, for convenience we recommend using the [smartscanner-android-api](https://github.com/idpass/smartscanner-android-api) library which simplifies the app intent call out process.

## Running the demo app
Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/org/newlogic/smartscanner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import org.idpass.smartscanner.api.ScannerConstants
import org.idpass.smartscanner.api.ScannerIntent
import org.idpass.smartscanner.lib.SmartScannerActivity
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_FAIL_RESULT
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_HEADER_RESULT
Expand All @@ -39,7 +38,6 @@ import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_RESULT
import org.idpass.smartscanner.lib.SmartScannerActivity.Companion.SCANNER_SIGNATURE_VERIFICATION
import org.idpass.smartscanner.lib.nfc.NFCActivity
import org.idpass.smartscanner.lib.scanner.config.*
import org.idpass.smartscanner.lib.scanner.config.Config.Companion.OP_SCANNER
import org.idpass.smartscanner.lib.scanner.config.Config.Companion.ORIENTATION
import org.newlogic.smartscanner.databinding.ActivityMainBinding
import org.newlogic.smartscanner.result.IDPassResultActivity
Expand Down Expand Up @@ -80,6 +78,7 @@ class MainActivity : AppCompatActivity() {
binding.itemBarcode.item.setOnClickListener { scanBarcode(BarcodeOptions.default) }
binding.itemIdpassLite.item.setOnClickListener { scanIDPassLite() }
binding.itemMrz.item.setOnClickListener { scanMRZ() }
binding.itemOcr.item.setOnClickListener { scanOCR() }
binding.itemQr.item.setOnClickListener { scanQRCode() }
// binding.itemQrGzip.item.setOnClickListener { scanQRCodeGzip() }
binding.itemNfc.item.setOnClickListener { scanNFC() }
Expand Down Expand Up @@ -145,6 +144,28 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(intent, OP_SCANNER)
}

private fun scanOCR() {
val intent = Intent(this, SmartScannerActivity::class.java)
intent.putExtra(
SmartScannerActivity.SCANNER_OPTIONS,
ScannerOptions(
mode = Modes.OCR.value,
language = getLanguage(preference),
ocrOptions = OCROptions(
analyzeStart = 1000
),
config = Config(
branding = true,
imageResultType = imageType,
label = "",
isManualCapture = false,
orientation = getOrientation(preference)
)
)
)
startActivityForResult(intent, OP_SCANNER)
}

private fun scanNFC() {
if (isNFCSupported()) {
val intent = Intent(this, SmartScannerActivity::class.java)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_scan_ocr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#646464"
android:pathData="M43.2,137.6c-3.7,0 -6.6,-3 -6.6,-6.6L36.6,71.7c0,-19.4 15.8,-35.2 35.2,-35.2L131,36.5c3.7,0 6.6,3 6.6,6.6s-3,6.6 -6.6,6.6L71.7,49.7c-12.1,0 -21.9,9.8 -21.9,21.9v59.2c0.1,3.8 -2.9,6.8 -6.6,6.8zM130.9,475.4L71.6,475.4c-19.3,0 -35,-15.7 -35,-35v-59.3c0,-3.7 3,-6.6 6.6,-6.6s6.6,3 6.6,6.6v59.3c0,12 9.8,21.8 21.8,21.8h59.3c3.7,0 6.6,3 6.6,6.6 0.1,3.7 -2.9,6.6 -6.6,6.6zM440.5,475.4h-59.4c-3.7,0 -6.6,-3 -6.6,-6.6 0,-3.7 3,-6.6 6.6,-6.6h59.4c11.9,0 21.6,-9.7 21.6,-21.6v-59.4c0,-3.7 3,-6.6 6.6,-6.6 3.7,0 6.6,3 6.6,6.6v59.4c0.1,19.2 -15.5,34.8 -34.8,34.8zM468.8,137.6c-3.7,0 -6.6,-3 -6.6,-6.6L462.2,71.6c0,-12 -9.8,-21.8 -21.8,-21.8h-59.3c-3.7,0 -6.6,-3 -6.6,-6.6s3,-6.6 6.6,-6.6h59.3c19.3,0 35,15.7 35,35v59.3c0,3.7 -2.9,6.7 -6.6,6.7zM130.6,316.2c-9.4,0 -18,-1.9 -25.8,-5.7 -7.8,-3.8 -14.4,-8.8 -20,-15.1 -5.5,-6.2 -9.8,-13.4 -12.9,-21.4 -3,-8.1 -4.6,-16.3 -4.6,-24.8 0,-8.8 1.6,-17.2 4.8,-25.3 3.2,-8.1 7.7,-15.2 13.3,-21.4 5.6,-6.2 12.3,-11.1 20.1,-14.8 7.8,-3.7 16.2,-5.5 25.4,-5.5 9.4,0 18,2 25.8,5.9 7.8,3.9 14.4,9 19.9,15.4 5.5,6.3 9.8,13.5 12.8,21.5s4.6,16.2 4.6,24.5c0,8.8 -1.6,17.2 -4.7,25.3 -3.2,8.1 -7.6,15.2 -13.3,21.3 -5.7,6.1 -12.4,11 -20.2,14.7 -7.7,3.6 -16.1,5.4 -25.2,5.4zM88.6,249.2c0,6.2 1,12.2 3,18.1 2,5.8 4.8,11 8.5,15.4 3.7,4.5 8.1,8 13.3,10.7 5.2,2.7 11,4 17.5,4 6.7,0 12.6,-1.4 17.8,-4.2 5.1,-2.8 9.5,-6.5 13.1,-11.1 3.6,-4.6 6.3,-9.7 8.2,-15.4 1.9,-5.7 2.8,-11.5 2.8,-17.5 0,-6.3 -1,-12.4 -3,-18.1 -2,-5.8 -4.8,-10.9 -8.5,-15.3s-8.1,-7.9 -13.2,-10.6c-5.2,-2.7 -10.9,-4 -17.2,-4 -6.7,0 -12.7,1.4 -17.9,4.2 -5.2,2.8 -9.6,6.4 -13.2,10.9 -3.6,4.5 -6.4,9.6 -8.3,15.4 -2,5.7 -2.9,11.6 -2.9,17.5zM207.3,248.3c0,-7.9 1.4,-15.8 4.3,-23.7 2.9,-7.9 7,-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9 1,-3 1.5,-6.1 1.5,-9.5 0,-3.4 -0.6,-6.5 -1.8,-9.5 -1.2,-3 -2.7,-5.6 -4.7,-7.8 -1.9,-2.2 -4.2,-4 -6.7,-5.3 -2.5,-1.3 -5.2,-2 -7.9,-2h-35.4v49.4z" />
</vector>
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_idpass_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
android:text="@string/label_hex"
android:textColor="@color/newlogic_black"
android:textSize="14sp"
tools:ignore="MissingConstraints"
tools:text="54 65 73 74 20 51 52 20 Test QR\n43 6F 64 65 Code" />
tools:ignore="MissingConstraints" />
</LinearLayout>

<androidx.appcompat.widget.AppCompatEditText
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_pdf417" />

<include
android:id="@+id/item_ocr"
layout="@layout/item_ocr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_mrz" />

<include
android:id="@+id/item_nfc"
layout="@layout/item_nfc"
Expand All @@ -121,7 +132,7 @@
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_mrz" />
app:layout_constraintTop_toBottomOf="@+id/item_ocr" />

<include
android:id="@+id/item_qr"
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/res/layout/activity_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,24 @@
tools:ignore="NestedWeights"
android:visibility="gone"/>

<TextView
android:id="@+id/text_result"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_regular"
android:text="@string/label_hex"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
android:visibility="gone"
tools:ignore="MissingConstraints"
tools:text="54 65 73 74 20 51 52 20 Test QR\n43 6F 64 65 Code" />
android:layout_height="wrap_content">

<TextView
android:id="@+id/text_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_regular"
android:text="@string/label_hex"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
android:visibility="gone"
tools:ignore="MissingConstraints" />

</ScrollView>

</LinearLayout>

<Button
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/res/layout/item_barcode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_barcode"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -24,22 +24,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_barcode"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_barcode" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 7 additions & 8 deletions app/src/main/res/layout/item_idpass_lite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_idpass_lite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -24,22 +24,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_idpass_lite"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_idpass" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
17 changes: 8 additions & 9 deletions app/src/main/res/layout/item_mrz.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:src="@drawable/ic_scan_mrz"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -24,22 +24,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_mrz"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_mrz" />
app:layout_constraintTop_toBottomOf="@id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
19 changes: 9 additions & 10 deletions app/src/main/res/layout/item_nfc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingTop="16dp">
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_height="38dp"
android:layout_marginStart="18dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_scan_nfc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -23,23 +23,22 @@
android:id="@+id/txt_nfc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginStart="18dp"
android:fontFamily="@font/sourcesanspro_medium"
android:text="@string/mode_nfc"
android:textColor="@color/newlogic_black"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginTop="10dp"
android:background="@color/transparent_dark_grey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_nfc" />
app:layout_constraintTop_toBottomOf="@+id/icon" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 227d969

Please sign in to comment.