├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── skyhope │ │ └── textrecognizer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── skyhope │ │ │ └── textrecognizer │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── file_paths.xml │ └── test │ └── java │ └── com │ └── skyhope │ └── textrecognizer │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot.png ├── settings.gradle └── textrecognizerlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── skyhope │ └── textrecognizerlibrary │ └── ExampleInstrumentedTest.java ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── skyhope │ │ └── textrecognizerlibrary │ │ ├── TextScanner.java │ │ └── callback │ │ └── TextExtractCallback.java └── res │ └── values │ └── strings.xml └── test └── java └── com └── skyhope └── textrecognizerlibrary └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TextRecognizer 2 | This library extend [google vision](https://developers.google.com/vision/) . And initilay it read text from image. 3 | for reading text from image you have to give image **Uri** or **Bitmap**. 4 | 5 | Sample 6 | ![Alt Text](https://github.com/mahimrocky/TextRecognizer/blob/master/screenshot.png) 7 | # Setup 8 | Setup part is simple 9 | 10 | # Root Gradle 11 | ```sh 12 | allprojects { 13 | repositories { 14 | ... 15 | maven { url 'https://jitpack.io' } 16 | } 17 | } 18 | ``` 19 | 20 | # App Gradle: 21 | 22 | ```sh 23 | dependencies { 24 | implementation 'com.github.mahimrocky:TextRecognizer:1.0.0' 25 | } 26 | ``` 27 | 28 | # Api 29 | ```sh 30 | TextScanner.getInstance(this) 31 | .init() 32 | .load(uri) // uri or bitmap 33 | .getCallback(new TextExtractCallback() { 34 | @Override 35 | public void onGetExtractText(List textList) { 36 | // Here you will get list of text 37 | 38 | } 39 | }); 40 | ``` 41 | Happy coding 42 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.skyhope.textrecognizer" 7 | minSdkVersion 15 8 | targetSdkVersion 28 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(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | implementation 'com.karumi:dexter:5.0.0' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 29 | implementation project(':textrecognizerlibrary') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 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 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/skyhope/textrecognizer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.skyhope.textrecognizer; 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 Testing documentation 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.skyhope.textrecognizer", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/skyhope/textrecognizer/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.skyhope.textrecognizer; 2 | 3 | import android.Manifest; 4 | import android.annotation.SuppressLint; 5 | import android.content.Intent; 6 | import android.content.pm.ActivityInfo; 7 | import android.graphics.Bitmap; 8 | import android.net.Uri; 9 | import android.os.Build; 10 | import android.os.Environment; 11 | import android.provider.MediaStore; 12 | import android.support.annotation.Nullable; 13 | import android.support.v4.content.FileProvider; 14 | import android.support.v7.app.AppCompatActivity; 15 | import android.os.Bundle; 16 | import android.view.View; 17 | import android.widget.Button; 18 | import android.widget.ImageView; 19 | import android.widget.TextView; 20 | 21 | import com.karumi.dexter.Dexter; 22 | import com.karumi.dexter.PermissionToken; 23 | import com.karumi.dexter.listener.PermissionDeniedResponse; 24 | import com.karumi.dexter.listener.PermissionGrantedResponse; 25 | import com.karumi.dexter.listener.PermissionRequest; 26 | import com.karumi.dexter.listener.single.PermissionListener; 27 | import com.skyhope.textrecognizerlibrary.TextScanner; 28 | import com.skyhope.textrecognizerlibrary.callback.TextExtractCallback; 29 | 30 | import java.io.File; 31 | import java.io.IOException; 32 | import java.text.SimpleDateFormat; 33 | import java.util.Date; 34 | import java.util.List; 35 | 36 | public class MainActivity extends AppCompatActivity { 37 | 38 | Button buttonGallery, buttonCamera; 39 | TextView recognizeText; 40 | ImageView captureImage; 41 | 42 | public static final int REQUEST_FOR_IMAGE_FROM_GALLERY = 101; 43 | public static final int REQUEST_FOR_IMAGE_FROM_CAMERA = 102; 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_main); 49 | 50 | buttonGallery = findViewById(R.id.button_gallery); 51 | buttonCamera = findViewById(R.id.button_camera); 52 | recognizeText = findViewById(R.id.text); 53 | captureImage = findViewById(R.id.imageView); 54 | 55 | 56 | buttonGallery.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | openGallery(); 60 | } 61 | }); 62 | 63 | buttonCamera.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View view) { 66 | Dexter.withActivity(MainActivity.this).withPermission(Manifest.permission.CAMERA).withListener(new PermissionListener() { 67 | @Override 68 | public void onPermissionGranted(PermissionGrantedResponse response) { 69 | openCamera(); 70 | } 71 | 72 | @Override 73 | public void onPermissionDenied(PermissionDeniedResponse response) { 74 | 75 | } 76 | 77 | @Override 78 | public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { 79 | 80 | } 81 | }).check(); 82 | 83 | } 84 | }); 85 | 86 | } 87 | 88 | 89 | @Override 90 | protected void onActivityResult(final int requestCode, int resultCode, @Nullable Intent data) { 91 | super.onActivityResult(requestCode, resultCode, data); 92 | 93 | final Uri uri = data.getData(); 94 | try { 95 | Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); 96 | captureImage.setImageBitmap(bitmap); 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | } 100 | TextScanner.getInstance(this) 101 | .init() 102 | .load(uri) 103 | .getCallback(new TextExtractCallback() { 104 | @Override 105 | public void onGetExtractText(List textList) { 106 | // Here ypu will get list of text 107 | 108 | final StringBuilder text = new StringBuilder(); 109 | for (String s : textList) { 110 | text.append(s).append("\n"); 111 | } 112 | recognizeText.post(new Runnable() { 113 | @Override 114 | public void run() { 115 | recognizeText.setText(text.toString()); 116 | } 117 | }); 118 | 119 | } 120 | }); 121 | } 122 | 123 | /** 124 | * Method for Open device default Camera and take snap 125 | */ 126 | private void openCamera() { 127 | Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 128 | File imageFile = null; 129 | if (cameraIntent.resolveActivity(getPackageManager()) != null) { 130 | try { 131 | imageFile = createImageFile(); 132 | } catch (Exception e) { 133 | e.printStackTrace(); 134 | } 135 | if (imageFile != null) { 136 | Uri mImageFileUri; 137 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { 138 | mImageFileUri = FileProvider.getUriForFile(this, 139 | getResources().getString(R.string.file_provider_authority), 140 | imageFile); 141 | } else { 142 | mImageFileUri = Uri.parse("file:" + imageFile.getAbsolutePath()); 143 | } 144 | cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageFileUri); 145 | cameraIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 146 | 147 | 148 | startActivityForResult(cameraIntent, REQUEST_FOR_IMAGE_FROM_CAMERA); 149 | } 150 | } 151 | } 152 | 153 | /** 154 | * Method for Open default device gallery 155 | */ 156 | private void openGallery() { 157 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 158 | photoPickerIntent.setType("image/*"); 159 | startActivityForResult(photoPickerIntent, REQUEST_FOR_IMAGE_FROM_GALLERY); 160 | } 161 | 162 | /** 163 | * Create a file for save photo from camera 164 | * 165 | * @return File 166 | * @throws IOException Input output error 167 | */ 168 | private File createImageFile() throws IOException { 169 | @SuppressLint("SimpleDateFormat") 170 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 171 | String imageFileName = "IMG_" + timeStamp; 172 | File storageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 173 | try { 174 | storageDirectory.mkdirs(); 175 | } catch (Exception e) { 176 | e.printStackTrace(); 177 | } 178 | return File.createTempFile(imageFileName, ".jpg", storageDirectory); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 31 | 32 |