Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #481 // Haiku font recognizer (include)

Lua code

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

Author comment

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 recognition results

hide nils
Image Result Result calculated
#1000176 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000014 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000181 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#93 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 02:54:48

[raw result]
[visualize]
#1000184 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000183 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000182 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000168 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000147 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000128 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#84 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 02:54:48

[raw result]
[visualize]
#1000180 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#87 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 02:54:48

[raw result]
[visualize]
#1000152 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000140 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000179 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000175 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000163 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000177 nil 2016-08-01 02:54:48
Lua instructions: 2k

[raw result]
[visualize]
#1000081 nil 2016-08-01 02:54:48
Lua instructions: 2k

[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: 1161 / 175
Referenced in: [show references]