• 大小: 1.69M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-10
  • 语言: 其他
  • 标签: 其他  

资源简介

hand-gesture-recognition-opencv-master.zip

资源截图

代码片段和文件信息

#!/usr/bin/python

import math
import numpy as np

class Gesture(object):
    def __init__(selfname):
        self.name=name
    def getName(self):
        return self.name
    def set_palm(selfhand_centerhand_radius):
        self.hand_center=hand_center
        self.hand_radius=hand_radius
    def set_finger_pos(selffinger_pos):
        self.finger_pos=finger_pos
        self.finger_count=len(finger_pos)
    def calc_angles(self):
        self.angle=np.zeros(self.finger_countdtype=int)
        for i in range(self.finger_count):
            y = self.finger_pos[i][1]
            x = self.finger_pos[i][0]
            self.angle[i]=abs(math.atan2((self.hand_center[1]-y)(x-self.hand_center[0]))*180/math.pi)

def DefineGestures():
    dict={}
    # 1. BEGIN ------------------------------------#
    V=Gesture(“V“)
    V.set_palm((475225)45)
    V.set_finger_pos([(49090)(415105)])
    V.calc_angles()
    dict[V.getName()]=V
    # 1. END --------------------------------------#
    # 2. BEGIN ------------------------------------#
    L_right=Gesture(“L_right“)
    L_right.set_palm((475225)50)
    L_right.set_finger_pos([(45062)(345200)])
    L_right.calc_angles()
    dict[L_right.getName()]=L_right
    # 2. END --------------------------------------#
    # 3. BEGIN ------------------------------------#
    Index_Pointing=Gesture(“Index_Pointing“)
    Index_Pointing.set_palm((480230)43)
    Index_Pointing.set_finger_pos([(475102)])
    Index_Pointing.calc_angles()
    dict[Index_Pointing.getName()]=Index_Pointing
    # 3. END --------------------------------------#
    return dict

def CompareGestures(src1src2):
    if(src1.finger_count==src2.finger_count):
        if(src1.finger_count==1):
            angle_diff=src1.angle[0]-src2.angle[0]
            if(angle_diff>20):
                result=0
            else:
                len1 = np.sqrt((src1.finger_pos[0][0]- src1.hand_center[0])**2 + (src1.finger_pos[0][1] - src1.hand_center[1])**2)
                len2 = np.sqrt((src2.finger_pos[0][0]- src2.hand_center[0])**2 + (src2.finger_pos[0][1] - src2.hand_center[1])**2)
                length_diff=len1/len2
                radius_diff=src1.hand_radius/src2.hand_radius
                length_score=abs(length_diff-radius_diff)
                if(length_score<0.09):
                    result=src2.getName()
                else:
                    result=0
        else:
            angle_diff=[]
            for i in range(src1.finger_count):
                angle_diff.append(src1.angle[i]-src2.angle[i])
            angle_score=max(angle_diff)-min(angle_diff)
            if(angle_score<15):
                length_diff=[]
                for i in range(src1.finger_count):
                    len1 = np.sqrt((src1.finger_pos[i][0]- src1.hand_center[0])**2 + (src1.finger_pos[i][1] - src1.hand_center[1])**2)
                    len2 = np.sqrt((src2.finger_pos[i][0]- src2.hand_center[0])**2 + (src2.finger_pos[i][1] - src2.hand_center[1])**2)
  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-07-02 16:04  hand-gesture-recognition-opencv-master\
     文件        3579  2016-07-02 16:04  hand-gesture-recognition-opencv-master\GestureAPI.py
     文件        3922  2016-07-02 16:04  hand-gesture-recognition-opencv-master\GestureAPI.pyc
     文件        9507  2016-07-02 16:04  hand-gesture-recognition-opencv-master\HandRecognition.py
     文件        1081  2016-07-02 16:04  hand-gesture-recognition-opencv-master\LICENSE
     文件        3972  2016-07-02 16:04  hand-gesture-recognition-opencv-master\README.md
     目录           0  2016-07-02 16:04  hand-gesture-recognition-opencv-master\docs\
     文件      672031  2016-07-02 16:04  hand-gesture-recognition-opencv-master\docs\Documentation.pdf
     目录           0  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\
     文件      179617  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\1.jpg
     文件       50359  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\2.jpg
     文件      198452  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\3.jpg
     文件      174660  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\4.jpg
     文件      111111  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\5.jpg
     文件       44299  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\6.jpg
     文件      182413  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\7.jpg
     文件      182529  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\8.jpg
     文件      179163  2016-07-02 16:04  hand-gesture-recognition-opencv-master\screenshots\9.jpg

评论

共有 条评论