I am planning to take every 5 seconds a frame from the web cam and run all the calculations in separate thread. Unfortunately, after 5 seconds the video transmission stops and nothing happens, although video must be continiued. All I see in the output - is the message “time is now”. But as i tried to debug it, I could never go into the functions in threads.py
So this is my main.py
:
from threads import myThread
import cv2
import time
vid = cv2.VideoCapture(0)
if __name__ == "__main__":
print("starting the measurements")
threads = {}
i=0
t_past = t_now = time.time()
period = 5
while True:
_,frame = vid.read()
t_now = time.time()
if t_now - t_past >=5 :
print("time is now")
t_past=t_now
threads[i] = myThread(i,frame)
threads[i].start()
i+=1
cv2.namedWindow("frame",cv2.WINDOW_NORMAL)
cv2.imshow("frame",frame)
cv2.waitKey(1)
and this is the threads.py
:
import threading
import gauge
class myThread(threading.Thread,gauge.Gauge):
def __init__(self,id,frame):
self.id = id
threading.Thread.__init__(self)
self.gg = gauge.Gauge(frame)
def run(self):
self.gg.makeBlur()
self.gg.makeGray()
self.gg.drawCircle()
self.gg.findAngle()
self.gg.findPressure()