'countdown timer with mediapipe freezes

My goal is that using media pipe I would calculate the angle between 2 lines, and for a certain range of angles a count down of 8 secs would begin.

My issue is that without applying the countdown code everything works fine but once the countdown code is implemented it freezes, I have also tried reducing model_complexity to 0 but barely makes any difference

while True:
    angles = []
    LMlist = []
    t = 8
    suc, img = cap.read()
    ret, vid = blank.read()
    rgb = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    res = pose.process(rgb)
    # mp_drawing.draw_landmarks(img, res.pose_landmarks, mp_pose.POSE_CONNECTIONS)
    if res.pose_landmarks is not None:
        for id, lm in enumerate(res.pose_landmarks.landmark):
            h, w, c = img.shape
            cx, cy = int(lm.x * w), int(lm.y * h)
            LMlist.append([id, cx, cy])

        x1, y1 = LMlist[p1][1:]
        x2, y2 = LMlist[p2][1:]
        x3, y3 = LMlist[p3][1:]
        angle = math.degrees(math.atan2(y3 - y2, x3 - x2) - math.atan2(y1 - y2, x1 - x2))
        if angle<0:
            angle += 180
        if angle<130 and angle>30 :
            cv2.putText(vid, f'{int(angle)}', (70, 70), cv2.FONT_ITALIC, 2, (0, 255, 255), 2)
            cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
            cv2.line(img, (x2, y2), (x3, y3), (0, 255, 0), 2)
            cv2.circle(img, (x1, y1), 5, (0, 0, 0), cv2.FILLED)
            cv2.circle(img, (x2, y2), 5, (0, 0, 0), cv2.FILLED)
            cv2.circle(img, (x3, y3), 5, (0, 0, 0), cv2.FILLED)
            while t:
                mins, secs = divmod(t, 60)
                timer = '{:02d}:{:02d}'.format(mins, secs)
                cv2.putText(vid, f'{timer}', (70, 200), cv2.FONT_ITALIC, 2, (0, 255, 255), 2)
                time.sleep(1)
                t -= 1
        else:
            # cv2.putText(vid, f'{int(deg)}', (70, 70), cv2.FONT_ITALIC, 2, (0, 255, 255), 2)
            cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2)
            cv2.line(img, (x2, y2), (x3, y3), (0, 0, 255), 2)
            cv2.circle(img, (x1, y1), 5, (0, 0, 0), cv2.FILLED)
            cv2.circle(img, (x2, y2), 5, (0, 0, 0), cv2.FILLED)
            cv2.circle(img, (x3, y3), 5, (0, 0, 0), cv2.FILLED)


    stack = imgstack.stackImages(0.8, ([img, vid]))

    cv2.imshow('a', stack)
    if cv2.waitKey(1) == 13:
        break

WITHOUT COUNDOWN TIMER

WITH COUNDOWN TIMER



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source