Created
November 24, 2019 03:07
-
-
Save Lavanyagaur22/7cf2e8430dd002ce9200c82094acaf43 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
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