cv2.VideoCapture leaking memory...
Open
Nobody has claimed this yet.
incomplete
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
Description
import psutil
import os
import random
import cv2
import gc
def logMem():
uss = psutil.Process(os.getpid()).memory_full_info().uss / 1024 / 1024
print(f"Memory usage: {uss} MB")
def Test(path):
print("-"*100)
print(path)
cap = cv2.VideoCapture(path)
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print("init")
logMem()
for i in range(20):
k = random.randint(0, total_frames)
_ = cap.set(cv2.CAP_PROP_POS_FRAMES, k)
ret, frame = cap.read()
del ret, frame
print("finish")
logMem()
cap.release()
del cap
gc.collect()
gc.collect()
gc.collect()
print("del")
logMem()
print("-"*100)
path = 'PATH_TO_VIDEOS_FOLDER'
videos = os.listdir(path)
for i in range(10):
Test(path + random.choice(videos))
Memory keep growing after every loop iter.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python reproduction with representative video files and record the Python, OpenCV, and platform details, which the issue does not specify. Trace memory across repeated VideoCapture creation, seeking, reading, release, and garbage collection; done means isolating a reproducible leak and identifying the relevant component or a minimal fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100