windows-capture
windows-capture copied to clipboard
[FEATURE ⭐] Capture a certain area
How can I capture a certain area? I can use crop() now, but I'm the only one losing FPS. How can I capture a part of the screen, similar to how it works when specifying window_name, where the application window is smaller than the screen size.
With window_name="Calculator"
:
FPS: 88.39
FPS: 84.82
FPS: 93.16
FPS: 80.45
With window_name=None
:
FPS: 34.94
FPS: 47.99
FPS: 48.00
FPS: 48.28
Code:
from windows_capture import WindowsCapture, Frame, InternalCaptureControl
from time import time
capture = WindowsCapture(
cursor_capture=False,
draw_border=False,
monitor_index=None,
#window_name="Calculator",
)
i = 0
s_time = time()
fps = 0
@capture.event
def on_frame_arrived(frame: Frame, capture_control: InternalCaptureControl):
global i, s_time, fps
i += 1
elapsed_time = time() - s_time
if elapsed_time >= 1: # Output FPS every second
fps = i / elapsed_time
print(f"FPS: {fps:.2f}")
i = 0 # Reset frame count
s_time = time() # Reset start time
@capture.event
def on_closed():
print("Capture Session Closed")
# capture.on_frame_arrived(width=128, height=128) - Well... I tried)
capture.start()