1

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


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
4

1 回答 1

0

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

如何做到这一点的可能方法是使用 win32api。

检查这一点:在 Windows 上使用 python 截屏的最快方法

于 2021-08-20T16:12:45.487 回答