基于mediapipe识别手势所对应的数字(一、二、三、四、五)。
mediapipe的官网
总体思路:mediapipe可以 识别 手掌的关键点,我的思路是识别单根手指是否弯曲,然后根据五根手指的弯曲程度判断手势所对应的数字。
那怎么判断单根手指是否弯曲呢?
我是根据手指的四个关键点的相对位置。比如识别大拇指的弯曲程度,先计算点4和点3的角度a,再计算点2和点1的角度b,最后计算角度a和角度b的差值的绝对值,如果绝对值小于12度,则认为大拇指是伸直的。其他手指同理。
那怎么根据五根手指的弯曲程度判断手势所对应的数字呢?
假设已知五根手指的弯曲程度,若五根手指均伸直,则手势为数字五;若食指、中指、无名指、小指均伸直,而大拇指弯曲,则认为手势是数字四。其它手势同理。





代码如下:
import cv2
import mediapipe as mp
import time
import math
# 根据手指四个关节判断手指是否伸直
def get_angleError(point_4,point_3,point_2,point_1):
try:
point_4_cx, point_4_cy = int(point_4.x * w), int(point_4.y * h)
point_3_cx, point_3_cy = int(point_3.x * w), int(point_3.y * h)
point_2_cx, point_2_cy = int(point_2.x * w), int(point_2.y * h)
point_1_cx, point_1_cy = int(point_1.x * w), int(point_1.y * h)
angle_1 = math.degrees(math.atan((point_3_cx - point_4_cx) / (point_3_cy - point_4_cy)))
angle_2 = math.degrees(math.atan((point_1_cx - point_2_cx) / (point_1_cy - point_2_cy)))
angle_error = abs(angle_1 - angle_2)
if angle_error<12:
isStraight = 1
else
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删