linux中的ImageGrab替代方案

2024-04-27 20:46:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习本教程,本教程与屏幕交互,但由于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有没有其他选择,或者更好地切换操作系统?


Tags: fromimportnumpypil屏幕timelinuxwindows