cv2.VideoCapture leaking memory...
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- computer-vision
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.
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.
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
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.
More from opencv/opencv-python
-
[DOC] README file Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
opencv/opencv-python#1217 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
opencv/opencv-python#1165 · 2 comments · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
opencv/opencv-python#1273 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
opencv/opencv-python#1272 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
opencv/opencv-python#1268 · 1 comment ·
All issues in opencv/opencv-python
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
stephrobert/dsoxlab#238 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sublimehq/package_control#1780 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nwg-piotr/nwg-displays#145 ·