基于mediapipe的单人姿态检测,可实时检测,cpu运行稳定可达到40fps

1.下载mediapipe库代码:

pip install mediapipe

2.完整代码:

import cv2
import time
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
fps = 0.0
cap = cv2.VideoCapture("2.mp4")
with mp_pose.Pose(
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5) as pose:
  while cap.isOpened():
    t1 = time.time()
    success, image = cap.read()
    if not success:
      print("Ignoring empty camera frame.")
      continue
    image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
    image.flags.writeable = False
    results = pose.process(image)
    image.flags.writeable = True
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    fps = (fps + (1. / (time.time() - t1))) / 2
    print("fps= %.2f" % (fps))
    image = cv2.putText(image, "fps= %.2f" % (fps), (0, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
    mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
    cv2.namedWindow("MediaPipe Pose", cv2.WINDOW_NORMAL)
    cv2.imshow('MediaPipe Pose', image)
    if cv2.waitKey(5) & 0xFF == 27:
      break
cap.release()

基于mediapipe的单人姿态检测,可实时检测,cpu运行稳定可达到40fps_第1张图片
3.成功了请求兄弟们一键三连,感谢。

你可能感兴趣的:(人工智能算法,计算机视觉,python,人工智能)