Created
October 15, 2018 07:14
-
-
Save tsh-code/a2147d69ddce8099fa30415baa36c633 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 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