Skip to content

Instantly share code, notes, and snippets.

@miquelbeltran
Created September 7, 2018 11:44
Show Gist options
  • Save miquelbeltran/e6473e883d87b3ae653b3d8353527826 to your computer and use it in GitHub Desktop.
Save miquelbeltran/e6473e883d87b3ae653b3d8353527826 to your computer and use it in GitHub Desktop.
// 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