Outils pour utilisateurs

Outils du site


movenet

Ceci est une ancienne révision du document !


MoveNet

Exemple

from time import time
import cv2
import numpy as np
import tensorflow as tf
 
interpreter = tf.lite.Interpreter(model_path="lite-model_movenet_singlepose_thunder_3.tflite")
interpreter.allocate_tensors()
 
cv2.namedWindow('color', cv2.WND_PROP_FULLSCREEN)
cam = cv2.VideoCapture(0)
t0 = time()
nbr = 0
 
while 1:
    nbr += 1
    ret, frame = cam.read()
 
    if not ret:
        continue
 
    image = tf.expand_dims(frame, axis=0)
    # Resize and pad the image to keep the aspect ratio and fit the expected size.
    image = tf.image.resize_with_pad(image, 256, 256)
 
    # TF Lite format expects tensor type of float32.
    input_image = tf.cast(image, dtype=tf.float32)
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()
 
    interpreter.set_tensor(input_details[0]['index'], input_image.numpy())
    interpreter.invoke()
 
    # Output is a [1, 1, 17, 3] numpy array.
    keypoints_with_scores = interpreter.get_tensor(output_details[0]['index'])
 
    # Affichage de l'image
    cv2.imshow('color', frame)
 
    # Calcul du FPS, affichage toutes les 10 s
    if time() - t0 > 10:
        print("FPS =", round(nbr/10, 2))
        t0, nbr = time(), 0
 
    # Pour quitter
    if cv2.waitKey(1) == 27:
        break
 
cv2.destroyAllWindows()
movenet.1633766802.txt.gz · Dernière modification : 2021/10/09 08:06 de serge