1 | get("#348") -- rgb functions |
2 | get("#480") -- horizontalsplit (v2) |
3 | |
4 | -- all the language names on #1000176 |
5 | tree = {0, 0, {0, 1, {0, 2, {0, 6, {0, 7, {0, 9, {4, 0, {1, 1, "p", "l"}, {1, 4, "h", {1, 6, "k", "l"}}}, {7, 0, {5, 0, {1, 0, "E", "I"}, {4, 0, {1, 0, {1, 8, "B", "F"}, "I"}, {1, 1, "M", {1, 8, "L", "I"}}}}, {6, 0, {4, 0, {1, 0, "F", "I"}, {1, 0, "N", {1, 4, "H", {1, 8, "L", "I"}}}}, {5, 0, {1, 0, "E", "I"}, {4, 0, {1, 0, {1, 4, {1, 8, "B", "F"}, "D"}, "I"}, {1, 8, "L", "I"}}}}}}, {6, 0, {4, 1, "m", "r"}, {4, 0, "n", "r"}}}, {4, 7, "v", "u"}}, "y"}, "i"}, {0, 1, {0, 2, {0, 3, {5, 0, "g", "o"}, "s"}, "a"}, {0, 2, {0, 3, {0, 5, "u", {4, 0, "e", "c"}}, "t"}, {0, 3, "n", {0, 4, {0, 6, "d", "s"}, {0, 5, "C", "a"}}}}}} |
6 | |
7 | function haikurecognize(img) |
8 | local parts = horizontalsplit(img) |
9 | |
10 | -- returns a list of characters |
11 | local function decide(tree, img) |
12 | if type(tree) == 'string' then -- leaf (single character) |
13 | return {tree} |
14 | elseif type(tree[1]) == 'number' then -- node (decision point) |
15 | local w, h = img.width, img.height |
16 | local x, y, plus, minus = unpack(tree) |
17 | local set = x < w and y < h and bright(rgb(img.getInt(x, y))) <= 0.5 |
18 | return decide(set and plus or minus, img) |
19 | else -- leaf (list of characters) |
20 | return tree |
21 | end |
22 | end |
23 | |
24 | -- iterate over parts |
25 | local result = {} |
26 | for _, r in ipairs(parts) do |
27 | local x1, y1, x2, y2 = r.x, r.y, r.x+r.width, r.y+r.height |
28 | |
29 | local cimg = {width=x2-x1+1, height=y2-y1+1, |
30 | getInt = function(x, y) |
31 | return (x < x2-x1 and y < y2-y1) and img.getInt(x1+x, y1+y) or 0xFFFFFF |
32 | end} |
33 | local chars = decide(tree, cimg) |
34 | table.insert(result, #chars == 1 and chars[1] or "["..table.concat(chars).."]") |
35 | end |
36 | |
37 | return table.concat(result) |
38 | end |
Began life as a copy of #477
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Image | Result | Result calculated |
---|---|---|
#93 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:48 [raw result] [visualize] |
#84 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:48 [raw result] [visualize] |
#87 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:48 [raw result] [visualize] |
Snippet ID: | #481 |
Snippet name: | Haiku font recognizer (include) |
Eternal ID of this version: | #481/1 |
Text MD5: | ad4cd5b366d27ef7bd7a8676030ab0e9 |
Author: | stefan |
Category: | |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-02-26 00:19:43 |
Source code size: | 1807 bytes / 38 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 1159 / 174 |
Referenced in: | [show references] |