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

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)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

青柠Löwenzahn m.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值