WeChall - Can you read me
Challenge
A friend and me have a bet running, that you won't beat his OCR program in scanning text out of images. His average scan time is 2.5 seconds, can you beat that?
挑战页面显示一张包含扭曲文本的图片,需要编写或使用 OCR 工具来识别其中的文字。目标是比 WeChall 声称的 2.5 秒平均扫描时间更快地识别出来。
Solution
答案每 session 动态生成(每次请求 /gimme.php
获得新的图片),所以不能硬编码,必须每次重新 OCR。
工具链:
- curl — 下载挑战图片,需要携带 cookie 和浏览器 UA
- tesseract — OCR 引擎,参数
--psm 7将图片视为单行文本(一行扭曲文字),配合tessedit_char_whitelist限制输出字符集提高准确率
步骤:
- 用 curl 获取图片,保存到临时文件
1 | $ curl -sL -b 'WC=你的cookie' \ |
得到的图片是 524x68 4-bit colormap PNG。
- 用 tesseract 做 OCR
1 | $ tesseract /tmp/ocr.png stdout \ |
参数说明: - --psm 7 — Treat image as a single line of
text(图片是一行文字) - tessedit_char_whitelist —
限制输出为小写字母,排除杂音
- 提交答案
1 | $ curl -sL -b 'WC=你的cookie' \ |
如果页面显示 "Solved By N People" 则提交成功。
实际执行过程:
第一次 OCR 识别出部分文本
internetitselfanincr,步过短说明识别不完整。换一张新图片重试后得到完整结果:
1 | $ tesseract /tmp/ocr.png stdout --psm 7 \ |
提交后确认 solved("Solved By 514 People")。
动态答案说明: 由于图片每 session 不同,实际 OCR
结果会变化。以上方法适用于任何 session,只需确保 tesseract
参数正确(尤其是 --psm 7)。