rjp*_*998 5 python performance screenshot python-imaging-library
所以我需要每秒得到一堆截图,比如 5。我用它来为游戏编写一个机器人程序。但是 imagegrab 方法需要 0.3 秒,这对我来说太慢了。即使在指定 bbox 值之后,它仍然需要 0.3 秒。我想应该提到我在 mac 上。有没有更好的方法适合我
我什至尝试了os.system("screencapture filename.png")0.15-0.2 秒的运行时间,这很好,但我想更快。
And*_*kha 10
另一种解决方案是使用Python MSS。
from mss import mss
from PIL import Image
def capture_screenshot():
# Capture entire screen
with mss() as sct:
monitor = sct.monitors[1]
sct_img = sct.grab(monitor)
# Convert to PIL/Pillow Image
return Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
img = capture_screenshot()
img.show()
Run Code Online (Sandbox Code Playgroud)
此功能可以在我的慢速笔记本电脑上以高达 27 fps 的速度返回屏幕截图。
| 归档时间: |
|
| 查看次数: |
6357 次 |
| 最近记录: |