OK手势通常是拇指和食指形成一个圆圈,其余三指伸直或稍微弯曲。这种手势的判断主要依靠以下特征:
- 拇指和食指的指尖靠近。
- 其余三指伸直。
判断OK手势的步骤
- 计算拇指和食指指尖之间的距离。
- 确保其余三指的指尖远离手掌根部。
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}")