-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carlos Sotelo
committed
Jul 22, 2016
1 parent
cd212a9
commit 695b636
Showing
11 changed files
with
619 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,17 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.1.0' | ||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} |
This file contains 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,25 @@ | ||
## Project-wide Gradle settings. | ||
# | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
# | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true | ||
#Fri Jul 22 18:38:34 BST 2016 | ||
systemProp.http.proxyPort=8080 | ||
systemProp.http.proxyUser=csotelo | ||
systemProp.http.proxyPassword=User\#\#345\#\# | ||
systemProp.https.proxyPassword=User\#\#345\#\# | ||
systemProp.https.proxyHost=10.164.212.25 | ||
systemProp.http.nonProxyHosts=svn.bancocetelem.local,localhost,127.0.0.1 | ||
systemProp.http.proxyHost=10.164.212.25 | ||
systemProp.https.proxyPort=8080 | ||
systemProp.https.nonProxyHosts=svn.bancocetelem.local,localhost,127.0.0.1 | ||
systemProp.https.proxyUser=csotelo |
This file contains 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,29 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
|
||
android { | ||
compileSdkVersion 22 | ||
buildToolsVersion "22.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
lintOptions { | ||
abortOnError false | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:22.0.0' | ||
compile 'com.rmtheis:tess-two:6.0.2' | ||
} |
This file contains 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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /home/priyankvex/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
ohcrapi/src/androidTest/java/com/csot/ohcrapi/ApplicationTest.java
This file contains 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,13 @@ | ||
package com.csot.ohcrapi; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains 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,103 @@ | ||
package com.csot.ohcrapi; | ||
|
||
import android.content.Context; | ||
import android.content.res.AssetManager; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
|
||
import com.googlecode.tesseract.android.TessBaseAPI; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Random; | ||
|
||
/** | ||
* Description Created on 19-07-2016. | ||
* | ||
* @author <a href="mailto:[email protected]">csotelo</a> | ||
* @version $Revision : 1 $ | ||
*/ | ||
public class OhCRapi { | ||
final static String TAG = "OCR"; | ||
final static Random random = new Random(); | ||
final static String url = "https://api.ocr.space/parse/image"; // OCR API Endpoints | ||
final static String url2 = "https://apifree2.ocr.space/parse/image"; // OCR API Endpoints | ||
static OhCRapi mInstance; | ||
static TessBaseAPI mLocalOcrEngine; | ||
String trainedDataLanguage = "eng"; | ||
String apiKey; | ||
|
||
private OhCRapi(String trainedDataLanguage, String apiKey) { | ||
this.trainedDataLanguage = trainedDataLanguage; | ||
this.apiKey = apiKey; | ||
} | ||
|
||
public static void initRemote(String trainedDataLanguage, String apiKey) { | ||
mInstance = new OhCRapi(trainedDataLanguage, apiKey); | ||
} | ||
|
||
//ProgressNotifier | ||
public static void initLocal(Context ctx, String tessDirectoryPath, String trainedDataLanguage, TessBaseAPI.ProgressNotifier progressNotifier) { | ||
if (mLocalOcrEngine == null) { | ||
mLocalOcrEngine = touchTesseract(ctx, tessDirectoryPath, trainedDataLanguage, progressNotifier); | ||
} | ||
} | ||
|
||
public static String getApiKey() { | ||
return mInstance.apiKey; | ||
} | ||
|
||
public static String getTrainedDataLanguage() { | ||
return mInstance.trainedDataLanguage; | ||
} | ||
|
||
public static String getOcrUrl() { | ||
int num = random.nextInt(2); | ||
return (num == 1) ? url : url2; | ||
} | ||
|
||
@NonNull | ||
static TessBaseAPI touchTesseract(@NonNull Context ctx, @NonNull String tessDirectoryPath, @NonNull String trainedDataLanguage, @Nullable TessBaseAPI.ProgressNotifier progressNotifier) { | ||
File tessDir = new File(tessDirectoryPath + File.separator + "tessdata"); | ||
tessDir.mkdir(); | ||
File tessData = new File(tessDir.getAbsolutePath() + File.separator + trainedDataLanguage + ".traineddata"); | ||
if (!tessData.exists()) { | ||
try { | ||
AssetManager assetManager = ctx.getAssets(); | ||
InputStream in = assetManager.open("tessdata/" + trainedDataLanguage + ".traineddata"); | ||
//GZIPInputStream gin = new GZIPInputStream(in); | ||
// Output stream with the location where we have to write the eng.traineddata file. | ||
OutputStream out = new FileOutputStream(tessData); | ||
|
||
// Transfer bytes from in to out | ||
byte[] buf = new byte[1024]; | ||
int len; | ||
//while ((lenf = gin.read(buff)) > 0) { | ||
while ((len = in.read(buf)) > 0) { | ||
out.write(buf, 0, len); | ||
} | ||
in.close(); | ||
//gin.close(); | ||
out.close(); | ||
// mInstance.trainedDataLanguage = trainedDataLanguage; | ||
Log.v(OhCRapi.TAG, "Copied " + tessData.getAbsolutePath()); | ||
} catch (IOException e) { | ||
Log.e(OhCRapi.TAG, "Was unable to copy " + tessData.getAbsolutePath() + " : " + e.toString()); | ||
} | ||
} else { | ||
Log.d(OhCRapi.TAG, "TessData already present"); | ||
} | ||
TessBaseAPI tess; | ||
if (progressNotifier != null) { | ||
tess = new TessBaseAPI(progressNotifier); | ||
} else { | ||
tess = new TessBaseAPI(); | ||
} | ||
tess.init(tessDirectoryPath, trainedDataLanguage); | ||
return tess; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ohcrapi/src/main/java/com/csot/ohcrapi/OhCRapiListener.java
This file contains 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,16 @@ | ||
package com.csot.ohcrapi; | ||
|
||
/** | ||
* Description Created on 19-07-2016. | ||
* | ||
* @author <a href="mailto:[email protected]">csotelo</a> | ||
* @version $Revision : 1 $ | ||
*/ | ||
public interface OhCRapiListener { | ||
|
||
void onOhCRapiStarted(); | ||
|
||
// void onOhCRapiFinished(Bitmap bitmap, String recognizedText); | ||
|
||
void onOhCRapiFinished(String recognizedText); | ||
} |
Oops, something went wrong.