深度CV項(xiàng)目就業(yè)小班第9期
CV項(xiàng)目肢體動(dòng)作識(shí)別
代碼:
import CV2import(已報(bào)名深度之?? 獲課底部) mediapipe as mpimport time
mpDraw = mp.solutions.drawing_utils
mpPose = mp.solutions.pose
pose = mpPose.Pose()cap = CV2.VideoCapture('PoseVideos/3.mp4')pTime = 0while True:
? ?success, img = cap.read()
? ?imgRGB = CV2.cvtColor(img, CV2.COLOR_BGR2RGB)
? ?results = pose.process(imgRGB)
? ?# print(results.pose_landmarks)
? ?if results.pose_landmarks:
? ? ? ?mpDraw.draw_landmarks(img, results.pose_landmarks, mpPose.POSE_CONNECTIONS)
? ? ? ?for id, lm in enumerate(results.pose_landmarks.landmark):
? ? ? ? ? ?h, w, c = img.shape
? ? ? ? ? ?print(id, lm)
? ? ? ? ? ?cx, cy = int(lm.x * w), int(lm.y * h)
? ? ? ? ? ?CV2.circle(img, (cx, cy), 5, (255, 0, 0), CV2.FILLED)
? ?cTime = time.time()
? ?fps = 1 / (cTime - pTime)
? ?pTime = cTime
? ?CV2.putText(img, str(int(fps)), (70, 50), CV2.FONT_HERSHEY_PLAIN, 3,
? ? ? ? ? ? ? ?(255, 0, 0), 3)
? ?CV2.imshow("Image", img)
? ?CV2.waitKey(1)