herrDeng網內搜尋

自訂搜尋

Ads

2023年11月22日 星期三

mediaPipe描繪pose landmarks在python針對人、狗pose偵測實作練習


















python code請進
print('練習mediapipe pose landmark')
import cv2
import mediapipe as mp
print(cv2.__version__)
print(mp.__version__)
#mediapipe相關繪圖
mp_drawing = mp.solutions.drawing_utils          # mediapipe 繪圖方法
mp_drawing_styles = mp.solutions.drawing_styles  

mp_pose = mp.solutions.pose                      # mediapipe 姿勢偵測
# cv2.VideoCapture
cap = cv2.VideoCapture("dog.mp4") # slot : 0 or "dog.mp4"
cap.set(3, 1280)
cap.set(4, 720)

if not cap.isOpened():
    print("Cannot open camera")
    exit()
# pose設定
pose=mp_pose.Pose(
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5)
# while loop
 while True:
    ret, im = cap.read()
    if not ret:
        print("Fail to receive frame")
        break
    im =cv2.resize(im, (1280, 720))
    im2 = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)   # 將 BGR 轉換成 RGB
    results = pose.process(im2)                 # pose
    mp_drawing.draw_landmarks(
            im,
            results.pose_landmarks,
            mp_pose.POSE_CONNECTIONS,
            landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style())
    cv2.imshow('pose', im)
    if cv2.waitKey(1)>0: break    # 按任意鍵停止
cap.release()
cv2.destroyAllWindows()
pose.close()
 


沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章