Created
March 29, 2020 17:39
-
-
Save ionutale/bb66400d83b829131a6f8508c5f17c73 to your computer and use it in GitHub Desktop.
GCP Vision OCR - extract text from selection
This file contains 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
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