get("#137") -- split get("#349") -- table functions get("#350") -- RecogUtil 2 function make_sig2letter() -- signatures from alphabet (#1000084) sigs = "121-121 121-121 232-121 2321-12121 121-121 12321-1212121 1321-1212121 121-1 12321-12121 12321-1212121 1-1" letters = "0123456789/" sigs, sig2letter = split(sigs, " "), {} for i=1, #sigs do sig = sigs[i] if sig2letter[sig] == nil then sig2letter[sig] = {} end table.insert(sig2letter[sig], letters:sub(i, i)) end end -- [014][014]23[014][59]678[59]/ :) function fix() local w, h, let = x2-x1, y2-y1, valuestokeys(letters) local cropped = { width = w, height = h, getInt = function(x, y) return img.getInt(x+x1, y+y1) end } -- distinguish 0 and 1 by middle width if let["0"] and let["1"] then local middleWidth = getWidth(cropped, math.floor(h/2)) let[middleWidth/h < 0.5 and "0" or "1"] = nil end if (let["0"] or let["1"]) and let["4"] then -- check the bottom (the "leg" of the 4) local yo, threshold = 8/9, 0.5 local avgLeft = getAverageLeft(cropped, math.floor(h*yo), h) if avgLeft/w >= threshold then let["0"], let["1"] = nil, nil else let["4"] = nil end end if let["5"] and let["9"] then -- check the top local yo, threshold = 1/9, (0.07+0.23)/2 local avgLeft = getAverageLeft(cropped, 0, math.floor(h*yo)) local flag = avgLeft/w >= threshold print("avgLeft", avgLeft/w, "threshold", threshold, "flag", flag) let[flag and "5" or "9"] = nil end letters = keystolist(let) end -- works on x1, lastX2 function isSpace() if lastX2 == nil then return false end local d = (x1-lastX2)/(y2-y1) --print("space dist", d) return d >= 0.3 end make_sig2letter() result = otherresults["#345"] or error("Need result of #345") _, _, s = string.find(result, ": (.+)") if s == nil then return end parts = split(s, "|") -- could also recalc this from parts sigs = otherresults["#340"] or error("Need result of #340") sigs = split(sigs, " ") result = {} for i=1, #sigs do sig = sigs[i] letters = sig2letter[sig] part = parts[i] lastX2 = x2 x1, y1, x2, y2 = unpack(split(part, ", ")) x1, y1, x2, y2 = tonumber(x1), tonumber(y1), tonumber(x2), tonumber(y2) if isSpace() then table.insert(result, " ") end s = "" if letters == nil then print("Unknown signature: "..sig) s = "?" else if #letters > 1 then fix() end if #letters == 1 then s = letters[1] else s = "["..table.concat(letters).."]" end end table.insert(result, s) end return table.concat(result)