本帖最后由 wkdxz 于 2023-12-6 11:08 编辑
[Python] 纯文本查看 复制代码 #前两天才写了个,送你了
import io
import ddddocr
import pyautogui
def capture_screen(left, top, width, height):
'''截取图片为二进制数据'''
screenshot = pyautogui.screenshot(region=(left, top, width, height))
img_bytes = io.BytesIO()
screenshot.save(img_bytes, format='PNG')
img_bytes.seek(0)
return img_bytes.read()
ocr = ddddocr.DdddOcr()
# 验证码图片的左上角坐标(left, top),和图片的宽,高(width, height)
img_bytes = capture_screen(1296, 660, 135, 51)
res = ocr.classification(img_bytes)
print('验证码:', res)
|