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