├── .gitignore ├── .idea ├── assetWizardSettings.xml ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── art ├── 1.png ├── 2.png ├── 3.png └── 4.png ├── barcodescanner ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cogitator │ │ └── barcodescanner │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cogitator │ │ │ └── barcodescanner │ │ │ ├── BarCodeReaderActivity.kt │ │ │ └── BaseCameraActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_camera.xml │ │ ├── ic_launcher_background.xml │ │ └── ic_refresh.xml │ │ ├── layout │ │ ├── activity_barcode.xml │ │ └── 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 │ └── test │ └── java │ └── com │ └── cogitator │ └── barcodescanner │ └── ExampleUnitTest.java ├── build.gradle ├── facedetection ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cogitator │ │ └── facedetection │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cogitator │ │ │ └── facedetection │ │ │ └── FaceDetectionActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── button_capture_background.xml │ │ ├── ic_camera_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_mouse_black_24dp.xml │ │ ├── ic_music_note_black_24dp.xml │ │ └── ic_remove_red_eye_black_24dp.xml │ │ ├── layout │ │ └── activity_face_detection.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 │ └── cogitator │ └── facedetection │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── textRecognition ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── cogitator │ └── firebasemlkit │ └── ExampleInstrumentedTest.kt ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── cogitator │ │ └── firebasemlkit │ │ ├── SplashActivity.kt │ │ └── textRecognizer │ │ ├── GraphicOverlay.kt │ │ ├── TextGraphic.kt │ │ └── TextRecognizerActivity.kt └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── firebase_28dp.png │ ├── firebase_logotype.png │ ├── ic_launcher_background.xml │ └── mlkit_fore_.png │ ├── layout │ ├── activity_spalsh.xml │ └── activity_text_recog.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 └── test └── java └── com └── cogitator └── firebasemlkit └── ExampleUnitTest.kt /.gitignore: -------------------------------------------------------------------------------- 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 11 | libs/ 12 | /google-services.json 13 | /facedetection/google-services.json 14 | -------------------------------------------------------------------------------- /.idea/assetWizardSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 45 | 46 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.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 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Firebase MLKit-Android 2 | # Demonstration of Firebase MLkit in android with simple examples and samples 3 | 4 | in your app level `build.gradle`, add the dependencies 5 | 6 | implementation 'com.google.firebase:firebase-core:15.0.2' 7 | implementation 'com.google.firebase:firebase-ml-vision:15.0.0' 8 | 9 | implementation 'com.wonderkiln:camerakit:0.13.1' 10 | 11 | 12 | And here its recogizing text from camera 13 | 14 | 15 | 16 | 17 | 18 | 19 | ## Tutorial for text Recognition can be found 20 | - [here](https://medium.com/@cogitator/working-with-firebase-ml-kit-in-android-app-text-recognition-on-device-7fceb9a0a307) 21 | 22 | ### Would you like to buy me a cup of coffee? 23 | #### I'd appreciate even your little contribution to my work, it helps me keep this Open Source updated. If this project helped you or your business and if you feel like donating some bucks, you can Paypal me - ankitdroiddeveloper@gmail.com 24 | 25 | Buy Me a Coffee at ko-fi.com 26 | 27 | 28 | 29 | ### Contact - Let's connect to learn together 30 | - [Twitter](https://twitter.com/KumarAnkitRKE) 31 | - [Github](https://github.com/AnkitDroidGit) 32 | - [LinkedIn](https://www.linkedin.com/in/kumarankitkumar/) 33 | - [Facebook](https://www.facebook.com/freeankit) 34 | - [Slack](https://ankitdroid.slack.com) 35 | - [Stackoverflow](https://stackoverflow.com/users/3282461/android) 36 | - [Android App](https://play.google.com/store/apps/details?id=com.freeankit.ankitprofile) 37 | 38 | 39 | ### License 40 | 41 | Copyright 2018 Ankit Kumar 42 | 43 | Licensed under the Apache License, Version 2.0 (the "License"); 44 | you may not use this file except in compliance with the License. 45 | You may obtain a copy of the License at 46 | 47 | http://www.apache.org/licenses/LICENSE-2.0 48 | 49 | Unless required by applicable law or agreed to in writing, software 50 | distributed under the License is distributed on an "AS IS" BASIS, 51 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 | See the License for the specific language governing permissions and 53 | limitations under the License. 54 | -------------------------------------------------------------------------------- /art/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/art/1.png -------------------------------------------------------------------------------- /art/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/art/2.png -------------------------------------------------------------------------------- /art/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/art/3.png -------------------------------------------------------------------------------- /art/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/art/4.png -------------------------------------------------------------------------------- /barcodescanner/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /barcodescanner/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion rootProject.ext.compileSdkVersion 7 | buildToolsVersion rootProject.ext.buildToolsVersion 8 | 9 | defaultConfig { 10 | applicationId "com.cogitator.barcodescanner" 11 | minSdkVersion rootProject.ext.minSdkVersion 12 | targetSdkVersion rootProject.ext.targetSdkVersion 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | } 31 | 32 | dependencies { 33 | implementation fileTree(dir: 'libs', include: ['*.jar']) 34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 35 | 36 | implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" 37 | implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion" 38 | implementation "com.android.support:animated-vector-drawable:$rootProject.supportLibraryVersion" 39 | implementation "com.android.support:exifinterface:$rootProject.supportLibraryVersion" 40 | implementation "com.android.support:support-media-compat:$rootProject.supportLibraryVersion" 41 | implementation "com.android.support:design:$rootProject.supportLibraryVersion" 42 | 43 | 44 | implementation "com.google.firebase:firebase-core:$rootProject.firebaseCoreVersion" 45 | implementation "com.google.firebase:firebase-ml-vision:$rootProject.firebaseMLVissionVersion" 46 | 47 | 48 | implementation 'com.wonderkiln:camerakit:0.13.1' 49 | implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar' 50 | implementation 'com.github.jkwiecien:EasyImage:1.3.1' 51 | 52 | testImplementation 'junit:junit:4.12' 53 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 54 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 55 | } 56 | repositories { 57 | mavenCentral() 58 | } 59 | 60 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /barcodescanner/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 | -------------------------------------------------------------------------------- /barcodescanner/src/androidTest/java/com/cogitator/barcodescanner/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.cogitator.barcodescanner; 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.cogitator.barcodescanner", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /barcodescanner/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /barcodescanner/src/main/java/com/cogitator/barcodescanner/BarCodeReaderActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.barcodescanner 2 | 3 | import android.graphics.Bitmap 4 | import android.os.Bundle 5 | import android.support.design.widget.BottomSheetBehavior 6 | import android.view.View 7 | import android.widget.Toast 8 | import com.google.firebase.ml.vision.FirebaseVision 9 | import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode 10 | import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions 11 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 12 | import kotlinx.android.synthetic.main.activity_barcode.* 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | 15 | /** 16 | * @author Ankit Kumar on 09/10/2018 17 | */ 18 | class BarCodeReaderActivity : BaseCameraActivity() { 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setupBottomSheet(R.layout.activity_barcode) 23 | } 24 | 25 | override fun onClick(v: View) { 26 | fabProgressCircle.show() 27 | cameraView.captureImage { cameraKitImage -> 28 | // Get the Bitmap from the captured shot 29 | getQRCodeDetailsFromBitmap(cameraKitImage.bitmap) 30 | runOnUiThread { 31 | showPreview() 32 | imagePreview.setImageBitmap(cameraKitImage.bitmap) 33 | } 34 | } 35 | } 36 | 37 | private fun getQRCodeDetailsFromBitmap(bitmap: Bitmap) { 38 | val options = FirebaseVisionBarcodeDetectorOptions.Builder() 39 | .setBarcodeFormats( 40 | FirebaseVisionBarcode.FORMAT_ALL_FORMATS) 41 | .build() 42 | val detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options) 43 | val image = FirebaseVisionImage.fromBitmap(bitmap) 44 | detector.detectInImage(image) 45 | 46 | 47 | .addOnSuccessListener { 48 | for (firebaseBarcode in it) { 49 | 50 | codeData.text = firebaseBarcode.displayValue //Display contents inside the barcode 51 | 52 | when (firebaseBarcode.valueType) { 53 | //Handle the URL here 54 | FirebaseVisionBarcode.TYPE_URL -> firebaseBarcode.url 55 | // Handle the contact info here, i.e. address, name, phone, etc. 56 | FirebaseVisionBarcode.TYPE_CONTACT_INFO -> firebaseBarcode.contactInfo 57 | // Handle the wifi here, i.e. firebaseBarcode.wifi.ssid, etc. 58 | FirebaseVisionBarcode.TYPE_WIFI -> firebaseBarcode.wifi 59 | //Handle more type of Barcodes 60 | } 61 | 62 | } 63 | } 64 | .addOnFailureListener { 65 | it.printStackTrace() 66 | Toast.makeText(baseContext, "Sorry, something went wrong!", Toast.LENGTH_SHORT).show() 67 | } 68 | .addOnCompleteListener { 69 | fabProgressCircle.hide() 70 | sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED 71 | } 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /barcodescanner/src/main/java/com/cogitator/barcodescanner/BaseCameraActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.barcodescanner 2 | 3 | import android.os.Bundle 4 | import android.support.annotation.LayoutRes 5 | import android.support.design.widget.BottomSheetBehavior 6 | import android.support.design.widget.CoordinatorLayout 7 | import android.support.v7.app.AppCompatActivity 8 | import android.view.Gravity 9 | import android.view.View 10 | import kotlinx.android.synthetic.main.activity_main.* 11 | 12 | /** 13 | * @author Ankit Kumar on 08/10/2018 14 | */ 15 | abstract class BaseCameraActivity : AppCompatActivity(), View.OnClickListener { 16 | 17 | lateinit var sheetBehavior: BottomSheetBehavior<*> 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | setContentView(R.layout.activity_main) 22 | btnRetry.setOnClickListener { 23 | if (cameraView.visibility == View.VISIBLE) showPreview() else hidePreview() 24 | } 25 | fab_take_photo.setOnClickListener(this) 26 | } 27 | 28 | fun setupBottomSheet(@LayoutRes id : Int){ 29 | //Using a ViewStub since changing the layout of an tag dynamically wasn't possible 30 | stubView.layoutResource = id 31 | val inflatedView = stubView.inflate() 32 | //Set layout parameters for the inflated bottomsheet 33 | val lparam = inflatedView.layoutParams as CoordinatorLayout.LayoutParams 34 | lparam.behavior = BottomSheetBehavior() 35 | inflatedView.layoutParams = lparam 36 | sheetBehavior = BottomSheetBehavior.from(inflatedView) 37 | sheetBehavior.peekHeight = 224 38 | //Anchor the FAB to the end of inflated bottom sheet 39 | val lp = fabProgressCircle.layoutParams as CoordinatorLayout.LayoutParams 40 | lp.anchorId = inflatedView.id 41 | lp.anchorGravity = Gravity.END 42 | fabProgressCircle.layoutParams = lp 43 | //Hide the fab as bottomSheet is expanded 44 | sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { 45 | override fun onStateChanged(bottomSheet: View, newState: Int) {} 46 | override fun onSlide(bottomSheet: View, slideOffset: Float) { 47 | fab_take_photo.animate().scaleX(1 - slideOffset).scaleY(1 - slideOffset).setDuration(0).start() 48 | } 49 | }) 50 | } 51 | 52 | override fun onResume() { 53 | super.onResume() 54 | cameraView.start() 55 | } 56 | 57 | override fun onPause() { 58 | cameraView.stop() 59 | super.onPause() 60 | } 61 | 62 | protected fun showPreview() { 63 | framePreview.visibility = View.VISIBLE 64 | cameraView.visibility = View.GONE 65 | } 66 | 67 | private fun hidePreview() { 68 | framePreview.visibility = View.GONE 69 | cameraView.visibility = View.VISIBLE 70 | } 71 | } -------------------------------------------------------------------------------- /barcodescanner/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/drawable/ic_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /barcodescanner/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 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/drawable/ic_refresh.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/layout/activity_barcode.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 17 | 18 | 25 | 26 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 18 | 19 | 24 | 25 | 33 | 34 | 35 | 36 | 42 | 43 | 49 | 50 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/barcodescanner/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /barcodescanner/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Barcode Scanner 3 | 4 | -------------------------------------------------------------------------------- /barcodescanner/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /barcodescanner/src/test/java/com/cogitator/barcodescanner/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.cogitator.barcodescanner; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | 4 | ext { 5 | // Sdk and tools 6 | minSdkVersion = 21 7 | targetSdkVersion = 28 8 | compileSdkVersion = 28 9 | buildToolsVersion = '28.0.3' 10 | 11 | // App dependencies 12 | supportLibraryVersion = '28.0.0' 13 | firebaseCoreVersion = '16.0.4' 14 | firebaseMLVissionVersion = '17.0.1' 15 | firebaseMLVissionVersion = '17.0.1' 16 | firebaseMLVissionImageLabelVersion = '16.2.0' 17 | } 18 | buildscript { 19 | ext.kotlin_version = '1.2.71' 20 | repositories { 21 | google() 22 | jcenter() 23 | } 24 | dependencies { 25 | classpath 'com.android.tools.build:gradle:3.2.1' 26 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 27 | classpath 'com.google.gms:google-services:4.0.0' 28 | 29 | // NOTE: Do not place your application dependencies here; they belong 30 | // in the individual module build.gradle files 31 | } 32 | } 33 | 34 | allprojects { 35 | repositories { 36 | google() 37 | jcenter() 38 | maven { url "https://jitpack.io" } 39 | } 40 | } 41 | 42 | task clean(type: Delete) { 43 | delete rootProject.buildDir 44 | } 45 | -------------------------------------------------------------------------------- /facedetection/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /google-services.json 3 | -------------------------------------------------------------------------------- /facedetection/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion rootProject.ext.compileSdkVersion 7 | buildToolsVersion rootProject.ext.buildToolsVersion 8 | 9 | defaultConfig { 10 | applicationId "com.cogitator.facedetection" 11 | minSdkVersion rootProject.ext.minSdkVersion 12 | targetSdkVersion rootProject.ext.targetSdkVersion 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | 31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 32 | implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" 33 | implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion" 34 | implementation "com.android.support:animated-vector-drawable:$rootProject.supportLibraryVersion" 35 | implementation "com.android.support:exifinterface:$rootProject.supportLibraryVersion" 36 | implementation "com.android.support:support-media-compat:$rootProject.supportLibraryVersion" 37 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 38 | 39 | 40 | implementation "com.google.firebase:firebase-ml-vision:$rootProject.firebaseMLVissionVersion" 41 | implementation "com.google.firebase:firebase-ml-vision-image-label-model:$rootProject.firebaseMLVissionImageLabelVersion" 42 | } 43 | repositories { 44 | mavenCentral() 45 | } 46 | 47 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /facedetection/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "400277749061", 4 | "firebase_url": "https://learning-204b9.firebaseio.com", 5 | "project_id": "learning-204b9", 6 | "storage_bucket": "learning-204b9.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:400277749061:android:b5bda8edb1942b28", 12 | "android_client_info": { 13 | "package_name": "com.cogitator.facedetection" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "400277749061-qich8cfe1llqptq6s9kq4nvcg2ifq0c2.apps.googleusercontent.com", 19 | "client_type": 3 20 | }, 21 | { 22 | "client_id": "400277749061-qich8cfe1llqptq6s9kq4nvcg2ifq0c2.apps.googleusercontent.com", 23 | "client_type": 3 24 | } 25 | ], 26 | "api_key": [ 27 | { 28 | "current_key": "AIzaSyC-viB1ZZkkC8CCBZQ8fpW6FGhC__vE-oc" 29 | } 30 | ], 31 | "services": { 32 | "analytics_service": { 33 | "status": 1 34 | }, 35 | "appinvite_service": { 36 | "status": 1, 37 | "other_platform_oauth_client": [] 38 | }, 39 | "ads_service": { 40 | "status": 2 41 | } 42 | } 43 | }, 44 | { 45 | "client_info": { 46 | "mobilesdk_app_id": "1:400277749061:android:f23d82b1fd9bd334", 47 | "android_client_info": { 48 | "package_name": "com.cogitator.firebasemlkit" 49 | } 50 | }, 51 | "oauth_client": [ 52 | { 53 | "client_id": "400277749061-qich8cfe1llqptq6s9kq4nvcg2ifq0c2.apps.googleusercontent.com", 54 | "client_type": 3 55 | }, 56 | { 57 | "client_id": "400277749061-qich8cfe1llqptq6s9kq4nvcg2ifq0c2.apps.googleusercontent.com", 58 | "client_type": 3 59 | } 60 | ], 61 | "api_key": [ 62 | { 63 | "current_key": "AIzaSyC-viB1ZZkkC8CCBZQ8fpW6FGhC__vE-oc" 64 | } 65 | ], 66 | "services": { 67 | "analytics_service": { 68 | "status": 1 69 | }, 70 | "appinvite_service": { 71 | "status": 1, 72 | "other_platform_oauth_client": [] 73 | }, 74 | "ads_service": { 75 | "status": 2 76 | } 77 | } 78 | } 79 | ], 80 | "configuration_version": "1" 81 | } -------------------------------------------------------------------------------- /facedetection/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 | -------------------------------------------------------------------------------- /facedetection/src/androidTest/java/com/cogitator/facedetection/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.cogitator.facedetection; 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.cogitator.facedetection", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /facedetection/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /facedetection/src/main/java/com/cogitator/facedetection/FaceDetectionActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.facedetection 2 | 3 | import android.annotation.SuppressLint 4 | import android.app.Activity 5 | import android.content.Intent 6 | import android.graphics.Bitmap 7 | import android.graphics.BitmapFactory 8 | import android.graphics.Canvas 9 | import android.os.Bundle 10 | import android.os.Environment 11 | import android.provider.MediaStore 12 | import android.support.v4.content.FileProvider 13 | import android.support.v7.app.AppCompatActivity 14 | import com.google.firebase.FirebaseApp 15 | import com.google.firebase.ml.vision.FirebaseVision 16 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 17 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetectorOptions 18 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceLandmark 19 | import kotlinx.android.synthetic.main.activity_face_detection.* 20 | import java.io.File 21 | import java.io.IOException 22 | import java.text.SimpleDateFormat 23 | import java.util.* 24 | 25 | 26 | /** 27 | * @author Ankit Kumar (ankitdroiddeveloper@gmail.com) on 04/06/2018 (MM/DD/YYYY) 28 | */ 29 | class FaceDetectionActivity : AppCompatActivity() { 30 | 31 | private lateinit var mCurrentPhotoPath: String 32 | private val CAMERA_REQUEST_CODE = 101 33 | 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | setContentView(R.layout.activity_face_detection) 37 | FirebaseApp.initializeApp(this@FaceDetectionActivity) 38 | title = "Face Detection" 39 | 40 | 41 | button_capture_.setOnClickListener({ 42 | val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) 43 | if (takePictureIntent.resolveActivity(packageManager) != null) { 44 | var photoFile: File? = null 45 | try { 46 | photoFile = createImageFile() 47 | } catch (ex: IOException) { 48 | } 49 | if (photoFile != null) { 50 | val photoURI = FileProvider.getUriForFile(this@FaceDetectionActivity, 51 | "com.cogitator.facedetection.fileprovider", 52 | photoFile) 53 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) 54 | startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE) 55 | } 56 | } 57 | }) 58 | } 59 | 60 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 61 | super.onActivityResult(requestCode, resultCode, data) 62 | if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK) { 63 | val imageFile = File(mCurrentPhotoPath) 64 | val photo = BitmapFactory.decodeFile(imageFile.absolutePath) 65 | addEmojis(photo) 66 | } 67 | } 68 | 69 | @SuppressLint("SimpleDateFormat") 70 | private fun createImageFile(): File { 71 | // Create an image file name 72 | val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date()) 73 | val imageFileName = "JPEG_" + timeStamp + "_" 74 | val storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES) 75 | val image = File.createTempFile( 76 | imageFileName, /* prefix */ 77 | ".jpg", /* suffix */ 78 | storageDir /* directory */ 79 | ) 80 | 81 | // Save a file: path for use with ACTION_VIEW intents 82 | mCurrentPhotoPath = image.absolutePath 83 | return image 84 | } 85 | 86 | private fun addEmojis(photo: Bitmap) { 87 | 88 | val emojiPhoto = photo.copy(Bitmap.Config.ARGB_8888, true) 89 | val canvas = Canvas(emojiPhoto) 90 | 91 | val options = FirebaseVisionFaceDetectorOptions.Builder() 92 | .setModeType(FirebaseVisionFaceDetectorOptions.ACCURATE_MODE) 93 | .setLandmarkType(FirebaseVisionFaceDetectorOptions.ALL_LANDMARKS) 94 | .setClassificationType(FirebaseVisionFaceDetectorOptions.ALL_CLASSIFICATIONS) 95 | .setMinFaceSize(0.1f) 96 | .setTrackingEnabled(false) 97 | .build() 98 | val image = FirebaseVisionImage.fromBitmap(photo) 99 | val detector = FirebaseVision.getInstance() 100 | .getVisionFaceDetector(options) 101 | 102 | detector.detectInImage(image).addOnSuccessListener { 103 | 104 | // Task completed successfully 105 | for (face in it) { 106 | 107 | val leftEye = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_EYE) 108 | val rightEye = face.getLandmark(FirebaseVisionFaceLandmark.RIGHT_EYE) 109 | val nose = face.getLandmark(FirebaseVisionFaceLandmark.NOSE_BASE) 110 | val mouth = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_MOUTH) 111 | 112 | if (leftEye != null) { 113 | val leftEyePosition = leftEye.position 114 | var bitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_remove_red_eye_black_24dp) 115 | val width = bitmap.width * 3 116 | val height = bitmap.height * 3 117 | bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false) 118 | canvas.drawBitmap(bitmap, leftEyePosition.x - width / 2, leftEyePosition.y - height / 2, null) 119 | } 120 | 121 | if (rightEye != null) { 122 | val rightEyePosition = rightEye.position 123 | var bitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_remove_red_eye_black_24dp) 124 | val width = bitmap.width * 3 125 | val height = bitmap.height * 3 126 | bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false) 127 | canvas.drawBitmap(bitmap, rightEyePosition.x - width / 2, rightEyePosition.y - height / 2, null) 128 | } 129 | 130 | if (nose != null) { 131 | val nosePosition = nose.position 132 | var bitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_music_note_black_24dp) 133 | val width = bitmap.width * 3 134 | val height = bitmap.height * 3 135 | bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false) 136 | canvas.drawBitmap(bitmap, nosePosition.x - width / 2, nosePosition.y - height, null) 137 | } 138 | 139 | if (mouth != null) { 140 | val mouthPosition = mouth.position 141 | var bitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_mouse_black_24dp) 142 | val width = bitmap.width * 4 143 | val height = bitmap.height * 4 144 | bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false) 145 | canvas.drawBitmap(bitmap, mouthPosition.x - width, mouthPosition.y - height / 2, null) 146 | } 147 | } 148 | canvas.save() 149 | image_view_.setImageBitmap(emojiPhoto) 150 | 151 | } 152 | } 153 | } -------------------------------------------------------------------------------- /facedetection/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /facedetection/src/main/res/drawable/button_capture_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /facedetection/src/main/res/drawable/ic_camera_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /facedetection/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 | -------------------------------------------------------------------------------- /facedetection/src/main/res/drawable/ic_mouse_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /facedetection/src/main/res/drawable/ic_music_note_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /facedetection/src/main/res/drawable/ic_remove_red_eye_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /facedetection/src/main/res/layout/activity_face_detection.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 29 | 30 | -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /facedetection/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/facedetection/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /facedetection/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /facedetection/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Face Detection 3 | 4 | -------------------------------------------------------------------------------- /facedetection/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /facedetection/src/main/res/xml/file_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /facedetection/src/test/java/com/cogitator/facedetection/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.cogitator.facedetection; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Oct 08 15:43:33 MYT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':textRecognition', ':facedetection', ':barcodescanner' 2 | -------------------------------------------------------------------------------- /textRecognition/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /google-services.json 3 | -------------------------------------------------------------------------------- /textRecognition/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion rootProject.ext.compileSdkVersion 9 | buildToolsVersion rootProject.ext.buildToolsVersion 10 | defaultConfig { 11 | applicationId "com.cogitator.firebasemlkit" 12 | minSdkVersion rootProject.ext.minSdkVersion 13 | targetSdkVersion rootProject.ext.targetSdkVersion 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 29 | implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" 30 | implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion" 31 | implementation "com.android.support:animated-vector-drawable:$rootProject.supportLibraryVersion" 32 | implementation "com.android.support:exifinterface:$rootProject.supportLibraryVersion" 33 | implementation "com.android.support:support-media-compat:$rootProject.supportLibraryVersion" 34 | 35 | implementation "com.google.firebase:firebase-core:$rootProject.firebaseCoreVersion" 36 | implementation "com.google.firebase:firebase-ml-vision:$rootProject.firebaseMLVissionVersion" 37 | 38 | implementation 'com.wonderkiln:camerakit:0.13.1' 39 | } 40 | 41 | apply plugin: 'com.google.gms.google-services' 42 | -------------------------------------------------------------------------------- /textRecognition/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 | -------------------------------------------------------------------------------- /textRecognition/src/androidTest/java/com/cogitator/firebasemlkit/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.firebasemlkit 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.cogitator.firbasemlkit", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /textRecognition/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /textRecognition/src/main/java/com/cogitator/firebasemlkit/SplashActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.firebasemlkit 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.os.Handler 6 | import android.support.v7.app.AppCompatActivity 7 | import android.view.Window 8 | import android.view.WindowManager 9 | import com.cogitator.firebasemlkit.textRecognizer.TextRecognizerActivity 10 | 11 | /** 12 | * @author Ankit Kumar (ankitdroiddeveloper@gmail.com) on 25/05/2018 (MM/DD/YYYY) 13 | */ 14 | class SplashActivity : AppCompatActivity() { 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | requestWindowFeature(Window.FEATURE_NO_TITLE) 18 | this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) 19 | setContentView(R.layout.activity_spalsh) 20 | 21 | Handler().postDelayed({ 22 | startActivity(Intent(this@SplashActivity, TextRecognizerActivity::class.java)) 23 | finish() 24 | }, 500) 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /textRecognition/src/main/java/com/cogitator/firebasemlkit/textRecognizer/GraphicOverlay.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.firebasemlkit.textRecognizer 2 | 3 | import android.content.Context 4 | import android.graphics.Canvas 5 | import android.hardware.camera2.CameraCharacteristics 6 | import android.util.AttributeSet 7 | import android.view.View 8 | 9 | 10 | /** 11 | * @author Ankit Kumar (ankitdroiddeveloper@gmail.com) on 30/05/2018 (MM/DD/YYYY) 12 | */ 13 | class GraphicOverlay(context: Context?, attrs: AttributeSet?) : View(context, attrs) { 14 | 15 | 16 | private val lock = Any() 17 | private var previewWidth: Int = 0 18 | private var widthScaleFactor = 1.0f 19 | private var previewHeight: Int = 0 20 | private var heightScaleFactor = 1.0f 21 | private var facing = CameraCharacteristics.LENS_FACING_BACK 22 | private val graphics: MutableSet = HashSet() 23 | 24 | /** 25 | * Base class for a custom graphics object to be rendered within the graphic overlay. Subclass 26 | * this and implement the [Graphic.draw] method to define the graphics element. Add 27 | * instances to the overlay using [GraphicOverlay.add]. 28 | */ 29 | abstract class Graphic(private val overlay: GraphicOverlay) { 30 | 31 | /** 32 | * Returns the application context of the app. 33 | */ 34 | val applicationContext: Context 35 | get() = overlay.context.applicationContext 36 | 37 | /** 38 | * Draw the graphic on the supplied canvas. Drawing should use the following methods to convert 39 | * to view coordinates for the graphics that are drawn: 40 | * 41 | * 42 | * 43 | * 1. [Graphic.scaleX] and [Graphic.scaleY] adjust the size of the 44 | * supplied value from the preview scale to the view scale. 45 | * 1. [Graphic.translateX] and [Graphic.translateY] adjust the 46 | * coordinate from the preview's coordinate system to the view coordinate system. 47 | * 48 | * 49 | * @param canvas drawing canvas 50 | */ 51 | abstract fun draw(canvas: Canvas) 52 | 53 | /** 54 | * Adjusts a horizontal value of the supplied value from the preview scale to the view scale. 55 | */ 56 | fun scaleX(horizontal: Float): Float { 57 | return horizontal * overlay.widthScaleFactor 58 | } 59 | 60 | /** 61 | * Adjusts a vertical value of the supplied value from the preview scale to the view scale. 62 | */ 63 | fun scaleY(vertical: Float): Float { 64 | return vertical * overlay.heightScaleFactor 65 | } 66 | 67 | /** 68 | * Adjusts the x coordinate from the preview's coordinate system to the view coordinate system. 69 | */ 70 | fun translateX(x: Float): Float { 71 | return if (overlay.facing == CameraCharacteristics.LENS_FACING_FRONT) { 72 | overlay.width - scaleX(x) 73 | } else { 74 | scaleX(x) 75 | } 76 | } 77 | 78 | /** 79 | * Adjusts the y coordinate from the preview's coordinate system to the view coordinate system. 80 | */ 81 | fun translateY(y: Float): Float { 82 | return scaleY(y) 83 | } 84 | 85 | fun postInvalidate() { 86 | overlay.postInvalidate() 87 | } 88 | } 89 | 90 | /** 91 | * Removes all graphics from the overlay. 92 | */ 93 | fun clear() { 94 | synchronized(lock) { 95 | graphics.clear() 96 | } 97 | postInvalidate() 98 | } 99 | 100 | /** 101 | * Adds a graphic to the overlay. 102 | */ 103 | fun add(graphic: Graphic) { 104 | synchronized(lock) { 105 | graphics.add(graphic) 106 | } 107 | postInvalidate() 108 | } 109 | 110 | /** 111 | * Removes a graphic from the overlay. 112 | */ 113 | fun remove(graphic: Graphic) { 114 | synchronized(lock) { 115 | graphics.remove(graphic) 116 | } 117 | postInvalidate() 118 | } 119 | 120 | /** 121 | * Sets the camera attributes for size and facing direction, which informs how to transform image 122 | * coordinates later. 123 | */ 124 | fun setCameraInfo(previewWidth: Int, previewHeight: Int, facing: Int) { 125 | synchronized(lock) { 126 | this.previewWidth = previewWidth 127 | this.previewHeight = previewHeight 128 | this.facing = facing 129 | } 130 | postInvalidate() 131 | } 132 | 133 | /** 134 | * Draws the overlay with its associated graphic objects. 135 | */ 136 | override fun onDraw(canvas: Canvas) { 137 | super.onDraw(canvas) 138 | 139 | synchronized(lock) { 140 | if (previewWidth != 0 && previewHeight != 0) { 141 | widthScaleFactor = canvas.width.toFloat() / previewWidth as Float 142 | heightScaleFactor = canvas.height.toFloat() / previewHeight as Float 143 | } 144 | 145 | for (graphic in graphics) { 146 | graphic.draw(canvas) 147 | } 148 | } 149 | } 150 | } -------------------------------------------------------------------------------- /textRecognition/src/main/java/com/cogitator/firebasemlkit/textRecognizer/TextGraphic.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.firebasemlkit.textRecognizer 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Color 5 | import android.graphics.Paint 6 | import com.google.firebase.ml.vision.text.FirebaseVisionText 7 | import android.graphics.RectF 8 | 9 | 10 | /** 11 | * @author Ankit Kumar (ankitdroiddeveloper@gmail.com) on 30/05/2018 (MM/DD/YYYY) 12 | */ 13 | class TextGraphic(overlay: GraphicOverlay, private val element: FirebaseVisionText.Element) : GraphicOverlay.Graphic(overlay) { 14 | 15 | private val TAG = "TextGraphic" 16 | private val TEXT_COLOR = Color.RED 17 | private val TEXT_SIZE = 54.0f 18 | private val STROKE_WIDTH = 4.0f 19 | 20 | private var rectPaint: Paint = Paint() 21 | private var textPaint: Paint = Paint() 22 | 23 | init { 24 | rectPaint = Paint() 25 | rectPaint.color = TEXT_COLOR 26 | rectPaint.style = Paint.Style.STROKE 27 | rectPaint.strokeWidth = STROKE_WIDTH 28 | 29 | textPaint = Paint() 30 | textPaint.color = TEXT_COLOR 31 | textPaint.textSize = TEXT_SIZE 32 | // Redraw the overlay, as this graphic has been added. 33 | postInvalidate() 34 | } 35 | 36 | /** 37 | * Draws the text block annotations for position, size, and raw value on the supplied canvas. 38 | */ 39 | override fun draw(canvas: Canvas) { 40 | // Draws the bounding box around the TextBlock. 41 | val rect = RectF(element.boundingBox) 42 | canvas.drawRect(rect, rectPaint) 43 | 44 | // Renders the text at the bottom of the box. 45 | canvas.drawText(element.text, rect.left, rect.bottom, textPaint) 46 | } 47 | } -------------------------------------------------------------------------------- /textRecognition/src/main/java/com/cogitator/firebasemlkit/textRecognizer/TextRecognizerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cogitator.firebasemlkit.textRecognizer 2 | 3 | import android.graphics.Bitmap 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.util.Log 7 | import com.cogitator.firebasemlkit.R 8 | import com.google.firebase.ml.vision.FirebaseVision 9 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 10 | import com.google.firebase.ml.vision.text.FirebaseVisionText 11 | import com.wonderkiln.camerakit.* 12 | import kotlinx.android.synthetic.main.activity_text_recog.* 13 | 14 | 15 | /** 16 | * @author Ankit Kumar (ankitdroiddeveloper@gmail.com) on 25/05/2018 (MM/DD/YYYY) 17 | */ 18 | class TextRecognizerActivity : AppCompatActivity() { 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | setContentView(R.layout.activity_text_recog) 22 | 23 | camView.addCameraKitListener(object : CameraKitEventListener { 24 | override fun onEvent(cameraKitEvent: CameraKitEvent) { 25 | 26 | } 27 | 28 | override fun onError(cameraKitError: CameraKitError) { 29 | 30 | } 31 | 32 | override fun onImage(cameraKitImage: CameraKitImage) { 33 | 34 | var bitmap = cameraKitImage.bitmap 35 | bitmap = Bitmap.createScaledBitmap(bitmap, camView.width, camView.height, false) 36 | camView.stop() 37 | runTextRecognition(bitmap) 38 | 39 | } 40 | 41 | override fun onVideo(cameraKitVideo: CameraKitVideo) { 42 | 43 | } 44 | }) 45 | 46 | cameraBtn.setOnClickListener { 47 | graphic_overlay_.clear() 48 | camView.start() 49 | camView.captureImage() 50 | } 51 | 52 | } 53 | 54 | private fun runTextRecognition(bitmap: Bitmap) { 55 | val image = FirebaseVisionImage.fromBitmap(bitmap) 56 | val detector = FirebaseVision.getInstance() 57 | .visionTextDetector 58 | detector.detectInImage(image) 59 | .addOnSuccessListener( 60 | { texts -> processTextRecognitionResult(texts as FirebaseVisionText) }) 61 | .addOnFailureListener( 62 | { e -> 63 | // Task failed with an exception 64 | e.printStackTrace() 65 | }) 66 | } 67 | 68 | private fun processTextRecognitionResult(texts: FirebaseVisionText) { 69 | val blocks = texts.blocks 70 | if (blocks.size == 0) { 71 | Log.d("TAG", "No text found") 72 | return 73 | } 74 | graphic_overlay_.clear() 75 | for (i in blocks.indices) { 76 | val lines = blocks.get(i).lines 77 | for (j in lines.indices) { 78 | val elements = lines[j].elements 79 | for (k in elements.indices) { 80 | val textGraphic = TextGraphic(graphic_overlay_, elements[k]) 81 | graphic_overlay_.add(textGraphic) 82 | 83 | } 84 | } 85 | } 86 | } 87 | 88 | public override fun onResume() { 89 | super.onResume() 90 | camView.start() 91 | } 92 | 93 | public override fun onPause() { 94 | camView.stop() 95 | super.onPause() 96 | } 97 | 98 | 99 | } -------------------------------------------------------------------------------- /textRecognition/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /textRecognition/src/main/res/drawable/firebase_28dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/textRecognition/src/main/res/drawable/firebase_28dp.png -------------------------------------------------------------------------------- /textRecognition/src/main/res/drawable/firebase_logotype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/textRecognition/src/main/res/drawable/firebase_logotype.png -------------------------------------------------------------------------------- /textRecognition/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 | -------------------------------------------------------------------------------- /textRecognition/src/main/res/drawable/mlkit_fore_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArchitectAK/FirebaseMLKit-Android/7e37f52a154b5a90947bfc226eac5297144bc922/textRecognition/src/main/res/drawable/mlkit_fore_.png -------------------------------------------------------------------------------- /textRecognition/src/main/res/layout/activity_spalsh.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 27 | 28 | 40 | 41 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /textRecognition/src/main/res/layout/activity_text_recog.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 15 | 16 | 17 |