from mss import mss
import numpy as np
import cv2 as cv
import time
with mss() as sct:
rect = sct.monitors[0]
while True:
stime = time.time()
sct_img = np.array(sct.grab(rect))
cv.imshow('frame', sct_img)
if cv.waitKey(1) == ord('q'):
break
cv.destroyAllWindows()
python-opencv
不允许您这样做,但您可以使用例如mss
(pip install mss
):