如何测试mediapipe是否安装成功?
时间: 2023-06-25 09:05:32 浏览: 286
可以通过运行一个简单的示例代码来测试 mediapipe 是否安装成功。以下是一个简单的示例代码,它使用 mediapipe 来捕获摄像头视频并在每个视频帧上应用手部检测模型:
```
import cv2
import mediapipe as mp
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
cap = cv2.VideoCapture(0)
with mp_hands.Hands(
min_detection_confidence=0.5,
min_tracking_confidence=0.5) as hands:
while cap.isOpened():
success, image = cap.read()
if not success:
break
image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
image.flags.writeable = False
results = hands.process(image)
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
cv2.imshow('MediaPipe Hands', image)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
```
如果运行成功并且能够打开摄像头并检测手部,那么 mediapipe 就已经成功安装了。如果出现错误或无法打开摄像头或检测手部,请检查您的 mediapipe 安装是否正确配置。
阅读全文