Skip to content

Instantly share code, notes, and snippets.

@eugeneek
Last active July 11, 2018 06:30
Show Gist options
  • Select an option

  • Save eugeneek/6ba40f0bb6ed8a143d9b1d07df642fbb to your computer and use it in GitHub Desktop.

Select an option

Save eugeneek/6ba40f0bb6ed8a143d9b1d07df642fbb to your computer and use it in GitHub Desktop.
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