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