赞
踩
最近在做项目需要用到mediapipe,所以简单记录一下。
在win10环境下安装mediapipe很简单,直接打开cmd用pip安装就行,我的环境是python3.7,提前需要安装好opencv-python哦。
pip3 install mediapipe -i https://pypi.tuna.tsinghua.edu.cn/simple
实例代码:
- import cv2
- import mediapipe as mp
-
- # 导入solution
- mpHands = mp.solutions.hands
- hands = mpHands.Hands()
- mpDraw = mp.solutions.drawing_utils
-
- # 打开摄像头
- cap = cv2.VideoCapture(0)
-
- while True:
- flag, img = cap.read()
- imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
- results = hands.process(imgRGB)
- if results.multi_hand_landmarks:
- for handLms in results.multi_hand_landmarks:
- for id, lm in enumerate(handLms.landmark):
- h, w, c = img.shape
- cx, cy = int(lm.x * w), int(lm.y * h)
- cv2.circle(img, (cx, cy), 15, (255, 0, 255), cv2.FILLED)
- mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
- cv2.imshow("myhand", img)
- cv2.waitKey(1)
上述代码能够实现手部手部关键点。
实现的效果
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。