├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── app-release.apk │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── github │ │ └── the_dagger │ │ └── mlkit │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── optimized_graph.tflite │ │ ├── pokedex.tflite │ │ ├── pokedex_dep.tflite │ │ └── pokelist.txt │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── the_dagger │ │ │ └── mlkit │ │ │ ├── activity │ │ │ ├── BarCodeReaderActivity.kt │ │ │ ├── BaseCameraActivity.kt │ │ │ ├── CardScannerActivity.kt │ │ │ ├── FaceDetectionActivity.kt │ │ │ ├── HomeActivity.kt │ │ │ ├── ImageLabelActivity.kt │ │ │ ├── LandmarkDetectorActivity.kt │ │ │ └── PokemonDetectorActivity.kt │ │ │ ├── adapter │ │ │ ├── FaceAdapter.kt │ │ │ ├── HomeAdapter.kt │ │ │ ├── ImageLabelAdapter.kt │ │ │ └── PokemonAdapter.kt │ │ │ └── model │ │ │ ├── PojoApi.kt │ │ │ └── Pokemon.kt │ └── res │ │ ├── drawable │ │ ├── barcode_scanning.png │ │ ├── face_detection.png │ │ ├── ic_arrow_upward.xml │ │ ├── ic_camera.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_refresh.xml │ │ ├── image_labelling.png │ │ ├── landmark_identification.png │ │ └── text_recognition.png │ │ ├── font │ │ └── roboto_medium.xml │ │ ├── layout │ │ ├── activity_home.xml │ │ ├── activity_main.xml │ │ ├── face_row.xml │ │ ├── item_row.xml │ │ ├── item_row_home.xml │ │ ├── layout_card_scanner.xml │ │ ├── layout_image_label.xml │ │ ├── layout_landmark.xml │ │ └── layout_qr_code_reader.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── font_certs.xml │ │ ├── preloaded_fonts.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── io │ └── github │ └── the_dagger │ └── mlkit │ └── ExampleUnitTest.kt ├── art └── screen01.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | .idea/workspace.xml 39 | 40 | # Keystore files 41 | *.jks 42 | 43 | # Mac 44 | .DS_Store 45 | 46 | # Other 47 | .externalNativeBuild 48 | google-services.json 49 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/.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 | 17 | 18 | -------------------------------------------------------------------------------- /.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 2 | A collection of real life apps built using [Firebase ML Kit](https://firebase.google.com/products/ml-kit/) APIs. 3 | 4 | # Setup Instructions 5 | 6 | 1. Clone the project 7 | 2. Add it to your Firebase Console 8 | 3. Profit! 9 | 10 | # Blogposts covering the making of this app 11 | 12 | * [Creating a Google Lens clone using Firebase MLKit](https://medium.com/coding-blocks/google-lens-firebase-54d34d7e1505) 13 | * [Creating a Credit Card Scanner using Firebase MLKit](https://medium.com/coding-blocks/creating-a-credit-card-scanner-using-firebase-mlkit-5345140f6a5c) 14 | * [Creating a Barcode Scanner using Firebase MLKit](https://medium.com/coding-blocks/creating-a-qr-code-reader-using-firebase-mlkit-60bb882f95f9) 15 | * [Identifying Places in a provided Image using Firebase MLKit](https://medium.com/coding-blocks/identifying-places-in-a-provided-image-using-firebase-mlkit-fe3c918756da) 16 | * [Building “Pokédex” in Android using TensorFlow Lite and Firebase’s ML Kit](https://heartbeat.fritz.ai/building-pok%C3%A9dex-in-android-using-tensorflow-lite-and-firebase-cc780848395) 17 | 18 | # Screenshots : 19 | ![image01](https://raw.githubusercontent.com/the-dagger/MLKitAndroid/master/art/screen01.png) 20 | 21 | # Libraries 22 | 23 | * [CameraKit Android](https://github.com/CameraKit/camerakit-android) 24 | * [FAB Progress to show progress](https://github.com/JorgeCastilloPrz/FABProgressCircle) 25 | * [Picking Image from camera/gallery](https://github.com/jkwiecien/EasyImage) 26 | 27 | Built with ❤️ by [@the-dagger](https://github.com/the-dagger) 28 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | apply plugin: 'kotlin-android-extensions' 5 | 6 | android { 7 | compileSdkVersion 28 8 | defaultConfig { 9 | applicationId "io.github.the_dagger.mlkit" 10 | minSdkVersion 21 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | aaptOptions { 16 | noCompress "tflite" 17 | } 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 30 | implementation 'com.android.support:appcompat-v7:28.0.0' 31 | implementation 'com.android.support:exifinterface:28.0.0' 32 | implementation 'com.android.support:support-media-compat:28.0.0' 33 | implementation 'com.android.support:support-v4:28.0.0' 34 | implementation 'com.android.support:design:28.0.0' 35 | implementation 'com.android.support:cardview-v7:28.0.0' 36 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 37 | implementation 'com.google.firebase:firebase-ml-vision-image-label-model:15.0.0' 38 | implementation "com.google.firebase:firebase-ml-model-interpreter:16.2.0" 39 | implementation "com.google.firebase:firebase-ml-vision:17.0.0" 40 | implementation 'com.google.firebase:firebase-core:16.0.3' 41 | implementation 'com.google.firebase:firebase-crash:16.2.0' 42 | testImplementation 'junit:junit:4.12' 43 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 45 | implementation 'com.wonderkiln:camerakit:0.13.1' 46 | implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar' 47 | implementation 'com.github.jkwiecien:EasyImage:1.3.1' 48 | } 49 | 50 | apply plugin: 'com.google.gms.google-services' 51 | -------------------------------------------------------------------------------- /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/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/io/github/the_dagger/mlkit/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit 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("io.github.the_dagger.mlkit", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 16 | 17 | 20 | 23 | 24 | 27 | 30 | 31 | 34 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 49 | 52 | 53 | 56 | 57 | 58 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/assets/optimized_graph.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/assets/optimized_graph.tflite -------------------------------------------------------------------------------- /app/src/main/assets/pokedex.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/assets/pokedex.tflite -------------------------------------------------------------------------------- /app/src/main/assets/pokedex_dep.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/assets/pokedex_dep.tflite -------------------------------------------------------------------------------- /app/src/main/assets/pokelist.txt: -------------------------------------------------------------------------------- 1 | "abra", 2 | "aerodactyl", 3 | "alakazam", 4 | "arbok", 5 | "arcanine", 6 | "articuno", 7 | "beedrill", 8 | "bellsprout", 9 | "blastoise", 10 | "bulbasaur", 11 | "butterfree", 12 | "caterpie", 13 | "chansey", 14 | "charizard", 15 | "charmander", 16 | "charmeleon", 17 | "clefable", 18 | "clefairy", 19 | "cloyster", 20 | "cubone", 21 | "dewgong", 22 | "diglett", 23 | "ditto", 24 | "dodrio", 25 | "doduo", 26 | "dragonair", 27 | "dragonite", 28 | "dratini", 29 | "drowzee", 30 | "dugtrio", 31 | "eevee", 32 | "ekans", 33 | "electabuzz", 34 | "electrode", 35 | "exeggcute", 36 | "exeggutor", 37 | "farfetchd", 38 | "fearow", 39 | "flareon", 40 | "gastly", 41 | "gengar", 42 | "geodude", 43 | "gloom", 44 | "golbat", 45 | "goldeen", 46 | "golduck", 47 | "golem", 48 | "graveler", 49 | "grimer", 50 | "growlithe", 51 | "gyarados", 52 | "haunter", 53 | "hitmonchan", 54 | "hitmonlee", 55 | "horsea", 56 | "hypno", 57 | "ivysaur", 58 | "jigglypuff", 59 | "jolteon", 60 | "jynx", 61 | "kabuto", 62 | "kabutops", 63 | "kadabra", 64 | "kakuna", 65 | "kangaskhan", 66 | "kingler", 67 | "koffing", 68 | "krabby", 69 | "lapras", 70 | "lickitung", 71 | "machamp", 72 | "machoke", 73 | "machop", 74 | "magikarp", 75 | "magmar", 76 | "magnemite", 77 | "magneton", 78 | "mankey", 79 | "marowak", 80 | "meowth", 81 | "metapod", 82 | "mew", 83 | "mewtwo", 84 | "moltres", 85 | "mrmime", 86 | "muk", 87 | "nidoking", 88 | "nidoqueen", 89 | "nidorina", 90 | "nidorino", 91 | "ninetales", 92 | "oddish", 93 | "omanyte", 94 | "omastar", 95 | "onix", 96 | "paras", 97 | "parasect", 98 | "persian", 99 | "pidgeot", 100 | "pidgeotto", 101 | "pidgey", 102 | "pikachu", 103 | "pinsir", 104 | "poliwag", 105 | "poliwhirl", 106 | "poliwrath", 107 | "ponyta", 108 | "porygon", 109 | "primeape", 110 | "psyduck", 111 | "raichu", 112 | "rapidash", 113 | "raticate", 114 | "rattata", 115 | "rhydon", 116 | "rhyhorn", 117 | "sandshrew", 118 | "sandslash", 119 | "scyther", 120 | "seadra", 121 | "seaking", 122 | "seel", 123 | "shellder", 124 | "slowbro", 125 | "slowpoke", 126 | "snorlax", 127 | "spearow", 128 | "squirtle", 129 | "starmie", 130 | "staryu", 131 | "tangela", 132 | "tauros", 133 | "tentacool", 134 | "tentacruel", 135 | "vaporeon", 136 | "venomoth", 137 | "venonat", 138 | "venusaur", 139 | "victreebel", 140 | "vileplume", 141 | "voltorb", 142 | "vulpix", 143 | "wartortle", 144 | "weedle", 145 | "weepinbell", 146 | "weezing", 147 | "wigglytuff", 148 | "zapdos", 149 | "zubat" 150 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/BarCodeReaderActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 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 io.github.the_dagger.mlkit.R 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | import kotlinx.android.synthetic.main.layout_qr_code_reader.* 15 | 16 | 17 | class BarCodeReaderActivity : BaseCameraActivity() { 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | setupBottomSheet(R.layout.layout_qr_code_reader) 22 | } 23 | 24 | override fun onClick(v: View) { 25 | fabProgressCircle.show() 26 | cameraView.captureImage { cameraKitImage -> 27 | // Get the Bitmap from the captured shot 28 | getQRCodeDetails(cameraKitImage.bitmap) 29 | runOnUiThread { 30 | showPreview() 31 | imagePreview.setImageBitmap(cameraKitImage.bitmap) 32 | } 33 | } 34 | } 35 | 36 | private fun getQRCodeDetails(bitmap: Bitmap) { 37 | val options = FirebaseVisionBarcodeDetectorOptions.Builder() 38 | .setBarcodeFormats( 39 | FirebaseVisionBarcode.FORMAT_ALL_FORMATS) 40 | .build() 41 | val detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options) 42 | val image = FirebaseVisionImage.fromBitmap(bitmap) 43 | detector.detectInImage(image) 44 | .addOnSuccessListener { 45 | for (firebaseBarcode in it) { 46 | 47 | codeData.text = firebaseBarcode.displayValue //Display contents inside the barcode 48 | 49 | when (firebaseBarcode.valueType) { 50 | //Handle the URL here 51 | FirebaseVisionBarcode.TYPE_URL -> firebaseBarcode.url 52 | // Handle the contact info here, i.e. address, name, phone, etc. 53 | FirebaseVisionBarcode.TYPE_CONTACT_INFO -> firebaseBarcode.contactInfo 54 | // Handle the wifi here, i.e. firebaseBarcode.wifi.ssid, etc. 55 | FirebaseVisionBarcode.TYPE_WIFI -> firebaseBarcode.wifi 56 | //Handle more type of Barcodes 57 | } 58 | 59 | } 60 | } 61 | .addOnFailureListener { 62 | it.printStackTrace() 63 | Toast.makeText(baseContext, "Sorry, something went wrong!", Toast.LENGTH_SHORT).show() 64 | } 65 | .addOnCompleteListener { 66 | fabProgressCircle.hide() 67 | sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/BaseCameraActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 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 io.github.the_dagger.mlkit.R 11 | import kotlinx.android.synthetic.main.activity_main.* 12 | 13 | abstract class BaseCameraActivity : AppCompatActivity(), View.OnClickListener { 14 | 15 | lateinit var sheetBehavior: BottomSheetBehavior<*> 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_main) 20 | btnRetry.setOnClickListener { 21 | if (cameraView.visibility == View.VISIBLE) showPreview() else hidePreview() 22 | } 23 | fab_take_photo.setOnClickListener(this) 24 | } 25 | 26 | fun setupBottomSheet(@LayoutRes id : Int){ 27 | //Using a ViewStub since changing the layout of an tag dynamically wasn't possible 28 | stubView.layoutResource = id 29 | val inflatedView = stubView.inflate() 30 | //Set layout parameters for the inflated bottomsheet 31 | val lparam = inflatedView.layoutParams as CoordinatorLayout.LayoutParams 32 | lparam.behavior = BottomSheetBehavior() 33 | inflatedView.layoutParams = lparam 34 | sheetBehavior = BottomSheetBehavior.from(inflatedView) 35 | sheetBehavior.peekHeight = 224 36 | //Anchor the FAB to the end of inflated bottom sheet 37 | val lp = fabProgressCircle.layoutParams as CoordinatorLayout.LayoutParams 38 | lp.anchorId = inflatedView.id 39 | lp.anchorGravity = Gravity.END 40 | fabProgressCircle.layoutParams = lp 41 | //Hide the fab as bottomSheet is expanded 42 | sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { 43 | override fun onStateChanged(bottomSheet: View, newState: Int) {} 44 | override fun onSlide(bottomSheet: View, slideOffset: Float) { 45 | fab_take_photo.animate().scaleX(1 - slideOffset).scaleY(1 - slideOffset).setDuration(0).start() 46 | } 47 | }) 48 | } 49 | 50 | override fun onResume() { 51 | super.onResume() 52 | cameraView.start() 53 | } 54 | 55 | override fun onPause() { 56 | cameraView.stop() 57 | super.onPause() 58 | } 59 | 60 | protected fun showPreview() { 61 | framePreview.visibility = View.VISIBLE 62 | cameraView.visibility = View.GONE 63 | } 64 | 65 | protected fun hidePreview() { 66 | framePreview.visibility = View.GONE 67 | cameraView.visibility = View.VISIBLE 68 | } 69 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/CardScannerActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 2 | 3 | import android.graphics.Bitmap 4 | import android.os.Bundle 5 | import android.support.design.widget.BottomSheetBehavior 6 | import android.util.Log 7 | import android.view.View 8 | import android.widget.Toast 9 | import com.google.firebase.ml.vision.FirebaseVision 10 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 11 | import io.github.the_dagger.mlkit.R 12 | import kotlinx.android.synthetic.main.activity_main.* 13 | import kotlinx.android.synthetic.main.layout_card_scanner.* 14 | 15 | 16 | class CardScannerActivity : BaseCameraActivity() { 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | setupBottomSheet(R.layout.layout_card_scanner) 21 | } 22 | 23 | override fun onClick(v: View?) { 24 | fabProgressCircle.show() 25 | cameraView.captureImage { cameraKitImage -> 26 | // Get the Bitmap from the captured shot 27 | getCardDetailsFromCloud(cameraKitImage.bitmap) 28 | runOnUiThread { 29 | showPreview() 30 | imagePreview.setImageBitmap(cameraKitImage.bitmap) 31 | } 32 | } 33 | } 34 | 35 | private fun getCardDetailsFromCloud(bitmap: Bitmap) { 36 | val image = FirebaseVisionImage.fromBitmap(bitmap) 37 | val firebaseVisionTextDetector = FirebaseVision.getInstance().cloudTextRecognizer 38 | 39 | firebaseVisionTextDetector.processImage(image) 40 | .addOnSuccessListener { 41 | Log.e("TAG", it.text) 42 | val words = it.text.split("\n") 43 | for (word in words) { 44 | Log.e("TAG", word) 45 | //REGEX for detecting a credit card 46 | if (word.replace(" ", "").matches(Regex("^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})\$"))) 47 | tvCardNumber.text = word 48 | //Find a better way to do this 49 | if (word.contains("/")) { 50 | for (year in word.split(" ")) { 51 | if (year.contains("/")) 52 | tvCardExpiry.text = year 53 | } 54 | } 55 | } 56 | sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED 57 | } 58 | .addOnFailureListener { 59 | Toast.makeText(baseContext, "Sorry, something went wrong!", Toast.LENGTH_SHORT).show() 60 | } 61 | .addOnCompleteListener { 62 | fabProgressCircle.hide() 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/FaceDetectionActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 2 | 3 | import android.graphics.Bitmap 4 | import android.os.Bundle 5 | import android.support.design.widget.BottomSheetBehavior 6 | import android.support.v7.widget.LinearLayoutManager 7 | import android.view.View 8 | import android.widget.Toast 9 | import com.google.firebase.ml.vision.FirebaseVision 10 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 11 | import com.google.firebase.ml.vision.face.FirebaseVisionFace 12 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetector 13 | import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetectorOptions 14 | import com.wonderkiln.camerakit.CameraKit 15 | import io.github.the_dagger.mlkit.R 16 | import io.github.the_dagger.mlkit.R.id.* 17 | import io.github.the_dagger.mlkit.activity.BaseCameraActivity 18 | import io.github.the_dagger.mlkit.adapter.FaceAdapter 19 | import kotlinx.android.synthetic.main.activity_main.* 20 | import kotlinx.android.synthetic.main.layout_image_label.* 21 | 22 | class FaceDetectionActivity : BaseCameraActivity() { 23 | 24 | private val detectedFaces = arrayListOf() 25 | private val adapter = FaceAdapter(detectedFaces) 26 | 27 | override fun onCreate(savedInstanceState: Bundle?) { 28 | super.onCreate(savedInstanceState) 29 | // cameraView.facing = CameraKit.Constants.FACING_FRONT 30 | setupBottomSheet(R.layout.layout_image_label) 31 | rvLabel.layoutManager = LinearLayoutManager(this) 32 | 33 | rvLabel.adapter = adapter 34 | } 35 | 36 | private fun getFaceDetails(bitmap: Bitmap) { 37 | val options: FirebaseVisionFaceDetectorOptions = FirebaseVisionFaceDetectorOptions.Builder() 38 | .setLandmarkType(FirebaseVisionFaceDetectorOptions.ALL_LANDMARKS) 39 | .setClassificationType(FirebaseVisionFaceDetectorOptions.ALL_CLASSIFICATIONS) 40 | .setModeType(FirebaseVisionFaceDetectorOptions.FAST_MODE) 41 | .build() 42 | val image: FirebaseVisionImage = FirebaseVisionImage.fromBitmap(bitmap) 43 | val faceDetector = FirebaseVision.getInstance().getVisionFaceDetector(options) 44 | 45 | faceDetector.detectInImage(image) 46 | .addOnSuccessListener { 47 | detectedFaces.clear() 48 | detectedFaces.addAll(it) 49 | adapter.notifyDataSetChanged() 50 | } 51 | .addOnFailureListener { 52 | Toast.makeText(this, "Sorry, an error occurred", Toast.LENGTH_SHORT).show() 53 | } 54 | .addOnCompleteListener { 55 | sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED 56 | fabProgressCircle.hide() 57 | } 58 | } 59 | 60 | override fun onClick(v: View?) { 61 | fabProgressCircle.show() 62 | cameraView.captureImage { cameraKitImage -> 63 | // Get the Bitmap from the captured shot 64 | getFaceDetails(cameraKitImage.bitmap) 65 | runOnUiThread { 66 | showPreview() 67 | imagePreview.setImageBitmap(cameraKitImage.bitmap) 68 | } 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/HomeActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.support.v7.widget.LinearLayoutManager 6 | import io.github.the_dagger.mlkit.adapter.HomeAdapter 7 | import io.github.the_dagger.mlkit.model.PojoApi 8 | import io.github.the_dagger.mlkit.R 9 | import kotlinx.android.synthetic.main.activity_home.* 10 | 11 | class HomeActivity : AppCompatActivity() { 12 | 13 | private val apiList by lazy { 14 | ArrayList() 15 | } 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_home) 20 | with(apiList) { 21 | add(PojoApi(R.drawable.image_labelling, getString(R.string.title_labelling), getString(R.string.desc_labelling), 0)) 22 | add(PojoApi(R.drawable.text_recognition, getString(R.string.title_text), getString(R.string.desc_text), 1)) 23 | add(PojoApi(R.drawable.barcode_scanning, getString(R.string.title_barcode), getString(R.string.desc_barcode), 2)) 24 | add(PojoApi(R.drawable.landmark_identification, getString(R.string.title_landmark), getString(R.string.desc_landmark), 3)) 25 | add(PojoApi(R.drawable.face_detection, getString(R.string.title_face), getString(R.string.desc_face), 4)) 26 | } 27 | 28 | rvHome.layoutManager = LinearLayoutManager(this) 29 | rvHome.adapter = HomeAdapter(apiList) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/ImageLabelActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 2 | 3 | import android.graphics.Bitmap 4 | import android.os.Bundle 5 | import android.support.design.widget.BottomSheetBehavior 6 | import android.support.v7.widget.LinearLayoutManager 7 | import android.view.View 8 | import android.widget.Toast 9 | import com.google.firebase.ml.vision.FirebaseVision 10 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 11 | import io.github.the_dagger.mlkit.R 12 | import io.github.the_dagger.mlkit.adapter.ImageLabelAdapter 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | import kotlinx.android.synthetic.main.layout_image_label.* 15 | 16 | class ImageLabelActivity : BaseCameraActivity() { 17 | 18 | private var itemsList: ArrayList = ArrayList() 19 | private lateinit var itemAdapter: ImageLabelAdapter 20 | 21 | override fun onCreate(savedInstanceState: Bundle?) { 22 | super.onCreate(savedInstanceState) 23 | setupBottomSheet(R.layout.layout_image_label) 24 | rvLabel.layoutManager = LinearLayoutManager(this) 25 | } 26 | 27 | private fun getLabelsFromDevice(bitmap: Bitmap) { 28 | val image = FirebaseVisionImage.fromBitmap(bitmap) 29 | val detector = FirebaseVision.getInstance().visionLabelDetector 30 | itemsList.clear() 31 | detector.detectInImage(image) 32 | .addOnSuccessListener { 33 | // Task completed successfully 34 | fabProgressCircle.hide() 35 | itemsList.addAll(it) 36 | itemAdapter = ImageLabelAdapter(itemsList, false) 37 | rvLabel.adapter = itemAdapter 38 | sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) 39 | } 40 | .addOnFailureListener { 41 | // Task failed with an exception 42 | fabProgressCircle.hide() 43 | Toast.makeText(baseContext,"Sorry, something went wrong!",Toast.LENGTH_SHORT).show() 44 | } 45 | } 46 | 47 | private fun getLabelsFromClod(bitmap: Bitmap) { 48 | val image = FirebaseVisionImage.fromBitmap(bitmap) 49 | val detector = FirebaseVision.getInstance() 50 | .visionCloudLabelDetector 51 | itemsList.clear() 52 | detector.detectInImage(image) 53 | .addOnSuccessListener { 54 | // Task completed successfully 55 | fabProgressCircle.hide() 56 | itemsList.addAll(it) 57 | itemAdapter = ImageLabelAdapter(itemsList, true) 58 | rvLabel.adapter = itemAdapter 59 | sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) 60 | } 61 | .addOnFailureListener { 62 | // Task failed with an exception 63 | fabProgressCircle.hide() 64 | Toast.makeText(baseContext,"Sorry, something went wrong!",Toast.LENGTH_SHORT).show() 65 | } 66 | } 67 | 68 | override fun onClick(v: View?) { 69 | fabProgressCircle.show() 70 | cameraView.captureImage { cameraKitImage -> 71 | // Get the Bitmap from the captured shot 72 | getLabelsFromClod(cameraKitImage.bitmap) 73 | runOnUiThread { 74 | showPreview() 75 | imagePreview.setImageBitmap(cameraKitImage.bitmap) 76 | } 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/LandmarkDetectorActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 2 | 3 | import android.Manifest 4 | import android.content.Intent 5 | import android.content.pm.PackageManager 6 | import android.graphics.Bitmap 7 | import android.graphics.BitmapFactory 8 | import android.os.Bundle 9 | import android.support.design.widget.BottomSheetBehavior 10 | import android.support.v4.app.ActivityCompat 11 | import android.util.Log 12 | import android.view.View 13 | import android.widget.Toast 14 | import com.google.firebase.ml.vision.FirebaseVision 15 | import com.google.firebase.ml.vision.common.FirebaseVisionImage 16 | import io.github.the_dagger.mlkit.R 17 | import kotlinx.android.synthetic.main.activity_main.* 18 | import kotlinx.android.synthetic.main.layout_landmark.* 19 | import pl.aprilapps.easyphotopicker.DefaultCallback 20 | import pl.aprilapps.easyphotopicker.EasyImage 21 | import java.io.File 22 | 23 | 24 | class LandmarkDetectorActivity : BaseCameraActivity() { 25 | 26 | override fun onCreate(savedInstanceState: Bundle?) { 27 | super.onCreate(savedInstanceState) 28 | setupBottomSheet(R.layout.layout_landmark) 29 | cameraView.visibility = View.GONE 30 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) 31 | == PackageManager.PERMISSION_DENIED) { 32 | ActivityCompat.requestPermissions(this, Array(1) { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 12345) 33 | fab_take_photo.setOnClickListener(null) 34 | } else { 35 | fab_take_photo.setOnClickListener(this) 36 | } 37 | } 38 | 39 | override fun onClick(v: View?) { 40 | //onClick attribute for the FloatingActionButton 41 | startIntentForPicker() 42 | } 43 | 44 | private fun startIntentForPicker() { 45 | EasyImage.openGallery(this, 0) 46 | } 47 | 48 | override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { 49 | super.onRequestPermissionsResult(requestCode, permissions, grantResults) 50 | if (requestCode == 12345) { 51 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) 52 | //The library requires write access to the External Storage, 53 | //so ensure that the permission is granted 54 | fab_take_photo.setOnClickListener(this) 55 | } 56 | } 57 | 58 | 59 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 60 | super.onActivityResult(requestCode, resultCode, data) 61 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) 62 | == PackageManager.PERMISSION_GRANTED) { 63 | EasyImage.handleActivityResult(requestCode, resultCode, data, this, object : DefaultCallback() { 64 | 65 | override fun onImagePicked(imageFile: File?, source: EasyImage.ImageSource?, type: Int) { 66 | val bitmap = BitmapFactory.decodeFile(imageFile?.path) 67 | getLandmarkFromCloud(bitmap) 68 | imagePreview.setImageBitmap(bitmap) 69 | framePreview.visibility = View.VISIBLE 70 | btnRetry.visibility = View.GONE 71 | } 72 | 73 | override fun onImagePickerError(e: Exception?, source: EasyImage.ImageSource?, type: Int) { 74 | //Some error handling since no image was picked 75 | } 76 | }) 77 | } 78 | } 79 | 80 | private fun getLandmarkFromCloud(bitmap: Bitmap) { 81 | val image = FirebaseVisionImage.fromBitmap(bitmap) 82 | val detector = FirebaseVision.getInstance() 83 | .visionCloudLandmarkDetector 84 | 85 | detector.detectInImage(image) 86 | .addOnCompleteListener { 87 | Log.e("TAG", "completed") 88 | for (firebaseVisionLandmarks in it.result) { 89 | val landmark = firebaseVisionLandmarks.landmark 90 | tvLocationName.text = landmark 91 | for (location in firebaseVisionLandmarks.locations) { 92 | val lat = location.latitude 93 | val long = location.longitude 94 | tvLatitude.text = lat.toString() 95 | tvLongitude.text = long.toString() 96 | } 97 | tvAccuracy.text = (firebaseVisionLandmarks.confidence * 100).toInt().toString() 98 | } 99 | } 100 | .addOnFailureListener { 101 | Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show() 102 | } 103 | .addOnCompleteListener { 104 | sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED 105 | } 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/activity/PokemonDetectorActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.activity 2 | 3 | import android.graphics.Bitmap 4 | import android.os.Bundle 5 | import android.support.design.widget.BottomSheetBehavior 6 | import android.support.v7.widget.LinearLayoutManager 7 | import android.view.View 8 | import com.google.firebase.ml.custom.* 9 | import com.google.firebase.ml.custom.model.FirebaseLocalModelSource 10 | import io.github.the_dagger.mlkit.model.Pokemon 11 | import io.github.the_dagger.mlkit.R 12 | import io.github.the_dagger.mlkit.adapter.PokemonAdapter 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | import kotlinx.android.synthetic.main.layout_image_label.* 15 | import java.nio.ByteBuffer 16 | import java.nio.ByteOrder 17 | import com.google.firebase.ml.custom.FirebaseModelManager 18 | import com.google.firebase.ml.custom.model.FirebaseCloudModelSource 19 | 20 | class PokemonDetectorActivity : BaseCameraActivity() { 21 | private val pokeArray: Array = arrayOf("abra", "aerodactyl", "alakazam", "arbok", "arcanine", "articuno", "beedrill", "bellsprout", 22 | "blastoise", "bulbasaur", "butterfree", "caterpie", "chansey", "charizard", "charmander", "charmeleon", "clefable", "clefairy", "cloyster", "cubone", "dewgong", 23 | "diglett", "ditto", "dodrio", "doduo", "dragonair", "dragonite", "dratini", "drowzee", "dugtrio", "eevee", "ekans", "electabuzz", 24 | "electrode", "exeggcute", "exeggutor", "farfetchd", "fearow", "flareon", "gastly", "gengar", "geodude", "gloom", 25 | "golbat", "goldeen", "golduck", "golem", "graveler", "grimer", "growlithe", "gyarados", "haunter", "hitmonchan", 26 | "hitmonlee", "horsea", "hypno", "ivysaur", "jigglypuff", "jolteon", "jynx", "kabuto", 27 | "kabutops", "kadabra", "kakuna", "kangaskhan", "kingler", "koffing", "krabby", "lapras", "lickitung", "machamp", 28 | "machoke", "machop", "magikarp", "magmar", "magnemite", "magneton", "mankey", "marowak", "meowth", "metapod", 29 | "mew", "mewtwo", "moltres", "mrmime", "muk", "nidoking", "nidoqueen", "nidorina", "nidorino", "ninetales", 30 | "oddish", "omanyte", "omastar", "onix", "paras", "parasect", "persian", "pidgeot", "pidgeotto", "pidgey", 31 | "pikachu", "pinsir", "poliwag", "poliwhirl", "poliwrath", "ponyta", "porygon", "primeape", "psyduck", "raichu", 32 | "rapidash", "raticate", "rattata", "rhydon", "rhyhorn", "sandshrew", "sandslash", "scyther", "seadra", 33 | "seaking", "seel", "shellder", "slowbro", "slowpoke", "snorlax", "spearow", "squirtle", "starmie", "staryu", 34 | "tangela", "tauros", "tentacool", "tentacruel", "vaporeon", "venomoth", "venonat", "venusaur", "victreebel", 35 | "vileplume", "voltorb", "vulpix", "wartortle", "weedle", "weepinbell", "weezing", "wigglytuff", "zapdos", "zubat") 36 | 37 | companion object { 38 | /** Dimensions of inputs. */ 39 | const val DIM_IMG_SIZE_X = 224 40 | const val DIM_IMG_SIZE_Y = 224 41 | const val DIM_BATCH_SIZE = 1 42 | const val DIM_PIXEL_SIZE = 3 43 | const val IMAGE_MEAN = 128 44 | private const val IMAGE_STD = 128.0f 45 | } 46 | 47 | private val intValues = IntArray(DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y) 48 | private lateinit var imgData: ByteBuffer 49 | private lateinit var fireBaseInterpreter: FirebaseModelInterpreter 50 | private lateinit var inputOutputOptions: FirebaseModelInputOutputOptions 51 | 52 | private lateinit var itemAdapter: PokemonAdapter 53 | 54 | override fun onCreate(savedInstanceState: Bundle?) { 55 | super.onCreate(savedInstanceState) 56 | setupBottomSheet(R.layout.layout_image_label) 57 | imgData = ByteBuffer.allocateDirect( 58 | 4 * DIM_BATCH_SIZE * DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y * DIM_PIXEL_SIZE); 59 | imgData.order(ByteOrder.nativeOrder()) 60 | 61 | rvLabel.layoutManager = LinearLayoutManager(this) 62 | 63 | //Load a cloud model using the FirebaseCloudModelSource Builder class 64 | val cloudSource = FirebaseCloudModelSource.Builder("pokedex") 65 | .enableModelUpdates(true) 66 | .build() 67 | 68 | //Registering the cloud model loaded above with the ModelManager Singleton 69 | FirebaseModelManager.getInstance().registerCloudModelSource(cloudSource) 70 | 71 | //Load a local model using the FirebaseLocalModelSource Builder class 72 | val fireBaseLocalModelSource = FirebaseLocalModelSource.Builder("pokedex") 73 | .setAssetFilePath("pokedex.tflite") 74 | .build() 75 | 76 | //Registering the model loaded above with the ModelManager Singleton 77 | FirebaseModelManager.getInstance().registerLocalModelSource(fireBaseLocalModelSource) 78 | 79 | val firebaseModelOptions = FirebaseModelOptions.Builder() 80 | .setLocalModelName("pokedex") 81 | .setCloudModelName("pokedex") 82 | .build() 83 | 84 | fireBaseInterpreter = FirebaseModelInterpreter.getInstance(firebaseModelOptions)!! 85 | 86 | //Input and Output options for the model 87 | inputOutputOptions = FirebaseModelInputOutputOptions.Builder() 88 | .setInputFormat(0, FirebaseModelDataType.FLOAT32, intArrayOf(1, 224, 224, 3)) 89 | .setOutputFormat(0, FirebaseModelDataType.FLOAT32, intArrayOf(1, 149)) 90 | .build() 91 | } 92 | 93 | override fun onClick(v: View?) { 94 | fabProgressCircle.show() 95 | cameraView.captureImage { cameraKitImage -> 96 | // Get the Bitmap from the captured shot 97 | 98 | val scaledBitmap = Bitmap.createScaledBitmap(cameraKitImage.bitmap, 224, 224, false) 99 | getPokemonFromBitmap(scaledBitmap) 100 | runOnUiThread { 101 | showPreview() 102 | imagePreview.setImageBitmap(cameraKitImage.bitmap) 103 | } 104 | } 105 | } 106 | 107 | private fun convertBitmapToByteBuffer(bitmap: Bitmap?): ByteBuffer { 108 | //Clear the Bytebuffer for a new image 109 | imgData.rewind() 110 | bitmap?.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height) 111 | // Convert the image to floating point. 112 | var pixel = 0 113 | for (i in 0 until DIM_IMG_SIZE_X) { 114 | for (j in 0 until DIM_IMG_SIZE_Y) { 115 | val currPixel = intValues[pixel++] 116 | imgData.putFloat(((currPixel shr 16 and 0xFF) - IMAGE_MEAN) / IMAGE_STD) 117 | imgData.putFloat(((currPixel shr 8 and 0xFF) - IMAGE_MEAN) / IMAGE_STD) 118 | imgData.putFloat(((currPixel and 0xFF) - IMAGE_MEAN) / IMAGE_STD) 119 | } 120 | } 121 | return imgData 122 | } 123 | 124 | private fun getPokemonFromBitmap(bitmap: Bitmap?) { 125 | //Creating a FirebaseModelInput object that takes in the ByteBuffer as an input 126 | val inputs = FirebaseModelInputs.Builder() 127 | .add(convertBitmapToByteBuffer(bitmap)) 128 | .build() 129 | 130 | //Provide the firebaseModelInput to the FirebaseInterpreter 131 | fireBaseInterpreter.run(inputs, inputOutputOptions) 132 | ?.addOnSuccessListener { 133 | val pokeList = mutableListOf() 134 | /** 135 | * Run a foreach loop through the output float array containing the probabilities 136 | * corresponding to each label 137 | * @see pokeArray to know what labels are supported 138 | */ 139 | it.getOutput>(0)[0].forEachIndexed { index, fl -> 140 | //Only consider a pokemon when the accuracy is more than 30% 141 | if (fl > .20) 142 | pokeList.add(Pokemon(pokeArray[index], fl)) 143 | } 144 | 145 | rvLabel.layoutManager = LinearLayoutManager(this) 146 | fabProgressCircle.hide() 147 | itemAdapter = PokemonAdapter(pokeList) 148 | rvLabel.adapter = itemAdapter 149 | sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) 150 | } 151 | ?.addOnFailureListener { 152 | it.printStackTrace() 153 | fabProgressCircle.hide() 154 | } 155 | } 156 | 157 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/adapter/FaceAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import com.google.firebase.ml.vision.face.FirebaseVisionFace 8 | import io.github.the_dagger.mlkit.R 9 | import kotlinx.android.synthetic.main.face_row.view.* 10 | 11 | class FaceAdapter(private val faces: List) : RecyclerView.Adapter() { 12 | 13 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FaceHolder { 14 | return FaceHolder(LayoutInflater.from(parent.context).inflate(R.layout.face_row, parent, false)) 15 | } 16 | 17 | override fun getItemCount() = faces.size 18 | 19 | override fun onBindViewHolder(faceholder: FaceHolder, position: Int) { 20 | val face = faces[position] 21 | 22 | faceholder.itemView.smilingPro.text = face.smilingProbability.toString() 23 | faceholder.itemView.leftEyeClose.text = face.leftEyeOpenProbability.toString() 24 | faceholder.itemView.rightEyeClosed.text = face.rightEyeOpenProbability.toString() 25 | 26 | 27 | } 28 | 29 | class FaceHolder(itemView: View) : RecyclerView.ViewHolder(itemView) 30 | 31 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/adapter/HomeAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.adapter 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.support.v7.widget.RecyclerView 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.widget.Toast 10 | import io.github.the_dagger.mlkit.model.PojoApi 11 | import io.github.the_dagger.mlkit.R 12 | import io.github.the_dagger.mlkit.activity.* 13 | import kotlinx.android.synthetic.main.item_row_home.view.* 14 | 15 | class HomeAdapter(private val apiList: List) : RecyclerView.Adapter() { 16 | 17 | private lateinit var context: Context 18 | 19 | class HomeHolder(itemView: View) : RecyclerView.ViewHolder(itemView) 20 | 21 | override fun onBindViewHolder(holder: HomeHolder, position: Int) { 22 | val currItem = apiList[position] 23 | with(holder.itemView) { 24 | tViewApiName.text = currItem.title 25 | tViewApiDesc.text = currItem.desc 26 | iViewApi.setImageResource(currItem.imageId) 27 | cViewHome.setOnClickListener { 28 | when (currItem.id) { 29 | 0 -> context.startActivity(Intent(context, ImageLabelActivity::class.java)) 30 | 1 -> context.startActivity(Intent(context, CardScannerActivity::class.java)) 31 | 2 -> context.startActivity(Intent(context, BarCodeReaderActivity::class.java)) 32 | 3 -> context.startActivity(Intent(context, LandmarkDetectorActivity::class.java)) 33 | 4 -> context.startActivity(Intent(context, FaceDetectionActivity::class.java)) 34 | } 35 | } 36 | } 37 | } 38 | 39 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeHolder { 40 | context = parent.context 41 | return HomeHolder(LayoutInflater.from(context).inflate(R.layout.item_row_home, parent, false)) 42 | } 43 | 44 | override fun getItemCount() = apiList.size 45 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/adapter/ImageLabelAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.adapter 2 | 3 | import android.content.Context 4 | import android.support.v4.content.ContextCompat 5 | import android.support.v7.widget.RecyclerView 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabel 10 | import com.google.firebase.ml.vision.label.FirebaseVisionLabel 11 | import io.github.the_dagger.mlkit.R 12 | import kotlinx.android.synthetic.main.item_row.view.* 13 | 14 | class ImageLabelAdapter(private val firebaseVisionList: List, private val isCloud: Boolean) : RecyclerView.Adapter() { 15 | lateinit var context: Context 16 | 17 | inner class ItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 18 | 19 | fun bindCloud(currentItem: FirebaseVisionCloudLabel) { 20 | when { 21 | currentItem.confidence > .70 -> itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.green)) 22 | currentItem.confidence < .30 -> itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.red)) 23 | else -> itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.orange)) 24 | } 25 | itemView.itemName.text = currentItem.label 26 | itemView.itemAccuracy.text = "Probability : ${(currentItem.confidence * 100).toInt()}%" 27 | } 28 | 29 | fun bindDevice(currentItem: FirebaseVisionLabel) { 30 | when { 31 | currentItem.confidence > .70 -> itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.green)) 32 | currentItem.confidence < .30 -> itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.red)) 33 | else -> itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.orange)) 34 | } 35 | itemView.itemName.text = currentItem.label 36 | itemView.itemAccuracy.text = "Probability : ${(currentItem.confidence * 100).toInt()}%" 37 | } 38 | 39 | } 40 | 41 | override fun onBindViewHolder(holder: ItemHolder, position: Int) { 42 | val currentItem = firebaseVisionList[position] 43 | if (isCloud) 44 | holder.bindCloud(currentItem as FirebaseVisionCloudLabel) 45 | else 46 | holder.bindDevice(currentItem as FirebaseVisionLabel) 47 | } 48 | 49 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { 50 | context = parent.context 51 | return ItemHolder(LayoutInflater.from(context).inflate(R.layout.item_row, parent, false)) 52 | } 53 | 54 | override fun getItemCount() = firebaseVisionList.size 55 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/adapter/PokemonAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.adapter 2 | 3 | import android.content.Context 4 | import android.support.v4.content.ContextCompat 5 | import android.support.v7.widget.RecyclerView 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import io.github.the_dagger.mlkit.model.Pokemon 10 | import io.github.the_dagger.mlkit.R 11 | import kotlinx.android.synthetic.main.item_row.view.* 12 | 13 | class PokemonAdapter(private val pokeList: List) : RecyclerView.Adapter() { 14 | 15 | private lateinit var context: Context 16 | 17 | class PokeHolder(itemView: View) : RecyclerView.ViewHolder(itemView) 18 | 19 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PokeHolder { 20 | context = parent.context 21 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_row, parent, false) 22 | return PokeHolder(view) 23 | } 24 | 25 | override fun getItemCount() = pokeList.size 26 | 27 | override fun onBindViewHolder(holder: PokeHolder, position: Int) { 28 | 29 | val currentItem = pokeList[position] 30 | 31 | when { 32 | currentItem.accuracy > .70 -> holder.itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.green)) 33 | currentItem.accuracy < .30 -> holder.itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.red)) 34 | else -> holder.itemView.itemAccuracy.setTextColor(ContextCompat.getColor(context, R.color.orange)) 35 | } 36 | holder.itemView.itemName.text = currentItem.name 37 | holder.itemView.itemAccuracy.text = "Probability : ${(currentItem.accuracy * 100).toInt()}%" 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/model/PojoApi.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.model 2 | 3 | class PojoApi(val imageId: Int, val title: String, val desc: String, val id : Int) -------------------------------------------------------------------------------- /app/src/main/java/io/github/the_dagger/mlkit/model/Pokemon.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit.model 2 | 3 | data class Pokemon(val name: String, val accuracy: Float) -------------------------------------------------------------------------------- /app/src/main/res/drawable/barcode_scanning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/drawable/barcode_scanning.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/face_detection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/drawable/face_detection.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_upward.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_camera.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /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/drawable/ic_refresh.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/image_labelling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/drawable/image_labelling.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/landmark_identification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/drawable/landmark_identification.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/text_recognition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/drawable/text_recognition.png -------------------------------------------------------------------------------- /app/src/main/res/font/roboto_medium.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/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 | -------------------------------------------------------------------------------- /app/src/main/res/layout/face_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 25 | 26 | 35 | 36 | 45 | 46 | 55 | 56 | 65 | 66 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 26 | 27 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_row_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 19 | 20 | 28 | 29 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_card_scanner.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | 25 | 26 | 33 | 34 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_image_label.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_landmark.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | 25 | 26 | 33 | 34 | 40 | 41 | 48 | 49 | 55 | 56 | 63 | 64 | 70 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_qr_code_reader.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 17 | 18 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #384954 4 | #10222b 5 | #F0AD43 6 | #4CAF50 7 | #f44336 8 | #FF9800 9 | #58ADEA 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/font_certs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @array/com_google_android_gms_fonts_certs_dev 5 | @array/com_google_android_gms_fonts_certs_prod 6 | 7 | 8 | 9 | MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpFeVyxW0qMBujb8X8ETrWy550NaFtI6t9+u7hZeTfHwqNvacKhp1RbE6dBRGWynwMVX8XW8N1+UjFaq6GCJukT4qmpN2afb8sCjUigq0GuMwYXrFVee74bQgLHWGJwPmvmLHC69EH6kWr22ijx4OKXlSIx2xT1AsSHee70w5iDBiK4aph27yH3TxkXy9V89TDdexAcKk/cVHYNnDBapcavl7y0RiQ4biu8ymM8Ga/nmzhRKya6G0cGw8CAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6VTEM8YYY6FbBMvAPyT+CyoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJANWFuGx90071MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBABnTDPEF+3iSP0wNfdIjIz1AlnrPzgAIHVvXxunW7SBrDhEglQZBbKJEk5kT0mtKoOD1JMrSu1xuTKEBahWRbqHsXclaXjoBADb0kkjVEJu/Lh5hgYZnOjvlba8Ld7HCKePCVePoTJBdI4fvugnL8TsgK05aIskyY0hKI9L8KfqfGTl1lzOv2KoWD0KWwtAWPoGChZxmQ+nBli+gwYMzM1vAkP+aayLe0a1EQimlOalO762r0GXO0ks+UeXde2Z4e+8S/pf7pITEI/tP+MxJTALw9QUWEv9lKTk+jkbqxbsh8nfBUapfKqYn0eidpwq2AzVp3juYl7//fKnaPhJD9gs= 10 | 11 | 12 | 13 | 14 | MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDAeFw0wODA4MjEyMzEzMzRaFw0zNjAxMDcyMzEzMzRaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAKtWLgDYO6IIrgqWbxJOKdoR8qtW0I9Y4sypEwPpt1TTcvZApxsdyxMJZ2JORland2qSGT2y5b+3JKkedxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjAsb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/preloaded_fonts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @font/roboto_medium 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MlKit 3 | Detected Items 4 | A simple credit card scanner that reads the card number and expiry date 5 | Load and run a custom TensorflowLite model 6 | A simple QR code scanner 7 | Google Lens clone using MLKit 8 | Identify popular landmarks in an image 9 | Text recognition 10 | Custom Model 11 | Barcode scanning 12 | Image labeling 13 | Landmark recognition 14 | Location 15 | Latitude 16 | Longitude 17 | Accuracy 18 | Face Detection 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/test/java/io/github/the_dagger/mlkit/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.the_dagger.mlkit 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /art/screen01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/art/screen01.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.70' 5 | ext.mlkit_version = '16.0.0' 6 | repositories { 7 | google() 8 | jcenter() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.3.0-alpha10' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | classpath 'com.google.gms:google-services:4.0.1' 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | google() 23 | jcenter() 24 | maven { url "https://jitpack.io" } 25 | } 26 | } 27 | 28 | task clean(type: Delete) { 29 | delete rootProject.buildDir 30 | } 31 | -------------------------------------------------------------------------------- /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/the-dagger/MLKitAndroid/cde20d858ff46719b758dace1267fb3c96d45225/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 24 15:00:31 IST 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.10-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 ':app' 2 | --------------------------------------------------------------------------------