text_plain_output_1.png
import cv2

import numpy as np

def draw_keypoints(frame, keypoints, threshold=0.11):
    width, height, _ = frame.shape
    shaped = np.squeeze(np.multiply(keypoints, [width, height, 1]))
    for kp in shaped:
        ky, kx, kp_conf = kp
        if kp_conf > threshold:
            cv2.circle(frame, (int(kx), int(ky)), 4, (255, 0, 0), -1)

def draw_edges(frame, keypoints, edges, threshold=0.11):
    y, x, c = frame.shape
    shaped = np.squeeze(np.multiply(keypoints, [y, x, 1]))
    for edge, color in edges.items():
        p1, p2 = edge
        y1, x1, c1 = shaped[p1]
        y2, x2, c2 = shaped[p2]
        if (c1 > threshold) & (c2 > threshold):
            cv2.line(frame, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 4)

gif = cv2.VideoCapture('./ngannou.gif')
frame_count = int(gif.get(cv2.CAP_PROP_FRAME_COUNT))
print(f'Frame count: {frame_count}')