import cv2
import mediapipe as mp
import numpy as np
cap = cv2.VideoCapture("./dataset/accident_3.mp4")
mpHands = mp.solutions.hands
hands = mpHands.Hands(static_image_mode=False,
max_num_hands=2,
min_detection_confidence=0.75,
min_tracking_confidence=0.5
)
mpDraw = mp.solutions.drawing_utils
img = np.zeros((500, 500, 3), np.uint8)
img.fill(255)
i = 0
while True:
sussess, frame = cap.read()
if not sussess:
break
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(frame)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
print("\n")
m = hand_landmarks.landmark
for id, lm in enumerate(m):
print("x = {}, y = {}, z = {}".format(lm.x, lm.y, lm.z))
mpDraw.draw_landmarks(
img, hand_landmarks, mpHands.HAND_CONNECTIONS)
cv2.imwrite('./test/' + str(i) + '.png', img)
img = np.zeros((500, 500, 3), np.uint8)
img.fill(255)
i = i + 1
if cv2.waitKey(1) & 0xFF == 27:
break
print("共{}帧,第{}帧".format(cap.get(7), i))
cap.release()