Created
September 7, 2018 11:44
-
-
Save miquelbeltran/e6473e883d87b3ae653b3d8353527826 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ML Kit Input | |
val inp = arrayOf(FloatArray(784) { 0f }) | |
// Read our Bitmap | |
val bitmap = BitmapFactory.decodeStream(assets.open("three.bmp")) | |
// Read pixels | |
val intValues = IntArray(784) | |
bitmap.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height) | |
intValues.forEachIndexed { index, i -> | |
// Take one color channel, convert it to float, and divide it by 265 to obtain a [0, 1] value | |
val f = (i and 0xFF).toFloat() | |
inp[0][index] = f / 256 | |
} | |
// Pass the inputs | |
val inputs = FirebaseModelInputs.Builder().add(inp).build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment