相关文章推荐
文质彬彬的勺子  ·  unable to install ...·  2 年前    · 
没人理的油条  ·  ONNX小结 - 知乎·  3 年前    · 
阳光的香槟  ·  javascript fetch 同步-掘金·  3 年前    · 
爱跑步的长颈鹿  ·  c# - The property is ...·  3 年前    · 

python实时获取屏幕

在 Python 中实时获取屏幕截图的方法有很多,其中一种方法是使用 mss 库。mss 是一个用 Python 编写的跨平台库,它可以轻松地截取屏幕。

安装 mss:

pip install mss

示例代码:

import mss
import cv2
with mss.mss() as sct:
    # Get the screen shot of the 1st monitor
    sct_img = sct.grab(sct.monitors[0])
    # Convert to a OpenCV image
    img = np.array(sct_img)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    # Display the image
    cv2.imshow("Screenshot", img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

这段代码将截取第一个显示器的屏幕截图,然后使用 OpenCV 将其显示出来。

  •