vidgear icon indicating copy to clipboard operation
vidgear copied to clipboard

[Question]: Transforms size keep growing.

Open naserpiltan opened this issue 1 year ago • 3 comments

Issue guidelines

Issue Checklist

  • [X] I have searched open or closed issues for my problem and found nothing related or helpful.
  • [X] I have read the Documentation and found nothing related to my problem.
  • [X] I have gone through the Bonus Examples and FAQs and found nothing related or helpful.

Describe your Question

Hello and thank you for sharing your great work. I was testing the code provided in the video stabilization library and bumped into something weird at this line : https://github.com/abhiTronix/vidgear/blob/3572ef37439473fc44405684eb7d3938b50b9a2e/vidgear/gears/stabilizer.py#L283-L286 I checked the size of the self.__transforms variable and noticed that it keeps increasing throughout the video. If you use a camera for live-streaming and let it run for a long time, it will consume and eventually exhaust the memory. I tried to fix it by changing it to a queue and removing the first item at the end of each frame, but it worsened the final result. I wanted to ask you if this was intentional or a bug.

Terminal log output(Optional)

No response

Python Code(Optional)

No response

VidGear Version

0.3.0

Python version

3.8.0

Operating System version

Windows

Any other Relevant Information?

No response

naserpiltan avatar Jun 25 '23 21:06 naserpiltan

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

  • Read our Issue Guidelines, and update your issue accordingly. Please note that your issue will be fixed much faster if you spend about half an hour preparing it, including the exact reproduction steps and a demo.
  • Go comprehensively through our dedicated FAQ & Troubleshooting section.
  • For any quick questions and typos, please refrain from opening an issue, as you can reach us on Gitter community channel.

welcome[bot] avatar Jun 25 '23 21:06 welcome[bot]

Hello and thank you for sharing your great work. I was testing the code provided in the video stabilization library and bumped into something weird at this line :

vidgear/vidgear/gears/stabilizer.py

Lines 283 to 286 in 3572ef3

save this transformation

self.__transforms.append([dx, dy, da])

calculate path from cumulative transformations sum

I checked the size of the self.__transforms variable and noticed that it keeps increasing throughout the video. If you use a camera for live-streaming and let it run for a long time, it will consume and eventually exhaust the memory. I tried to fix it by changing it to a queue and removing the first item at the end of each frame, but it worsened the final result. I wanted to ask you if this was intentional or a bug.

@naserpiltan Thanks for sharing this insight. Yeah, it was intentional. In stabilizer, Once we have estimated the motion(rigid (Euclidean) transformation), we decompose it into x and y translation and rotation (angle). We store these transformation values in an array so we can change them smoothly. Also, we find the trajectory of motion by cumulatively adding the differential motion estimated.

But I agree, storing all transformation throught is not necessary or logical but instead storing them w.r.t to our window size is the better way to handle them. So I'll see if it can be replaced with deque or something similar, and let you know.

abhiTronix avatar Jun 29 '23 03:06 abhiTronix

@naserpiltan There's no immediate solution for this issue as transformations cannot be simply deleted from queue, as we require cumulative sum of all transformations. I'll see this problem later.

abhiTronix avatar Aug 28 '23 13:08 abhiTronix