get("#348") -- rgb functions get("#480") -- horizontalsplit (v2) -- all the language names on #1000176 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"}}}}}} function haikurecognize(img) local parts = horizontalsplit(img) -- returns a list of characters local function decide(tree, img) if type(tree) == 'string' then -- leaf (single character) return {tree} elseif type(tree[1]) == 'number' then -- node (decision point) local w, h = img.width, img.height local x, y, plus, minus = unpack(tree) local set = x < w and y < h and bright(rgb(img.getInt(x, y))) <= 0.5 return decide(set and plus or minus, img) else -- leaf (list of characters) return tree end end -- iterate over parts local result = {} for _, r in ipairs(parts) do local x1, y1, x2, y2 = r.x, r.y, r.x+r.width, r.y+r.height local cimg = {width=x2-x1+1, height=y2-y1+1, getInt = function(x, y) return (x < x2-x1 and y < y2-y1) and img.getInt(x1+x, y1+y) or 0xFFFFFF end} local chars = decide(tree, cimg) table.insert(result, #chars == 1 and chars[1] or "["..table.concat(chars).."]") end return table.concat(result) end