用 tesseract OCR 从图片提取文字
在 Linux 上用免费离线的 Tesseract OCR,把截图、照片和扫描件变成可编辑的文本文件。
运行 tesseract screenshot.png output -l eng,识别结果会写入 output.txt。
01命令
命令
$ tesseract screenshot.png output -l eng --psm 302作用说明
Tesseract 会读取图片并把识别出的文字写入 output.txt(扩展名自动添加)。-l 选择语言——简体中文需要安装 tesseract-ocr-chi-sim 语言包,并可用 -l chi_sim+eng 同时识别中英文。--psm 控制版面分析模式:默认 3 适合整页文档,6(统一文本块)或 7(单行)更适合裁剪过的截图。图像清晰、对比度高时准确率会好很多——模糊的照片可以先用 ImageMagick 预处理(convert in.png -colorspace Gray -resize 300% out.png)。
03风险
!注意: OCR 不可能百分之百准确:人名、数字和代码类文本务必人工校对,手写体、艺术字和低分辨率照片尤其容易出错。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- tesseract(1) — Ubuntu manual page依据: Documents tesseract imagename outputbase [-l lang] [--psm pagesegmode] for OCR of image files.
- tesseract-ocr/tesseract — GitHub依据: Official repository describing supported languages, language data installation, and page segmentation modes.
最后验证: 2026-09-18 · 分类: 媒体