Created
March 12, 2020 06:28
-
-
Save Lavanyagaur22/98a8d2b35a5bdb05ce44904fcecae113 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
private class YourImageAnalyzer : ImageAnalysis.Analyzer { | |
private fun degreesToFirebaseRotation(degrees: Int): Int = when(degrees) { | |
0 -> FirebaseVisionImageMetadata.ROTATION_0 | |
90 -> FirebaseVisionImageMetadata.ROTATION_90 | |
180 -> FirebaseVisionImageMetadata.ROTATION_180 | |
270 -> FirebaseVisionImageMetadata.ROTATION_270 | |
else -> throw Exception("Rotation must be 0, 90, 180, or 270.") | |
} | |
override fun analyze(imageProxy: ImageProxy?, degrees: Int) { | |
val mediaImage = imageProxy?.image | |
val imageRotation = degreesToFirebaseRotation(degrees) | |
if (mediaImage != null) { | |
val image = FirebaseVisionImage.fromMediaImage(mediaImage, imageRotation) | |
// Pass image to an ML Kit Vision API | |
// ... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment