Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created November 24, 2019 03:07
Show Gist options
  • Save Lavanyagaur22/7cf2e8430dd002ce9200c82094acaf43 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/7cf2e8430dd002ce9200c82094acaf43 to your computer and use it in GitHub Desktop.
class ImageProcessor : ImageAnalysis.Analyzer {
var predictor: FritzVisionLabelPredictor? = null
val TAG = javaClass.simpleName
override fun analyze(image: ImageProxy?, rotationDegrees: Int) {
//Handle all the ML logic here
val mediaImage = image?.image
val imageRotation = ImageRotation.getFromValue(rotationDegrees)
val visionImage = FritzVisionImage.fromMediaImage(mediaImage, imageRotation)
val managedModel = ImageLabelManagedModelFast()
FritzVision.ImageLabeling.loadPredictor(
managedModel,
object : PredictorStatusListener<FritzVisionLabelPredictor> {
override fun onPredictorReady(p0: FritzVisionLabelPredictor?) {
Log.d(TAG, "Image Labeling predictor is ready")
predictor = p0
}
})
val labelResult = predictor?.predict(visionImage)
runOnUiThread {
labelResult?.resultString?.let {
val sname = it.split(":")
Log.e(TAG, it)
Log.e(TAG, sname[0])
tv_name.text = sname[0]
} ?: kotlin.run {
tv_name.visibility = TextView.INVISIBLE
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment