get("#137") -- string split get("#349") -- table functions get("#350") -- RecogUtil 2 function make_sig2letter() -- first, signatures from alphabet (#1000080), then additional -- signatures for slightly varying instances, e.g. from #1000082 sigs = "121-1212 1321-12121 121-12121 121-121 1321-1 12-1 12321-12121 1-212 1-1 121-121 121-212 1-1 1-2343 1-232 121-121 121-121 12321-12121 12321-1212 12321-12121 1-1 1-21 12121-56787865 1-21 12321-1 12121-212 132321-12121" letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "VWX", "Y", "Z", "X", "B"} 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[i]) end end -- [ILT][ILT]N[UY]?RA[ILT]NCANREA[DPOJ] :) 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 I and T by width if let["I"] and let["T"] then let[w/h >= 0.5 and "I" or "T"] = nil end -- distinguish T and L by upper to lower width if let["T"] and let["L"] then let[upperToLowerWidth(cropped) < 1 and "T" or "L"] = nil end -- ...and so on... if let["I"] and let["L"] then let[upperToLowerWidth(cropped) <= 0.5 and "I" or "L"] = nil end if let["U"] and let["Y"] then local middleY = math.ceil(h/2) let[getWidth(cropped, middleY)/w <= 0.5 and "U" or "Y"] = nil end if (let["D"] or let["O"]) and let["P"] then if upperMaxWidth(cropped)/lowerMaxWidth(cropped) >= 2 then let["D"], let["O"] = nil, nil else let["P"] = nil end end if let["D"] and let["O"] then let[getAverageLeft(cropped)/w >= 0.05 and "D" or "O"] = nil end if (let["D"] or let["O"] or let["P"]) and let["J"] then if getAverageLeft(cropped, math.floor(h*0.33), math.floor(h*0.6))/w >= 0.5 then let["D"], let["O"], let["P"] = nil, nil, nil else let["J"] = nil end end if (let["G"] or let["S"]) and let["Q"] then if getAverageLeft(cropped, math.floor(h*8/9), h)/w >= 0.4 then let["G"], let["S"] = nil, nil else let["Q"] = nil end end if let["G"] and let["S"] then let[getLeftmostPoint(cropped, math.floor(h/2))/w >= 0.15 and "G" or "S"] = nil end letters = keystolist(let) end function isSpace() return lastX2 ~= nil and (x1-lastX2)/(y2-y1) >= 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, "|") sigs = split(otherresults["#340"] or error("Need result of #340"), " ") result = {} for i=1, #sigs do lastX2, sig, part = x2, sigs[i], parts[i] letters = sig2letter[sig] 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 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)