Last active
March 1, 2018 07:14
-
-
Save makorowy/cc10970e8688fa108568e7558073befa to your computer and use it in GitHub Desktop.
TensorFlow Hot or Not example. Classification of the taken photo.
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 val handler = Handler() | |
private var photoFilePath = "" | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
val file = File(photoFilePath) | |
if (requestCode == REQUEST_TAKE_PICTURE && file.exists()) { | |
classifyPhoto(file) | |
} | |
} | |
private fun classifyPhoto(file: File) { | |
val photoBitmap = BitmapFactory.decodeFile(file.absolutePath) | |
val croppedBitmap = ImageUtils.getCroppedBitmap(photoBitmap) | |
classifyAndShowResult(croppedBitmap) | |
imagePhoto.setImageBitmap(photoBitmap) | |
} | |
private fun classifyAndShowResult(croppedBitmap: Bitmap) { | |
runInBackground( | |
Runnable { | |
val result = classifier.recognizeImage(croppedBitmap) | |
//show result | |
}) | |
} | |
@Synchronized | |
private fun runInBackground(runnable: Runnable) { | |
handler.post(runnable) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment