Created
November 25, 2019 19:51
-
-
Save Lavanyagaur22/a5eef1eca7d40c0023c7509e4870270d 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
/* It allows us to define a custom class implementing the ImageAnalysis.Analyzer interface, | |
which will be called with incoming camera frames. | |
*/ | |
class ImageProcessor : ImageAnalysis.Analyzer { | |
var predictor: FritzVisionStylePredictor? = 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 = PaintingManagedModels.BICENTENNIAL_PRINT_MANAGED_MODEL | |
/* Load the FritzVision Style Transfer Predictor | |
*/ | |
FritzVision.StyleTransfer.loadPredictor( | |
managedModel, object : PredictorStatusListener<FritzVisionStylePredictor> { | |
override fun onPredictorReady(stylePredictor: FritzVisionStylePredictor?) { | |
Log.d(TAG, "Style Transfer predictor is ready") | |
predictor = stylePredictor | |
} | |
} | |
) | |
/* Get the FritzVisionStyleResult by running the predictor on the vision image. | |
*/ | |
val styleResult = predictor?.predict(visionImage) | |
/* Perform UI operations accordingly. | |
*/ | |
runOnUiThread { | |
Log.d(TAG, "UI thread") | |
val bitmap = styleResult?.toBitmap() | |
image_view.setImageBitmap(bitmap) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment