Skip to content

Instantly share code, notes, and snippets.

@makorowy
Created March 1, 2018 06:35
Show Gist options
  • Save makorowy/a0796620f3ba38f3cbb0f170e3ec6fee to your computer and use it in GitHub Desktop.
Save makorowy/a0796620f3ba38f3cbb0f170e3ec6fee to your computer and use it in GitHub Desktop.
TensorFlow Hot or Not example. Show the result.
class MainActivity : AppCompatActivity {
//...
private fun classifyAndShowResult(croppedBitmap: Bitmap) {
runInBackground(
Runnable {
val result = classifier.recognizeImage(croppedBitmap)
showResult(result)
})
}
@Synchronized
private fun runInBackground(runnable: Runnable) {
handler.post(runnable)
}
private fun showResult(result: Result) {
textResult.text = result.result.toUpperCase()
layoutContainer.setBackgroundColor(getColorFromResult(result.result))
}
@Suppress("DEPRECATION")
private fun getColorFromResult(result: String): Int {
return if (result == getString(R.string.hot)) {
resources.getColor(R.color.hot)
} else {
resources.getColor(R.color.not)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment