I'm using Tesseract to OCR images to read puzzle data. The problem is that Tesseract squashes whitespace so messes with the positions of the found characters. It does have an option to output the bounding box coordinates for each of the characters, but I'm not sure how to convert that back to a row/column to produce the original puzzle positions. An example input image: https://i.imgur.com/dspLfTI.png and the resulting box data is:
N 68 115 79 127 0 K 120 115 128 127 0 A 145 115 155 127 0 L 246 115 253 127 0 B 46 91 54 103 0 I 69 91 77 103 0 C 95 91 103 103 0 C 119 91 127 103 0 Y 145 91 154 103 0 D 169 91 179 103 0 I 195 91 203 103 0 T 218 91 228 103 0 Z 245 91 255 103 0 I 269 91 277 103 0 I 45 65 49 77 0 I 45 65 54 77 0 O 68 65 79 77 0 L 96 65 103 77 0 I 119 65 127 77 0 E 146 65 153 77 0 D 169 65 179 77 0 P 197 65 204 77 0 B 220 65 228 77 0 H 245 65 255 77 0 O 268 65 279 77 0 S 295 65 304 77 0 I 45 41 53 53 0 I 69 41 77 53 0 L 96 41 103 53 0 V 120 41 129 53 0 E 146 41 153 53 0 V 170 41 179 53 0 N 194 41 205 53 0 U 219 41 229 53 0 Y 245 41 254 53 0 Z 269 41 279 53 0 L 296 41 303 53 0 T 18 15 28 27 0 S 45 15 54 27 0 E 70 15 77 27 0 C 95 15 103 27 0 I 119 15 123 27 0 I 119 15 128 27 0 E 146 15 153 27 0 N 168 15 179 27 0 E 196 15 203 27 0 O 218 15 229 27 0 T 244 15 254 27 0 Y 269 15 278 27 0 U 295 15 305 27 0 E 320 15 327 27 0
(Note that tesseract assigns 0,0 to the lower left corner)

I can parse that using something like:

for my $line (split "\n", $boxdata) { my ($chr, $x1, $y1, $x2, $y2, $page) = $line =~ m{ ^ (\S) \ (\d+) \ (\d+) \ (\d+) \ (\d+) \ (\d+) $ }x; }
But I need to figure out how to convert that to this:
my @grid = ( [split '', ' N KA L '], [split '', ' BICCYDITZI '], [split '', ' ROLIEDPBHOS '], [split '', ' IILVEVNUYZL '], [split '', 'TSECRENEOTYUE'], ); p @grid; [ [0] [ [0] " ", [1] " ", [2] "N", [3] " ", [4] "K", [5] "A", [6] " ", [7] " ", [8] " ", [9] "L", [10] " ", [11] " ", [12] " " ], [1] [ [0] " ", [1] "B", [2] "I", [3] "C", [4] "C", [5] "Y", [6] "D", [7] "I", [8] "T", [9] "Z", [10] "I", [11] " ", [12] " " ], [2] [ [0] " ", [1] "R", [2] "O", [3] "L", [4] "I", [5] "E", [6] "D", [7] "P", [8] "B", [9] "H", [10] "O", [11] "S", [12] " " ], [3] [ [0] " ", [1] "I", [2] "I", [3] "L", [4] "V", [5] "E", [6] "V", [7] "N", [8] "U", [9] "Y", [10] "Z", [11] "L", [12] " " ], [4] [ [0] "T", [1] "S", [2] "E", [3] "C", [4] "R", [5] "E", [6] "N", [7] "E", [8] "O", [9] "T", [10] "Y", [11] "U", [12] "E" ] ]

In reply to Converting tesseract box data into 2d grid by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.