当前位置:   article > 正文

MediaPipe Hands 代码搬运_mediapipe handslandmark web

mediapipe handslandmark web

地址:https://google.github.io/mediapipe/solutions/hands.html

代码:

  1. import cv2
  2. import mediapipe as mp
  3. mp_drawing = mp.solutions.drawing_utils
  4. mp_hands = mp.solutions.hands
  5. drawing_styles = mp.solutions.drawing_styles
  6. # For webcam input:
  7. cap = cv2.VideoCapture(0)
  8. with mp_hands.Hands(
  9. min_detection_confidence=0.5,
  10. min_tracking_confidence=0.5) as hands:
  11. while cap.isOpened():
  12. success, image = cap.read()
  13. if not success:
  14. print("Ignoring empty camera frame.")
  15. # If loading a video, use 'break' instead of 'continue'.
  16. continue
  17. # Flip the image horizontally for a later selfie-view display, and convert
  18. # the BGR image to RGB.
  19. image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
  20. # To improve performance, optionally mark the image as not writeable to
  21. # pass by reference.
  22. image.flags.writeable = False
  23. results = hands.process(image)
  24. # Draw the hand annotations on the image.
  25. image.flags.writeable = True
  26. image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
  27. if results.multi_hand_landmarks:
  28. for hand_landmarks in results.multi_hand_landmarks:
  29. mp_drawing.draw_landmarks(
  30. image, hand_landmarks, mp_hands.HAND_CONNECTIONS,
  31. drawing_styles.get_default_hand_landmark_style(),
  32. drawing_styles.get_default_hand_connection_style())
  33. cv2.imshow('MediaPipe Hands', image)
  34. if cv2.waitKey(1) & 0xFF == 27:
  35. cv2.destroyAllWindows()
  36. cap.release()
  37. break

代码测试结果:

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/906168
推荐阅读
相关标签
  

闽ICP备14008679号