Last active
September 20, 2018 12:35
-
-
Save tomekdz/c1e8f1e1ca21a735b4ababe4a3feaf03 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
override fun process(bitmap: Bitmap): List<Detection> { | |
convertBitmapToByteBuffer(bitmap) | |
tensorflow.run(imgData, output) | |
return processOutput(output) | |
} | |
private fun convertBitmapToByteBuffer(bitmap: Bitmap) { | |
imgData.rewind() | |
val resizedBitmap = Bitmap.createScaledBitmap(bitmap, 416, 416, true) | |
resizedBitmap.getPixels(intValues, 0, resizedBitmap.width, 0, 0, resizedBitmap.width, resizedBitmap.height) | |
// Convert the image to floating point. | |
var pixel = 0 | |
for (i in 0 until 416) { | |
for (j in 0 until 416) { | |
val value = intValues[pixel++] | |
addPixelValue(value) | |
} | |
} | |
} | |
private fun addPixelValue(pixelValue: Int) { | |
imgData.putFloat(((pixelValue shr 16 and 0xFF) - IMAGE_MEAN) / IMAGE_STD) | |
imgData.putFloat(((pixelValue shr 8 and 0xFF) - IMAGE_MEAN) / IMAGE_STD) | |
imgData.putFloat(((pixelValue and 0xFF) - IMAGE_MEAN) / IMAGE_STD) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment