我正在学习本教程,本教程与屏幕交互,但由于ImageGrab在linux中不可用,因此是在Windows操作系统上完成的
import numpy as np
from PIL import ImageGrab
import cv2
import time
def screen_record():
last_time = time.time()
while(True):
# 800x600 windowed mode
printscreen = np.array(ImageGrab.grab(bbox=(0,40,800,640)))
print('loop took {} seconds'.format(time.time()-last_time))
last_time = time.time()
cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2RGB))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
对于ImageGrab有没有其他选择,或者更好地切换操作系统?
使用pyscreenshot库。它是linux系统的ImageGrab替代品。
希望这对你的代码有用。
相关问题 更多 >
编程相关推荐