-
Notifications
You must be signed in to change notification settings - Fork 949
Open
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.
Metadata
Metadata
Assignees
Labels
No labels