Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created October 15, 2018 07:14
Show Gist options
  • Save tsh-code/e35b299bf2f629c1ff72aff90b1d4add to your computer and use it in GitHub Desktop.
Save tsh-code/e35b299bf2f629c1ff72aff90b1d4add to your computer and use it in GitHub Desktop.
val blocks = text.blocks
val blocksRect = blocks.mapNotNull { it.boundingBox }
val lines = blocks.flatMap { it.lines }
val linesRect = lines.mapNotNull { it.boundingBox }
val elements = lines.flatMap { it.elements }
val elementsRect = elements.mapNotNull { it.boundingBox }
// copy bitmap and make it mutable if necessary (optional step)
// depends on how do you get your bitmap
val mutableBitmap = inputBitmap.copy(inputBitmap.config, true)
// draw all bounding boxes on bitmap
with(Canvas(mutableBitmap)) {
blocksRect.forEach { drawRect(it, blocksPaint) }
linesRect.forEach { drawRect(it, linesPaint) }
elementsRect.forEach { drawRect(it, elementsPaint) }
}
imageView.setImageBitmap(mutableBitmap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment