起因:最近在写一个py脚本需要登录一个网站,网站上有一个简单的数字验证码需要识别。
在Linux下识别图片可以使用tesseract来实现。
以Centos7为例,网上很多下载源码编译安装的,其实可以直接用yum来安装

yum -y install epel-release
yum -y install tesseract

我这里需要的是识别单个数字,以此为例,可以使用

tesseract num.jpg test -psm 10 digits

然后会在当前目录下生成一个test.txt,打开查看里面的识别结果就可以了。
-psm参数可以指定识别模式,Mode10就是把整个图像当作单个字符来识别。下面是所有十个模式的介绍,可以依自己需求选择模式。

0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.

本文作者:小欢

本文链接:Linux识别图片 - https://www.xh-ws.com/archives/linux_recognize_picture.html

版权声明:如无特别声明,本文即为原创文章,仅代表个人观点,版权归 小欢博客 所有,遵循知识共享署名-相同方式共享 4.0 国际许可协议。转载请注明出处!