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

Performance improvements #1

Merged
merged 8 commits into from
Apr 26, 2023
Merged

Performance improvements #1

merged 8 commits into from
Apr 26, 2023

Conversation

ninjatall12
Copy link

Forked from ra1nty#62.

Could you please create a compiled version of the above, pull requester states significant gains were made after optimisations would be great if you created a dxshot version.(Please include python 3.11)

Agade09 added 8 commits April 15, 2023 10:04
In profiling a benchmark code this takes processing overhead from ~14% to ~1.4% and ~0.06% respectively
…ller than the whole screen.

The idea is to ask ctypes.string_at for as little memory as possible. Since images are stored in memory with width being the fast index. If we want to grab a 480x640 region from a 1440x2560 screen we can ask ctypes.string_at() for a 480x2560 region. This reduces memory allocation and memcpy overhead in ctypes.string_at().
To grab a 480x640 region out of a 1440x2560 screen the profiler time spent went from ~24% to ~8%.
…ere its width region matches the screen's width.
…rom_address API instead. In profiling a 1440x2560 grab, total time spent went from 20% in string_at() to almost 0% in from_address. My understanding is that string_at uses memove which is slower than the memcpy I suspect from_address uses.
…that case self.region is used, and self.region was already validated when it was defined.

In profiling a max FPS benchmark with no region defined, this spares 3% of total execution time.
… if statement bypassed the call to self.process_cvtcolor(). Simplify code in process_cvtcolor since it no longer needs to handle 'BGRA''.

In profiling this spares 0.4% of total execution time in 'BGRA' mode.
…but it was producing a non-contiguous array, which changes the behavior of the library
@AI-M-BOT AI-M-BOT merged commit a0964dc into AI-M-BOT:main Apr 26, 2023
@ninjatall12
Copy link
Author

@AI-M-BOT

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Overwatch\dxcam\dxcam.py", line 203, in __capture
File "C:\Users\Administrator\Desktop\Overwatch\dxcam\dxcam.py", line 109, in _grab
File "C:\Users\Administrator\Desktop\Overwatch\dxcam\processor\base.py", line 15, in process
File "C:\Users\Administrator\Desktop\Overwatch\dxcam\processor\numpy_processor.py", line 64, in process
File "C:\Users\Administrator\Desktop\Overwatch\dxcam\processor\numpy_processor.py", line 36, in process_cvtcolor
File "C:\Users\Administrator\Desktop\Overwatch\dxcam\processor\numpy_processor.py", line 28, in
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Hi I spoke agade about this issue and it seems to be related to your new release and not his source he has tested the python version 3.10 and had the same issue i tested python 3.11?

@AI-M-BOT
Copy link
Owner

AI-M-BOT commented May 3, 2023

I used CopySubresourceRegion maybe that's the issue comes from? But no issue on my computer at all...
And yes c++ version is a better choice, likely 0.1ms~0.3ms faster than python implementation for each grab

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

Successfully merging this pull request may close these issues.

3 participants