Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ionutale/bb66400d83b829131a6f8508c5f17c73 to your computer and use it in GitHub Desktop.
Save ionutale/bb66400d83b829131a6f8508c5f17c73 to your computer and use it in GitHub Desktop.
GCP Vision OCR - extract text from selection
function textInsideRect (xMin, yMin, xMax, yMax) {
return blocks.map( block => {
return block.paragraphs.map( p => {
return {
words: p.words.map( word => {
return word.symbols.map( symbol => {
// we are drawing only rects
// compare only the first and the 3 vertice
// this should do the job
if (
(symbol.boundingBox.vertices[0].x >= xMin
&& symbol.boundingBox.vertices[0].y >= yMin)
&&
(symbol.boundingBox.vertices[2].x <= xMax
&& symbol.boundingBox.vertices[2].y <= yMax)
) return symbol.text
return null
}).join('')
})
}
})
}).flat()
}
const result = textInsideRect(0, 0, 782, 300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment