python实现自动手势识别代码

本文展示了如何利用Python和Mediapipe库实现手势识别。通过初始化Mediapipe Hands,设置参数,开启并读取摄像头图像,进行手势检测。在检测完成后,释放摄像头资源和Mediapipe Hands。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import cv2
import mediapipe as mp

mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands

初始化mediapipe hands

hands = mp_hands.Hands(
static_image_mode=False,
max_num_hands=2,
min_detection_confidence=0.5,
min_tracking_confidence=0.5
)

开启摄像头

cap = cv2.VideoCapture(0)

while cap.isOpened():
# 读取摄像头图像
success, image = cap.read()
if not success:
print(“Ignoring empty camera frame.”)
continue

# 翻转图像,使其更符合视觉习惯
image = cv2.flip(image, 1)

# 将图像转换为RGB格式,并传给hands.process()函数
results = hands.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))

# 检测到手部时,使用mediapipe hands提供的工具绘制关键点和手部连线
if results.multi_hand_landmarks:
    for hand_landmarks in results.multi_hand_landmarks:
        mp_drawing.draw_landmarks(
            image, hand_landmarks, mp_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值