问题描述
使用PIL或cv2等模块在python中捕获屏幕的最有效方法是什么?因为它占用了很多内存。
我想教AI通过屏幕抓取和整洁来玩Chrome的恐龙游戏,但这是减慢速度的方法...
我尝试过:
import numpy as np
from PIL import ImageGrab
import cv2
import time
last_time = time.time()
while True:
printscreen_pil = ImageGrab.grab(bbox= (0,40,800,640))
printscreen_numpy = np.array(printscreen_pil.getdata(),dtype = 'uint8').reshape((printscreen_pil.size[1],printscreen_pil.size[0],3))
print(f'the loop took {time.time() - last_time} seconds')
last_time = time.time()
cv2.imshow('window',printscreen_numpy)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
>
# average time = the loop took 2.068769931793213 seconds
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)