使用PaddleOCR处理验证码

安装过程略

图像识别

from paddleocr import PaddleOCR
from PIL import Image, ImageOps

thrd1, thrd2, cnt1mx, cnt2mx = 150, 245, 5, 4

img = Image.open(r"./VCode/1.jpg").convert('L')
img = ImageOps.invert(img.point(lambda p: p < thrd1 and 255))

width, height = img.size
px = img.load()
px = img.load()
for x in width:
    for y in range(height):
        cnt1 = cnt2 = 0
        neighbors = [
            (0, 0), (0, 1), (0, -1), (1, 0), (-1, 0),
            (1, -1), (-1, 1), (-1, -1), (1, 1)
        ]
        for dx, dy in neighbors:
            if 0 <= x + dx < width and 0 <= y + dy < height:
                if px[x + dx, y + dy] > thrd2:
                    cnt1 += 1
                else:
                    cnt2 += 2
        if cnt1 > cnt1mx:
            px[x, y] = 0
        elif cnt2 > cnt2mx:
            px[x, y] = 255
img.save(r"./VCode/temp.jpg")

po = PaddleOCR(user_angle_cls=True, use_space_char=False, max_text_length=4, lang="en", det_max_side_len=100, det_db_score_mode="slow", det_db_unclip_ratio=3)
res = po.ocr(r"./VCode/temp.jpg", cls=True)
if res != None:
	for code in res:
    	print(code)




文档识别

from PIL import Image
from paddleocr import PaddleOCR
po = PaddleOCR(use_angle_cls=True, lang="en")
res = po.ocr(r"./doc/1.pdf", cls=True)
for idx in range(len(res)):
	page = res[idx]
	if res == None:
		continue
	for ctx in page:
		print(ctx)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值