Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created October 15, 2018 07:14
Show Gist options
  • Save tsh-code/a2147d69ddce8099fa30415baa36c633 to your computer and use it in GitHub Desktop.
Save tsh-code/a2147d69ddce8099fa30415baa36c633 to your computer and use it in GitHub Desktop.
class TextDetector {
private val detector = FirebaseVision.getInstance().visionTextDetector
private val detectionOutput = PublishProcessor.create<FirebaseVisionText>()
private val frameInput = PublishProcessor.create<Bitmap>()
init {
frameInput.map { it.toFirebaseVisionImage() }
.flatMap(::detect)
.subscribe(detectionOutput)
}
fun processImage(image: Bitmap) {
frameInput.offer(image)
}
fun observeDetections(): Flowable<FirebaseVisionText> = detectionOutput
fun detect(visionImage: FirebaseVisionImage): Flowable<FirebaseVisionText> =
detector.detectInImage(visionImage).toFlowable()
}
fun Bitmap.toFirebaseVisionImage(): FirebaseVisionImage = FirebaseVisionImage.fromBitmap(this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment