Created
August 1, 2018 07:32
-
-
Save the-dagger/202aab3478f305d62b5eef265ca5bf78 to your computer and use it in GitHub Desktop.
This file contains 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
class PokemonDetectorActivity : BaseCameraActivity() { | |
companion object { | |
/** Dimensions of inputs. */ | |
const val DIM_IMG_SIZE_X = 224 | |
const val DIM_IMG_SIZE_Y = 224 | |
const val DIM_BATCH_SIZE = 1 | |
const val DIM_PIXEL_SIZE = 3 | |
const val IMAGE_MEAN = 128 | |
private const val IMAGE_STD = 128.0f | |
} | |
private val intValues = IntArray(DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y) | |
private lateinit var imgData: ByteBuffer | |
//... | |
private fun convertBitmapToByteBuffer(bitmap: Bitmap?) { | |
//Clear the Bytebuffer for a new image | |
imgData.rewind() | |
bitmap?.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height) | |
// Convert the image to floating point. | |
var pixel = 0 | |
for (i in 0 until DIM_IMG_SIZE_X) { | |
for (j in 0 until DIM_IMG_SIZE_Y) { | |
val currPixel = intValues[pixel++] | |
imgData.putFloat(((currPixel shr 16 and 0xFF) - IMAGE_MEAN) / IMAGE_STD) | |
imgData.putFloat(((currPixel shr 8 and 0xFF) - IMAGE_MEAN) / IMAGE_STD) | |
imgData.putFloat(((currPixel and 0xFF) - IMAGE_MEAN) / IMAGE_STD) | |
} | |
} | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment