!752 static Map chars; sbool debug; static int luaMaxSteps = 10*1000*1000; sS code = [[ -- Input: -- iw = image of word to recognize -- chars = images of characters & description -- Output: -- what is recognized (a string) -- helper function function preciseMatch(ic, iw, x1) local w, h = iw.w, iw.h if ic.h ~= h then return false end local x2 = x1+ic.w if x2 > w then return false end for x = x1, x2-1 do for y = 0, h-1 do if ic.getBrightness(x-x1, y) ~= iw.getBrightness(x, y) then return false end end end return true end -- main algorithm local buf = {} for x=0, iw.w-1 do for ic, c in pairs(chars) do if preciseMatch(ic, iw, x) then table.insert(buf, c) x = x + ic.w-1 goto xloop end end ::xloop:: end return table.concat(buf) -- done ]]; static S recognizeWord(BWImage iw, O infos) { chars = (Map) quickImport(get(infos, "chars")); debug = isTrue(getOpt(infos, "debug")); luaMaxSteps(luaMaxSteps); ret evalLua(makeSandbox(iw), code).tojstring(); } static Sandbox makeSandbox(final BWImage img) { new LuaTable lChars; int i = 0; for (BWImage ic : keys(chars)) { //lChars.set(++i, bwImageToLua(ic)); //lChars.set(++i, Lua.value(chars.get(ic))); lChars.set(bwImageToLua(ic), Lua.value(chars.get(ic))); } ret luaSandbox( "iw", bwImageToLua(img), "chars", lChars); }