RoboMaster EP实用功能开发(二):手势控制

功能:基于MediaPipe通过PC摄像头获取不同手势控制EP运动

硬件:RoboMaster EP,PC

系统平台:Windows10

开发软件:PyCharm

语言及功能包:python3.8.6,mediapipe库,robomaster sdk

完成效果:

EP-手势识别

软件界面:左边为PC摄像头画面,用于手势识别;右边为EP摄像头画面,监控EP运动。

重点思路:

        利用MediaPipe识别手掌的返回信息,标识不同的手势样式,来控制EP旋转和平移(或者其他功能)。

        下图引用参考文章,标出了手部关节的21个主要点的说明。

    def fingerStatus(self, lmList):
        fingerDict = dict()
        fingerstaList = list()
        id, originx, originy = lmList[0]
        if self.results.multi_handedness:
            for hand_label in self.results.multi_handedness:
                try:
                    for score, label in enumerate(hand_label.classification):
                        if lmList[0][2] < lmList[17][2] or lmList[0][2] < lmList[5][2]:  # 判断手掌是否横向情况
                            fingerDict["Updown"] = True
                            if label.label == "Right":  # 横向-右手
                                fingerDict["Right"] = True
                                if lmList[0][2] > lmList[1][2]:  # 横向-右手-手背
                                    hand_palm = False
                                    if lmList[3][2] > lmList[4][2]:
                                        thumb_sta = True
                                    else:
                                        thumb_sta = False
                                else:  # 横向-右手-手心
                                    hand_palm = True
                                    if lmList[3][2] > lmList[4][2]:
                                        thumb_sta = False
                                    else:
                                        thumb_sta = True
                            else:  # 横向-左手
                                fingerDict["Right"] = False
                                if lmList[0][2] > lmList[1][2]:  # 横向-左手-手背
                                    hand_palm = False
                                    if lmList[3][2] > lmList[4][2]:
                                        thumb_sta = True
                                    else:
                                        thumb_sta = False
                                else:  # 横向-左手-手心
                                    hand_palm = True
                                    if lmList[3][2] > lmList[4][2]:
                                        thumb_sta = False
                                    else:
                                        thumb_sta = True
                        else:  # 竖向
                            fingerDict["Updown"] = False
                            if label.label == "Right":  # 竖向-右手
                                fingerDict["Right"] = True
                                if lmList[0][1] > lmList[1][1]:  # 竖向-右手-手心
                                    hand_palm = True
                                    if lmList[3][1] > lmList[4][1]:
                                        thumb_sta = True
                                    else:
                                        thumb_sta = False
                                else:  # 竖向-右手-手背
                                    hand_palm = False
                                    if lmList[3][1] > lmList[4][1]:
                                        thumb_sta = False
                                    else:
                                        thumb_sta = True
                            else:  # 竖向-左手
                                fingerDict["Right"] = False
                                if lmList[0][1] > lmList[1][1]:  # 竖向-左手-手背
                                    hand_palm = False
                                    if lmList[3][1] > lmList[4][1]:
                                        thumb_sta = True
                                    else:
                                        thumb_sta = False
                                else:  # 竖向-左手-手心
                                    hand_palm = True
                                    if lmList[3][1] > lmList[4][1]:
                                        thumb_sta = False
                                    else:
                                        thumb_sta = True
                except Exception as e:
                    print(e)
        fingerDict["Hand_palm"] = hand_palm
        fingerDict["Thumb"] = thumb_sta
        fingerstaList.append(thumb_sta)
        keypoint_dict = {"indexfinger": (6, 8), "midfinger": (10, 12), "ringfinger": (14, 16), "littlefinger": (18, 20)}
        for key, point in keypoint_dict.items():
            id, x1, y1 = lmList[point[0]]
            id, x2, y2 = lmList[point[1]]
            if math.hypot(x2 - originx, y2 - originy) > math.hypot(x1 - originx, y1 - originy):
                fingerDict[key] = True
                fingerstaList.append(True)
            else:
                fingerDict[key] = False
                fingerstaList.append(False)
        return fingerDict, fingerstaList

上面的函数返回的字典结果为:包含手掌方向左右手手心方向5个手指曲伸状态,例如:{'Updown': False, 'Right': False, 'Hand_palm': True, 'Thumb': True, 'indexfinger': True, 'midfinger': False, 'ringfinger': False, 'littlefinger': False}, 通过以上四类关键信息,得出手势。

参考链接:基于MediaPipe、opencv和python实现21点手势识别和手势运动方向识别_在于探索的博客-CSDN博客_mediapipe 手势识别

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值