# AIA MediaPipe 程式安裝 ###### tags: `AIA` 要安裝Python程式可以使用anaconda建起一個虛擬環境,讓開發環境在新增各個所需套件時,能夠保持在anaconda上,讓開發環境比較乾淨 1. 安裝anaconda https://www.anaconda.com/products/distribution ![](https://i.imgur.com/h5zX0fg.png) 3. 選擇uninstall,安裝OpenCV 4. 選擇uninstall,安裝Spyder 5. 開啟spyder ![](https://i.imgur.com/ON55ArW.png) 7.將media pipe的程式貼上,並且執行 ``` import cv2 import mediapipe as mp mp_drawing = mp.solutions.drawing_utils mp_hands = mp.solutions.hands hands = mp_hands.Hands( static_image_mode=False, max_num_hands=3, min_detection_confidence=0.5, min_tracking_confidence=0.5) cap = cv2.VideoCapture(0) #("TestingVideo.avi") while True: ret,frame = cap.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # 因为摄像头是镜像的,所以将摄像头水平翻转 # 不是镜像的可以不翻转 frame= cv2.flip(frame,1) results = hands.process(frame) frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) if results.multi_handedness: for hand_label in results.multi_handedness: print(hand_label) if results.multi_hand_landmarks: for hand_landmarks in results.multi_hand_landmarks: print('hand_landmarks:') print(hand_landmarks) # 关键点可视化 mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS) cv2.imshow('MediaPipe Hands', frame) if cv2.waitKey(1) & 0xFF == 27: break cap.release() ``` ![](https://i.imgur.com/tvBugcV.png) 9. 由於media pipe的模型需要另外安裝,所以執行會不成功,可在這裡打上 `pip install mediapipe` ![](https://i.imgur.com/fv7Gsmc.png) > 10. 執行完成,就可以出現結果囉