如何进行手势识别系列-6:OK手势识别

OK手势通常是拇指和食指形成一个圆圈,其余三指伸直或稍微弯曲。这种手势的判断主要依靠以下特征:

  1. 拇指和食指的指尖靠近
  2. 其余三指伸直

判断OK手势的步骤

  1. 计算拇指和食指指尖之间的距离
  2. 确保其余三指的指尖远离手掌根部

import numpy as np

def is_ok_sign(hand_landmarks, wrist_idx=0, thumb_tip_idx=4, index_tip_idx=8, threshold_thumb_index=30, threshold_fingers=60):
    wrist = hand_landmarks[wrist_idx]
    thumb_tip = hand_landmarks[thumb_tip_idx]
    index_tip = hand_landmarks[index_tip_idx]
    
    # 计算拇指和食指指尖之间的距离
    distance_thumb_index = np.linalg.norm(np.array(thumb_tip) - np.array(index_tip))
    
    if distance_thumb_index > threshold_thumb_index:
        return False
    
    # 确保其余三指(中指、无名指、小指)的指尖与手腕的距离大于一定阈值
    is_ok = True
    for i in [12, 16, 20]:  # Middle, Ring, Pinky finger tips
        fingertip = hand_landmarks[i]
        distance = np.linalg.norm(np.array(fingertip) - np.array(wrist))
        if distance < threshold_fingers:
            is_ok = False
            break
    
    return is_ok

# 示例关节点坐标
hand_landmarks = [
    [0, 0, 0],    # Wrist
    [1, 1, 0], [2, 1, 0], [3, 1, 0], [4, 1, 0],   # Thumb
    [1, 2, 0], [2, 2, 0], [3, 2, 0], [4, 2, 0],   # Index
    [1, 3, 0], [2, 3, 0], [3, 3, 0], [4, 3, 0],   # Middle
    [1, 4, 0], [2, 4, 0], [3, 4, 0], [4, 4, 0],   # Ring
    [1, 5, 0], [2, 5, 0], [3, 5, 0], [4, 5, 0]    # Pinky
]

# 计算是否为OK手势
is_ok = is_ok_sign(hand_landmarks)
print(f"是否为OK手势: {is_ok}")

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值