一、验证码处理效果展示
verify.jpg deal.png result.png
?
??
?? ?? ??
????? ??
?????? ???? ????????? ??????
??????? ???????? ?? ??????
???? ?? ??? ??? ???? ??
??? ?? ??? ??? ?? ?? ??
??? ?? ??? ??? ? ? ??
??? ??????? ??? ??? ?????
????? ???????? ???? ??? ??????? ??
??????? ?? ????????? ????
???? ?? ???? ??? ???
??? ?? ??? ???
??? ?? ??? ???
??? ???? ???
????? ???? ?????
?????? ?????? ?????
???? ??? ???
? ? ?
二、代码展示
import time
import cv2
from PIL import Image
import easyocr
import numpy as np
import cap
def get_resut(photo, driver):
deal = 'deal.jpg'
img1 = cv2.imread(photo)
single = []
for i in img1.tolist():
pic_y = ''
pic = []
for j in i:
sums = sum(j)
x, y, z = j
if 100 < sums < 300 and x < 80 and y > 40 and z < 80:
pic_y += '?'
pic.append(j)
else:
pic_y += ' '
pic.append([255, 255, 255])
print(pic_y)
single.append(pic)
sz = np.array(single, np.uint8)
img2 = Image.fromarray(sz)
img2.save(deal)
img3 = cv2.imread(deal)
dst = cv2.fastNlMeansDenoisingColored(img3, None, 40, 3, 0, 4)
_, img4 = cv2.threshold(dst, 200, 255, cv2.THRESH_BINARY)
binary = Image.fromarray(cv2.cvtColor(img4, cv2.COLOR_BGR2RGB))
binary.save('result.png', quality=80)
|