使用macos截屏

时间:2019-11-03 16:28:24

标签: python opencv pyautogui

使用python截屏时遇到问题。 我正在尝试快速截图以在cv2打开的窗口上获得较高的fps,但是要花很长时间才能截图

import numpy as np
import pyautogui
import cv2
import time

def screen_record():
    last_time = time.time()
    while True:
        screen = np.array(pyautogui.screenshot())
        print("loop took {} seconds".format(time.time() - last_time))
        last_time = time.time()
        cv2.imshow('window', screen)
        if cv2.waitKey(25) & 0xFF == ord("q"):
            cv2.destroyAllWindows()
            break

screen_record()
loop took 1.4119279384613037 seconds
loop took 2.31076979637146 seconds
loop took 5.383511066436768 seconds
loop took 6.175501108169556 seconds

如您所见,它需要很长时间来拍摄新的屏幕截图,所以我也尝试了使用其他软件包(例如PIL的ImageGrab),并且得到了相同的结果。

是否有理由如此截取屏幕截图?

谢谢,伊拉克。

0 个答案:

没有答案