Estimating text height before OCR: connected components held up where projection didn't
A pre-OCR gate that decides whether to upscale a screenshot needs one number from the image itself: how tall the text is in pixels. The two cheapest ways to get it are a horizontal projection profile and connected components, both a few lines of OpenCV. On clean Chinese renders both stayed within 2 px of the true height up to 30 px; above that projection ran 3 to 5 px high and components 1 to 3…
A pre-OCR gate that determines whether to upscale a screenshot requires one crucial number from the image itself: the height of the text in pixels. Two inexpensive methods for obtaining this measurement are horizontal projection profiles and connected components, both achievable with just a few lines of OpenCV code. Under clean conditions, both techniques closely approximated the true text height.
When the text height ranged from 6 to 40 pixels for Chinese characters and from 6 to 60 pixels for English text, both methods remained within 2 pixels of the actual height. However, when the text height exceeded 60 pixels, the projection method consistently overestimated the text height by approximately 8%.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.