Skip to content

Commit 2fe7b28

Browse files
committed
Add Free-Form OCR Sample App
1 parent b2c72bd commit 2fe7b28

37 files changed

+1462
-0
lines changed

FreeFormOCRSample1/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

FreeFormOCRSample1/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.zebra.freeformocrsample1'
7+
compileSdk 33
8+
9+
defaultConfig {
10+
applicationId "com.zebra.freeformocrsample1"
11+
minSdk 30
12+
targetSdk 33
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.9.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
36+
testImplementation 'junit:junit:4.13.2'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.zebra.freeformocrsample1;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.zebra.freeformocrsample1", appContext.getPackageName());
25+
}
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="com.symbol.datawedge.permission.contentprovider" />
6+
<queries>
7+
<package android:name="com.symbol.datawedge" />
8+
</queries>
9+
10+
11+
<application
12+
android:allowBackup="true"
13+
android:dataExtractionRules="@xml/data_extraction_rules"
14+
android:fullBackupContent="@xml/backup_rules"
15+
android:icon="@mipmap/ic_launcher"
16+
android:label="@string/app_name"
17+
android:roundIcon="@mipmap/ic_launcher_round"
18+
android:supportsRtl="true"
19+
android:theme="@style/Theme.FreeFormOCRSample1"
20+
tools:targetApi="31">
21+
<activity
22+
android:name=".MainActivity"
23+
android:exported="true">
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN" />
26+
27+
<category android:name="android.intent.category.LAUNCHER" />
28+
</intent-filter>
29+
30+
<meta-data
31+
android:name="android.app.lib_name"
32+
android:value="" />
33+
</activity>
34+
</application>
35+
36+
</manifest>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2018-2023 Zebra Technologies Corp
3+
* All rights reserved.
4+
*/
5+
package com.zebra.freeformocrsample1;
6+
7+
import android.graphics.Bitmap;
8+
import android.graphics.BitmapFactory;
9+
import android.graphics.ImageFormat;
10+
import android.graphics.Matrix;
11+
import android.graphics.Rect;
12+
import android.graphics.YuvImage;
13+
14+
import java.io.ByteArrayOutputStream;
15+
16+
public class ImageProcessing {
17+
18+
private final String IMG_FORMAT_YUV = "YUV";
19+
private final String IMG_FORMAT_Y8 = "Y8";
20+
21+
private static ImageProcessing instance = null;
22+
23+
public static ImageProcessing getInstance() {
24+
25+
if (instance == null) {
26+
instance = new ImageProcessing();
27+
}
28+
return instance;
29+
}
30+
31+
private ImageProcessing() {
32+
//Private Constructor
33+
}
34+
35+
public Bitmap getBitmap(byte[] data, String imageFormat, int orientation, int stride, int width, int height)
36+
{
37+
if(imageFormat.equalsIgnoreCase(IMG_FORMAT_YUV))
38+
{
39+
ByteArrayOutputStream out = new ByteArrayOutputStream();
40+
YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, new int[]{stride, stride});
41+
yuvImage.compressToJpeg(new Rect(0, 0, stride, height), 100, out);
42+
yuvImage.getYuvData();
43+
byte[] imageBytes = out.toByteArray();
44+
if(orientation != 0)
45+
{
46+
Matrix matrix = new Matrix();
47+
matrix.postRotate(orientation);
48+
Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
49+
return Bitmap.createBitmap(bitmap, 0 , 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
50+
}
51+
else
52+
{
53+
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
54+
}
55+
}
56+
else if(imageFormat.equalsIgnoreCase(IMG_FORMAT_Y8))
57+
{
58+
return convertYtoJPG_CPU(data, orientation, stride, height);
59+
}
60+
61+
return null;
62+
}
63+
64+
65+
private Bitmap convertYtoJPG_CPU(byte[] data, int orientation, int stride, int height)
66+
{
67+
int mLength = data.length;
68+
int [] pixels = new int[mLength];
69+
for(int i = 0; i < mLength; i++)
70+
{
71+
int p = data[i] & 0xFF;
72+
pixels[i] = 0xff000000 | p << 16 | p << 8 | p;
73+
}
74+
if(orientation != 0)
75+
{
76+
Matrix matrix = new Matrix();
77+
matrix.postRotate(orientation);
78+
Bitmap bitmap = Bitmap.createBitmap(pixels, stride, height, Bitmap.Config.ARGB_8888);
79+
return Bitmap.createBitmap(bitmap, 0 , 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
80+
}
81+
else
82+
{
83+
return Bitmap.createBitmap(pixels, stride, height, Bitmap.Config.ARGB_8888);
84+
}
85+
}
86+
87+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2018-2023 Zebra Technologies Corp
3+
* All rights reserved.
4+
*/
5+
package com.zebra.freeformocrsample1;
6+
7+
public class IntentKeys {
8+
9+
public static final String DATA_NEXT_URI = "next_data_uri";
10+
public static final String STRIDE = "stride";
11+
public static final String RAW_DATA = "raw_data";
12+
public static final String ORIENTATION = "orientation";
13+
public static final String IMAGE_FORMAT = "imageformat";
14+
public static final String IMAGE_WIDTH = "width";
15+
public static final String IMAGE_HEIGHT = "height";
16+
17+
public static final String COMMAND_IDENTIFIER_CREATE_PROFILE = "CREATE_PROFILE";
18+
public static final String COMMAND_IDENTIFIER_EXTRA = "COMMAND_IDENTIFIER";
19+
public static final String RESULT_ACTION = "com.symbol.datawedge.api.RESULT_ACTION";
20+
21+
public static final String DATA_TAG = "com.symbol.datawedge.data";
22+
23+
public static final String REGISTER_NOTIFICATION = "com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION";
24+
public static final String UNREGISTER_NOTIFICATION = "com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION";
25+
26+
public static final String STRING_DATA_KEY = "string_data";
27+
public static final String DATAWEDGE_API_NAME = "com.symbol.datawedge.api.APPLICATION_NAME";
28+
public static final String NOTIFICATION_TYPE = "com.symbol.datawedge.api.NOTIFICATION_TYPE";
29+
public static final String NOTIFICATION = "com.symbol.datawedge.api.NOTIFICATION";
30+
31+
32+
public static final String EXTRA_GET_PROFILES_LIST = "com.symbol.datawedge.api.GET_PROFILES_LIST";
33+
public static final String EXTRA_DELETE_PROFILE = "com.symbol.datawedge.api.DELETE_PROFILE";
34+
35+
public static final String SET_CONFIG = "com.symbol.datawedge.api.SET_CONFIG";
36+
37+
public static final String PROFILE_NAME = "FreeFormScanningProfile";
38+
public static final String DATAWEDGE_API_ACTION = "com.symbol.datawedge.api.ACTION";
39+
public static final String INTENT_OUTPUT_ACTION = "com.zebra.id_scanning.ACTION";
40+
public static final String SELECTED_WORKFLOW = "free_form_ocr";
41+
public static final String NOTIFICATION_ACTION = "com.symbol.datawedge.api.NOTIFICATION_ACTION";
42+
public static final String NOTIFICATION_TYPE_WORKFLOW_STATUS = "WORKFLOW_STATUS";
43+
public static final String KEY_STRING_DATA = "string_data";
44+
public static final String KEY_BLOCK_LABEL = "block_label";
45+
public static final String JSON_IMAGE_FORMAT = "imageformat";
46+
public static final String KEY_GROUP_ID = "group_id";
47+
48+
public static final String EXTRA_RESULT_GET_PROFILES_LIST = "com.symbol.datawedge.api.RESULT_GET_PROFILES_LIST";
49+
public static final String DATAWEDGE_PACKAGE = "com.symbol.datawedge";
50+
51+
public static final String EXTRA_SOFT_SCAN_TRIGGER = "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER";
52+
public static final String INTENT_RESULT_CODE_FAILURE = "FAILURE";
53+
54+
55+
}

0 commit comments

Comments
 (0)