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 限制输出字符集提高准确率

步骤:

  1. 用 curl 获取图片,保存到临时文件
1
2
3
4
$ curl -sL -b 'WC=你的cookie' \
-A 'Mozilla/5.0 Chrome/131' \
-o /tmp/ocr.png \
'https://www.wechall.net/challenge/can_you_readme/gimme.php'

得到的图片是 524x68 4-bit colormap PNG。

  1. 用 tesseract 做 OCR
1
2
3
$ tesseract /tmp/ocr.png stdout \
--psm 7 \
-c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyz

参数说明: - --psm 7 — Treat image as a single line of text(图片是一行文字) - tessedit_char_whitelist — 限制输出为小写字母,排除杂音

  1. 提交答案
1
2
3
$ curl -sL -b 'WC=你的cookie' \
-A 'Mozilla/5.0 Chrome/131' \
'https://www.wechall.net/challenge/can_you_readme/index.php?solution=识别结果&cmd=Answer'

如果页面显示 "Solved By N People" 则提交成功。

实际执行过程:

第一次 OCR 识别出部分文本 internetitselfanincr,步过短说明识别不完整。换一张新图片重试后得到完整结果:

1
2
3
$ tesseract /tmp/ocr.png stdout --psm 7 \
-c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyz
altoassigngloballyuniq

提交后确认 solved("Solved By 514 People")。

动态答案说明: 由于图片每 session 不同,实际 OCR 结果会变化。以上方法适用于任何 session,只需确保 tesseract 参数正确(尤其是 --psm 7)。

altoassigngloballyuniq