Last active
July 11, 2018 06:30
-
-
Save eugeneek/6ba40f0bb6ed8a143d9b1d07df642fbb 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 RecognitionException( | |
| override val message: String | |
| ) : Throwable() | |
| class Recognizer( | |
| private val documentReder: DocumentReader | |
| ) { | |
| fun recognize(image: Bitmap, callback: ((RecognitionResult) -> Unit)) { | |
| documentReader.recognizeImage(image) { action, results, error -> | |
| if (error != null) { | |
| throw RecognitionException(error) | |
| } else { | |
| callback.invoke(RecognitionResult(action, results)) | |
| } | |
| } | |
| } | |
| } | |
| class DocPresenter( | |
| private val recognizer: Recognizer | |
| ) { | |
| private fun recognize(image: Bitmap) { | |
| try { | |
| recognizer.recognize(image) { result -> | |
| if (result.result.textResult == null) { | |
| onNotRecognized() | |
| } else { | |
| onRecognized(result.result) | |
| } | |
| } | |
| } catch (ex: RecognitionException) { | |
| XLogger.e(ex) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment