有没有办法从窗口句柄中截取特定的窗口?即使窗口在后台,它仍然会捕捉到它。目前我只有这个代码来记录全屏桌面,而不是在特定的窗口中。
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
发布于 2021-08-20 16:12:45
嗨,我正在寻找和你一样的答案,看起来mss不能这样做。
如何做到这一点的可能方法是使用win32api。
检查这个:Fastest way to take a screenshot with python on windows
https://stackoverflow.com/questions/68842206
复制相似问题