[英]ImageGrab alternative in linux
我正在關注本教程,該教程與屏幕交互但適用於 Windows 操作系統,因為 ImageGrab 在 linux 中不可用
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 替代品。
import pyscreenshot as ImageGrab
im = ImageGrab.grab()
im2 = np.asanyarray(im)
希望這對您的代碼有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.