爬虫——图像识别和文字处理(代码极少)

1、了解什么是OCR技术
2、掌握安装Tesseract工具,掌握安装pytesseract库和PIL库
3、掌握PIL和pytesseract库的基本使用
4、掌握使用pytesseract识别和处理字符
5、掌握使用pytesseract识别简单的图形验证码

1、编写一个程序,读取图像中格式规范的文字。

# 导入模块
import pytesseract
from PIL import Image
# 将图像文件转换成Image实例
image = Image.open('test.png')
# 将图像中的文本转换成文本,进行输出
text = pytesseract.image_to_string(image)
print(text)

2、编写一个程序,读取带有渐变背景图像的文字。

import pytesseract
from PIL import Image

image=Image.open('test2.png')
image=image.point(lambda x: 0 if x<120 else 255)
text=pytesseract.image_to_string(image)
image.save('test_copy.png')
print(text)

3、编写一个程序,读取图像中格式规范的中文字符。

from pytesseract import *
from PIL import Image
data=Image.open("test4.png")
text=image_to_string(data,lang="chi_sim")
print(text)

4.编写一个程序,识别简单图形验证码。

from random import randint
import pytesseract
from PIL import Image
picName=str(randint(0,9))+'.png'
image=Image.open('img/'+picName)
text=pytesseract.image_to_string(image)
print(picName+":"+text)

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2022年5月27日
下一篇 2022年5月27日

相关推荐