Created
March 1, 2018 06:35
-
-
Save makorowy/a0796620f3ba38f3cbb0f170e3ec6fee to your computer and use it in GitHub Desktop.
TensorFlow Hot or Not example. Show the result.
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 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