I am running a Python script that captures and processes images from a USB camera using OpenCV 4.5.1 and V4L2 backend. The image is fed to a Tensorflow network. I noticed a very high memory leak during the execution. The relevant code is the following:
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, img = cap.read()
other_process_queue.put(img) // the image is processed on a parallel process
del(img)
According to the memory profiler, the instruction that causes the leak is cap.read(). Deleting the img variable did not fix the problem. What could be the cause for this?