Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE ⭐] Capture a certain area #80

Open
NeuralAIM opened this issue Sep 11, 2024 · 10 comments
Open

[FEATURE ⭐] Capture a certain area #80

NeuralAIM opened this issue Sep 11, 2024 · 10 comments

Comments

@NeuralAIM
Copy link

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()
@WHalcyon
Copy link

I'm not sure if there's a way to do this but as a workaround have you tried creating an entirely transparent and click-through application with your desired capture size and targeting that? Let me know if it works

@NiiightmareXD
Copy link
Owner

Hey, I'm not sure what causes the FPS drop, and crop() should be performant.

@Cyanide0210
Copy link

Cyanide0210 commented Sep 16, 2024

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator

Edit:
Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

@NiiightmareXD
Copy link
Owner

NiiightmareXD commented Sep 16, 2024

Ok, I'll check the performance to see if it's a API optimization or I can do it in the library itself because for now the underlying API doesn't allow capturing an area.

@Cyanide0210
Copy link

Cyanide0210 commented Sep 16, 2024

Ok, I'll check the performance to see if it's a API optimization or I can do it in the library itself because for now the underlying API doesn't allow capturing an area.

CopySubresourceRegion?

Edit: ahh, that is probably the same as Crop

@JiaPai12138
Copy link

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator

Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

@Cyanide0210
Copy link

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator
Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

@JiaPai12138
Copy link

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator
Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

Mine is 4060 RTX and 144hz monitor... should as least 100 fps any way

@NiiightmareXD
Copy link
Owner

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator
Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

Mine is 4060 RTX and 144hz monitor... should as least 100 fps any way

Sounds like some sort of bug somewhere

@JiaPai12138
Copy link

JiaPai12138 commented Sep 25, 2024

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator
Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

Mine is 4060 RTX and 144hz monitor... should as least 100 fps any way

Sounds like some sort of bug somewhere

I tried modified version of dxcam and get like 400 fps tops
but there seems to be some problems in my environment, some games will just crashed but runs fine on another one with gtx 1660 ti; plus when i install any software/driver from nvidia, it will just jump to installer failed instantly and i dont know how to fix
i will do a fresh reinstall of windows this weekend and retry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants