Skip to content

Commit 082371f

Browse files
committed
Initial commit
0 parents  commit 082371f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2312
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

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

.idea/caches/build_file_checksums.ser

543 Bytes
Binary file not shown.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Text Detection Using MLKit

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 28
5+
defaultConfig {
6+
applicationId "com.ajeetkumar.textdetectionusingmlkit"
7+
minSdkVersion 21
8+
targetSdkVersion 22
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
24+
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25+
26+
// ML Kit dependencies
27+
implementation 'com.google.firebase:firebase-core:16.0.3'
28+
implementation 'com.google.firebase:firebase-ml-vision:17.0.0'
29+
30+
testImplementation 'junit:junit:4.12'
31+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
32+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
33+
}
34+
35+
apply plugin: 'com.google.gms.google-services'

app/proguard-rules.pro

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.ajeetkumar.textdetectionusingmlkit;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.ajeetkumar.textdetectionusingmlkit", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.ajeetkumar.textdetectionusingmlkit">
4+
5+
<uses-permission android:name="android.permission.CAMERA" />
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
8+
9+
<uses-feature android:name="android.hardware.camera" />
10+
<uses-feature android:name="android.hardware.camera.autofocus" />
11+
12+
<application
13+
android:allowBackup="true"
14+
android:icon="@mipmap/ic_launcher"
15+
android:label="@string/app_name"
16+
android:roundIcon="@mipmap/ic_launcher_round"
17+
android:supportsRtl="true"
18+
android:theme="@style/AppTheme">
19+
20+
<meta-data
21+
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
22+
android:value="ocr" />
23+
24+
<activity android:name=".MainActivity"
25+
android:screenOrientation="portrait">
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN" />
28+
29+
<category android:name="android.intent.category.LAUNCHER" />
30+
</intent-filter>
31+
</activity>
32+
</application>
33+
34+
</manifest>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.ajeetkumar.textdetectionusingmlkit;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
import android.util.Log;
6+
7+
import com.ajeetkumar.textdetectionusingmlkit.camera.CameraSource;
8+
import com.ajeetkumar.textdetectionusingmlkit.camera.CameraSourcePreview;
9+
import com.ajeetkumar.textdetectionusingmlkit.others.GraphicOverlay;
10+
import com.ajeetkumar.textdetectionusingmlkit.text_detection.TextRecognitionProcessor;
11+
import com.google.firebase.FirebaseApp;
12+
13+
import java.io.IOException;
14+
15+
public class MainActivity extends AppCompatActivity {
16+
17+
//region ----- Instance Variables -----
18+
19+
private CameraSource cameraSource = null;
20+
private CameraSourcePreview preview;
21+
private GraphicOverlay graphicOverlay;
22+
23+
private static String TAG = MainActivity.class.getSimpleName().toString().trim();
24+
25+
//endregion
26+
27+
@Override
28+
protected void onCreate(Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_main);
31+
32+
//FirebaseApp.initializeApp(this);
33+
34+
preview = (CameraSourcePreview) findViewById(R.id.camera_source_preview);
35+
if (preview == null) {
36+
Log.d(TAG, "Preview is null");
37+
}
38+
graphicOverlay = (GraphicOverlay) findViewById(R.id.graphics_overlay);
39+
if (graphicOverlay == null) {
40+
Log.d(TAG, "graphicOverlay is null");
41+
}
42+
43+
createCameraSource();
44+
startCameraSource();
45+
}
46+
47+
@Override
48+
public void onResume() {
49+
super.onResume();
50+
Log.d(TAG, "onResume");
51+
startCameraSource();
52+
}
53+
54+
/** Stops the camera. */
55+
@Override
56+
protected void onPause() {
57+
super.onPause();
58+
preview.stop();
59+
}
60+
61+
@Override
62+
public void onDestroy() {
63+
super.onDestroy();
64+
if (cameraSource != null) {
65+
cameraSource.release();
66+
}
67+
}
68+
69+
private void createCameraSource() {
70+
71+
if (cameraSource == null) {
72+
cameraSource = new CameraSource(this, graphicOverlay);
73+
cameraSource.setFacing(CameraSource.CAMERA_FACING_BACK);
74+
}
75+
76+
cameraSource.setMachineLearningFrameProcessor(new TextRecognitionProcessor());
77+
}
78+
79+
private void startCameraSource() {
80+
if (cameraSource != null) {
81+
try {
82+
if (preview == null) {
83+
Log.d(TAG, "resume: Preview is null");
84+
}
85+
if (graphicOverlay == null) {
86+
Log.d(TAG, "resume: graphOverlay is null");
87+
}
88+
preview.start(cameraSource, graphicOverlay);
89+
} catch (IOException e) {
90+
Log.e(TAG, "Unable to start camera source.", e);
91+
cameraSource.release();
92+
cameraSource = null;
93+
}
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)