-
Notifications
You must be signed in to change notification settings - Fork 12
Speed updates #1126
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
Speed updates #1126
Conversation
Updated image scaling and LUT application methods to consistently use 8-bit (uint8) image data, removing unnecessary dtype conversions. Crosshair drawing now sets pixel values to 255 instead of 1 for proper visibility. This improves performance and ensures compatibility with OpenCV color mapping functions.
Refactored camera view controller to optimize LUT application using numpy for faster image processing and added debounced min/max updates. Improved VariableWithLock in common_functions.py with type annotations and enhanced docstrings for better thread safety and clarity.
Introduces a single-slot queue and persistent worker thread for image display, dropping stale frames. Refactors image processing logic into a new render() method, separating processing from display and updating usage in CameraViewController to avoid direct Tkinter calls outside the main loop.
Replaced time.time() with time.perf_counter() for more accurate timing. Improved max intensity history recording by using cached frame max if available, reducing redundant calculations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements performance optimizations for the image display functionality, reducing display time from ~31.64ms to ~21.57ms. The changes focus on improving the colormap lookup table (LUT) application and introducing a dedicated display worker thread to handle frame rendering more efficiently.
Key changes include:
- Replaced
cv2.applyColorMap
with direct numpy indexing for faster LUT application - Introduced a single-threaded display worker with frame dropping to maintain UI responsiveness
- Added debouncing for min/max control updates to reduce unnecessary recomputations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
src/navigate/tools/common_functions.py | Added type hints and documentation to improve code maintainability |
src/navigate/controller/sub_controllers/camera_view.py | Implemented performance optimizations for image display including LUT buffer reuse, display worker thread, and debounced UI updates |
Introduces max_fps and frame interval logic to limit the rate at which frames are enqueued for display, improving UI responsiveness and preventing overload. Also ensures dropped frames are replaced with the most recent frame, and fixes flat image generation to return a white image instead of black.
One issue that I just remembered to post. I definitely broke the ability to overlay a mask. We will have to discuss this. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1126 +/- ##
===========================================
- Coverage 54.00% 53.91% -0.09%
===========================================
Files 191 191
Lines 21785 21953 +168
===========================================
+ Hits 11765 11837 +72
- Misses 10020 10116 +96
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The time to
display_image
has improved.On my computer, it is taking 21.57 ms, with a std dev of 3.8 ms.
Develop is currently 31.64 ms, with a std. dev. of 5.68 ms.