Skip to content

Commit

Permalink
Ready to implement
Browse files Browse the repository at this point in the history
  • Loading branch information
Bcepnez committed Jun 15, 2018
1 parent d0e9db2 commit db74596
Show file tree
Hide file tree
Showing 110 changed files with 186 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .idea/libraries/android_android_22.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/libraries/tess_two_9_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<orderEntry type="library" scope="TEST" name="runner-1.0.2" level="project" />
<orderEntry type="library" scope="TEST" name="jsr305-2.0.1" level="project" />
<orderEntry type="library" name="support-compat-26.1.0" level="project" />
<orderEntry type="library" name="tess-two-9.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="javax.inject-1" level="project" />
<orderEntry type="library" name="support-annotations-26.1.0" level="project" />
<orderEntry type="library" name="support-v4-26.1.0" level="project" />
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies {

testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-vision:10.0.0+'
compile 'com.rmtheis:tess-two:9.0.0'
}
Binary file added app/src/main/assets/eng.traineddata
Binary file not shown.
Binary file added app/src/main/assets/jpn.traineddata
Binary file not shown.
Binary file added app/src/main/assets/tha.traineddata
Binary file not shown.
13 changes: 8 additions & 5 deletions app/src/main/java/com/bcepnez/gvreader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ else if (item.getItemId() == R.id.btn_gallery){
private void openGallery() {
GalIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
// startActivityForResult(Intent.createChooser(GalIntent,"Select Image from gallery"),2);
crop = false;
startActivityForResult(GalIntent,RESULT_LOAD_IMAGE);
}

Expand All @@ -113,11 +111,11 @@ private void RequestRuntimePermission() {
int chk =0;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK){
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK && !crop ){
if (!crop){ CropImage(); }
if (crop){ OCR(); }
}
else if (requestCode == RESULT_LOAD_IMAGE && !crop && resultCode == Activity.RESULT_OK) {
else if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && !crop ) {
if(data!= null && data.getData()!=null){
uri = data.getData();
try {
Expand All @@ -140,6 +138,9 @@ else if (requestCode == CROP && resultCode == RESULT_OK && !crop){
e.printStackTrace();
}
crop = true;
// OcrManager manager = new OcrManager();
// String str = manager.startRecognizer(bitmap);
// Toast.makeText(this,"*|*"+str+"*|*",Toast.LENGTH_SHORT).show();
OCR();
}
}
Expand Down Expand Up @@ -175,6 +176,7 @@ private void OCR() {
}
}


TextView textView = (TextView) findViewById(R.id.text1);
Frame imageFrame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame);
Expand All @@ -195,6 +197,7 @@ private void OCR() {
else textView.setText("No data");
}
crop = false;
textRecognizer.release();
}

}
Expand All @@ -209,7 +212,7 @@ private void CropImage() {
CropIntent.putExtra("scaleUpIfNeeded",true);
CropIntent.putExtra("scaleDownIfNeeded",true);
CropIntent.putExtra("data",true);
crop=true;
crop = true;
Toast.makeText(this,"****"+chk+"****",Toast.LENGTH_SHORT).show();
startActivityForResult(CropIntent,CROP);
}
Expand Down
77 changes: 77 additions & 0 deletions app/src/main/java/com/bcepnez/gvreader/MainApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.bcepnez.gvreader;

import android.app.Application;
import android.content.res.AssetManager;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
* Created by BenzRST on 15-Jun-18.
*/

public class MainApplication extends Application {

public static MainApplication instance = null;
String type = "eng.traineddata";
@Override
public void onCreate() {
super.onCreate();
//start copy file here
instance = this;
copyTessDataForTextRecognizer();
}
private String tessDataPath(){
return MainApplication.instance.getExternalFilesDir(null)+ "/tessdata";
}
public String getTessDataParentDirectory(){
return MainApplication.instance.getExternalFilesDir(null).getAbsolutePath();
}


private void copyTessDataForTextRecognizer(){
Runnable run = new Runnable() {
@Override
public void run() {
AssetManager assetManager = MainApplication.instance.getAssets();
OutputStream outputStream = null;
try {
Log.d("MainApplication", "CopyTessDataForTextRecognizer");
InputStream in = assetManager.open(type);
String tesspath = instance.tessDataPath();
File tessFolder = new File(tesspath);
if (!tessFolder.exists()) {
tessFolder.mkdir();
}
String tessData = tesspath + "/" + type;
File file = new File(tessData);
if (!file.exists()) {
outputStream = new FileOutputStream(tessData);
byte[] buffer = new byte[1024];
int read = in.read(buffer);
while (read != -1) {
outputStream.write(buffer, 0, read);
read = in.read(buffer);
}
Log.d("MainApplication", "***Did finish copy tess file***");
} else
Log.d("MainApplication", "***tess file exist***");
} catch (Exception e){
Log.d("MainApplication", "***couldn't finish copy \n Error : "+e.toString());
}finally {
try {
if (outputStream!=null){
outputStream.close();
}
}catch (Exception exx){

}
}
}
};
new Thread(run).start();
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/com/bcepnez/gvreader/OcrManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bcepnez.gvreader;
import android.graphics.Bitmap;

import com.googlecode.tesseract.android.TessBaseAPI;

/**
* Created by BenzRST on 15-Jun-18.
*/

public class OcrManager {
TessBaseAPI baseAPI = null;
public void initAPI(){
baseAPI = new TessBaseAPI();

String dataPath = MainApplication.instance.getTessDataParentDirectory();
baseAPI.init(dataPath,"eng");
// first param = datapath to trained data,
// second = language code

}
public String startRecognizer(Bitmap bitmap){
if(baseAPI == null){
initAPI();
}
baseAPI.setImage(bitmap);
return baseAPI.getUTF8Text();
}
}
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-13-23-910.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-13-39-810.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-14-09-976.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-18-34-964.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-21-33-944.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-24-41-549.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-11-35-03-286.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-19-41-437.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-19-59-307.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-34-52-988.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-40-30-660.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-41-47-767.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-41-53-608.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-42-10-885.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-42-21-156.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-42-25-628.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-42-28-434.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-42-42-328.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-44-30-875.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-44-35-501.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-44-50-129.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-46-46-699.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-14-17-48-03-168.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-08-25-227.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-08-43-280.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-31-08-072.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-39-55-414.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-39-59-908.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-44-03-346.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-52-07-382.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-52-10-616.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-09-59-36-342.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-01-10-605.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-01-44-240.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-03-12-755.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-24-49-842.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-27-16-040.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-27-24-707.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-52-23-538.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-10-52-58-136.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-05-22-565.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-05-32-689.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-07-07-327.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-07-19-280.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-08-44-417.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-12-35-366.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-15-01-426.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-15-25-33-052.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-17-33-07-492.json

Large diffs are not rendered by default.

Binary file not shown.
1 change: 1 addition & 0 deletions build/android-profile/profile-2018-06-15-17-33-22-118.json

Large diffs are not rendered by default.

Binary file not shown.

0 comments on commit db74596

Please sign in to comment.