Last active
May 16, 2020 09:29
-
-
Save kongkip/0cfb858f2b0afb49cbd9203dfb95d9b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
inner class Classify: ImageAnalysis.Analyzer { | |
@SuppressLint("SetTextI18n") | |
override fun analyze(imageProxy: ImageProxy?, rotationDegrees: Int) { | |
// get bitmap from the camera finder view | |
val imgBitmap = rotateImage(viewFinder.bitmap, | |
rotationDegrees.toFloat()) | |
val recognitions = imageClassifier!!.classifyImage( | |
imgBitmap, rotationDegrees) | |
runOnUiThread { | |
val empty = " " | |
textResult1!!.text = recognitions[0].title + empty + | |
String.format("%.2f%%", recognitions[0].confidence!! * 100.0f) | |
textResult2!!.text = recognitions[1].title + empty + | |
String.format("%.2f%%", recognitions[1].confidence!! * 100.0f) | |
textResult3!!.text = recognitions[2].title + empty+ | |
String.format("%.2f%%", recognitions[2].confidence!! * 100.0f) | |
} | |
} | |
} | |
// rotate image to its original position | |
private fun rotateImage(source: Bitmap, angle: Float): Bitmap { | |
val matrix = Matrix() | |
matrix.postRotate(angle) | |
return Bitmap.createBitmap(source, 0, 0, source.width, source.height, | |
matrix, true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment