Fix darknet_video.py to so it's not off by 1 frame#6717
Open
mazatov wants to merge 5 commits intoAlexeyAB:masterfrom
Open
Fix darknet_video.py to so it's not off by 1 frame#6717mazatov wants to merge 5 commits intoAlexeyAB:masterfrom
mazatov wants to merge 5 commits intoAlexeyAB:masterfrom
Conversation
The issue: Previously the output videofile had detections off by 1 frame from the video. The reason: The `darknet_image` is overwritten in `video_capture` every time it's being created because it sits in the same memory so effectively the `darknet_image_queue` is not working properly Changes: - `darknet_image` is created in every iteration of `video_capture` so every new `darknet_image` sits in different memory - remove limitations on `max_size` of the queue. I believe the limitations were put there to avoid the issue above, but it only made it so the result was off by one frame. Now that that's not an issue there is no reason to have `max_size` for any of the queques
Added maxsize so there is no memory overload in case too many frames load for the detect_image.
I was getting a memory problem because as `darknet_image` is created in every iteration of `video_capture`, it is not being released by the `darknet_image_queue` when it gets `.get()`. To fix it I make a list of darknet_images that is larger than the size of the queue. The list is being repeatedly updated with new darknet_images in `video_capture`, but the image that has not been processed yet, is never overwritten. A bit of a hacky fix, but it works.
Define `darknet_images`
FemiaLeandro
approved these changes
Oct 2, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue:
Previously the output videofile had detections off by 1 frame from the video.
The reason:
The
darknet_imageis overwritten invideo_captureevery time it's being created because it sits in the same memory so effectively thedarknet_image_queueis not working properlyChanges:
darknet_imageis created in every iteration ofvideo_captureso every newdarknet_imagesits in different memorymax_sizeof the queue. I believe the limitations were put there to avoid the issue above, but it only made it so the result was off by one frame. Now that that's not an issue there is no reason to havemax_sizefor any of the queques