The ThreadedCamera Class that get frame from thread.
I have two questions.
Q1: Will it affect program performance if I don't close threads when I create a lot of ThreadedCamera
classes?
Q2: Does the thread can terminate when call __del__
method?
from threading import Thread
import cv2, time
class ThreadedCamera(object):
def __init__(self, src=0):
self.capture = cv2.VideoCapture(src)
# Start frame retrieval thread
self.thread = Thread(target=self.update, args=())
self.thread.daemon = True
self.thread.start()
def update(self):
while True:
if self.capture.isOpened():
(self.status, self.frame) = self.capture.read()
def get_frame(self):
return self.frame
def __del__(self): # Q2: Does the self.thread can terminate when call this method ?
self.capture.release()