import time
import numpy as np
from mss import mss
import cv2
// 定义窗口位置和大小
bounding_box = {'top': 66, 'left': 0, 'width': 858, 'height': 466}
sct = mss()
timer = time.time()
while True:
start = time.time()
sct_img = sct.grab(bounding_box)
cv2.imshow('window', np.array(sct_img))
end = time.time()
if time.time() - timer >= 1:
seconds = end - start
fps = 1 / seconds
timer = time.time()
print(f"time taken: {seconds} seconds (fps: {fps})")
if (cv2.waitKey(25) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
Python和OpenCV相结合实现相关录屏功能
于 2022-03-01 14:08:08 首次发布