【问题标题】:Python MSS Screen Capture target specific windowsPython MSS 屏幕捕获目标特定窗口
【发布时间】:2021-08-19 04:50:58
【问题描述】:

有没有办法从窗口句柄截屏特定窗口?即使窗口在后台,它仍然会捕获它。目前我只有这个代码来记录全屏桌面,而不是在特定的窗口中。


def window_capture():
    # Define your Monitor
    x = 0
    y = 0
    w = 1920
    h = 1080
    
    hwnd = None

    with mss.mss() as sct:
        # Part of the screen to capture
        monitor = {"left": x, "top": y, "width": w, "height": h}
        img = sct.grab(monitor)
        img = np.array(img)
    return img



while "Screen capturing":
    # Define Time
    last_time = time()

    # Get the img
    screenshot = window_capture()

    # Display the picture
    cv.imshow('Computer Vision', screenshot)

    print(f'FPS {(1 / (time() - last_time))}')

    # Press "q" to quit
    if cv.waitKey(1) == ord("q"):
        cv.destroyAllWindows()
        break

【问题讨论】:

    标签: python python-mss


    【解决方案1】:

    您好,我正在寻找与您相同的答案,看来 mss 无法做到这一点。

    可能的方法是使用 win32api。

    检查这个:Fastest way to take a screenshot with python on windows

    【讨论】:

    • 好的,谢谢,顺便说一句,win32api 比 mss 快吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    相关资源
    最近更新 更多