first :1、使用pyautogui截图+拼接 2、使用lackey 截图+识别
import pyautogui """整凭截图""" im1 = pyautogui.screenshot() im2 = pyautogui.screenshot('my_screenshot.png') """区域截图""" import pyautogui im = pyautogui.screenshot(region=(0,0, 300, 400))
import pyautogui from PIL import Image time.sleep(5) # 截取屏幕的一部分 screenshot1 = pyautogui.screenshot(region=(0, 0, 500, 500)) screenshot2 = pyautogui.screenshot(region=(500, 0, 500, 500))# 将截图转换为PIL图像 screenshot1 = screenshot1.convert("RGB") screenshot2 = screenshot2.convert("RGB")# 打开两张截图 screenshot1 = screenshot1.crop((0, 0, 500, 500)) screenshot2 = screenshot2.crop((0, 0, 500, 500)) screenshot1.save("screenshot1.png")
screenshot2.save("screenshot2.png")
# 创建一个新图像,大小为(1000, 500),模式为"RGB" new_screenshot = Image.new("RGB", (1000, 500))# 拼接两张截图 new_screenshot.paste(screenshot1, (0, 0)) new_screenshot.paste(screenshot2, (500, 0))# 保存新图像 new_screenshot.save('combined_screenshot.png')
import lackeylackey.Region(194,329,286,50).saveScreenCapture(r"E:\humanDocter",name="namecheck")
import lackey import time import pytesseract from PIL import Imagetime.sleep(3) lackey.Region(194,329,286,50).saveScreenCapture(r"E:\humanDocter",name="namecheck") img = Image.open(r"E:\humanDocter\namecheck.png") pytesseract.pytesseract.tesseract_cmd=r'C:\Program Files\Tesseract-OCR\tesseract.exe' content = pytesseract.image_to_string(img,lang="chi_sim") print(content)
识别需要依赖两个工具库,见其他作者文章,来源:https://blog.csdn.net/u010226586/article/details/131886684