-
Notifications
You must be signed in to change notification settings - Fork 4
Camera scheduler and on_frame thread #372
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #372 +/- ##
==========================================
- Coverage 58.56% 52.50% -6.06%
==========================================
Files 72 80 +8
Lines 2756 3114 +358
==========================================
+ Hits 1614 1635 +21
- Misses 1142 1479 +337
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
The on_frame_thread seems like a good idea. I tried something like this before but was missing the critical piece to check self.__on_frame_thread.is_alive()
.
We'd need to talk another look at the capture actions in the frame_handler also, I think they use threads already but without that addition to allow it to drop frames. We could consider removing the frame handler functionality to be honest or otherwise combining it with on_frame. It does make it a bit easier to add multiple processing callbacks, but there are less complex alternatives.
I think other threads can run whilst this is blocked waiting for the next camera frame, without the need for a sleep or scheduler delay. I'm not sure though and the scheduler seems like an reasonable implementation but I worry a bit about the accuracy and overhead of the timing calls.
👍
There's a ticket here for removing the frame handler stuff: #198 It does bloat the camera code massively
I'm a pretty big fan of |
@m-roberts I think we can close this PR but in your opinion is item 2 worth implementing into the SDK? If so we can create a ticket for it. |
what about using an FPS regulator on the camera similar to what we do with the miniscreen? i.e. if you are calling frames too often, then it will sleep to ensure that the FPS is no higher than what we want. This means "dynamic sleeping" rather than hard-coding it to always run. |
I'm not sure - would be good to have some data to look at - what are the performance stats before/after? I don't really have much of an opinion on this right now as I'm not close enough to it... |
Right now we are getting frames as fast as possible from the camera since it always guarantees the user has the most recent frame to use when their code requests one. If they use the I think what you're talking about is a user-settable FPS, which we can do for sure - this would limit the amount of IO reads to the camera and therefore reduce the overhead. It would be somewhat of an advanced feature when heavy computer vision is involved though since they need to set it higher than their algorithm FPS to ensure it doesn't slow down the system even more waiting for frames to be ready |
It's not directly a performance thing (dependant on the user's code), it's just ensuring that the user callback function is put into a thread instead of stopping our camera thread from running. As I describe in the PR, I don't think there is any downside but just interested if you seen any potential drawbacks |
I don't really see an issue - other than the build failing ;) (which is my bad) |
I was hoping this would fix #367. It didn't but I think the changes are worthwhile regardless. Changes:
1. Frame retrieval is no longer in a
while True
loop.time_to_next_frame
is zero around 95% of the time (meaning it acts exactly like a while true with no delay).2. Calling
self.on_frame
is done by a separate threadFor change 1, I'm not sure if it's worthwhile implementing over a
while True
loop, but change 2 is definitely an improvement.The reason this PR doesn't fix #367 is the same reason why change 1 might not be worth implementing - they are essentially doing the same thing. This is because the
self.__frame_handler.frame = self.__camera.get_frame()
is the bottleneck (time is very close to 1/FPS)