示例#1
0
    def __init__(self):
        print("Started Gesture Recognition")
        self._setConfig()
        self.soundPlayer = Sound(self.audioConfig, self.osConfig)

        self.gestureFileIO = GestureFileIO(self.name, self.path)
        self.recorder = SwhRecorder(self.gestureFileIO, self.audioConfig, self.recordConfig)

        self.view = Console(self.recorder, self.soundPlayer, self.applicationClose, self.gestureFileIO.setFileName, self.gestureFileIO.getFileName)

        self.t1 = None
        self.t2 = None
        self.t3 = None
def getAverage(cut, fold):
    global avg
    # Use this if reaults are too bad by creating avg on demand with recorded gestures
    # the avg from all gestures isn't correct anymore -> hardcoded avg
    #     avg = [ 0.01405917,  0.01451394,  0.01501277,  0.01552741,  0.01608232,  0.0166838,
    #   0.017318,    0.01801043,  0.01876477,  0.01958107,  0.02046903,  0.02144034,
    #   0.02251206,  0.02370547,  0.02503494,  0.02651884,  0.02819135,  0.03008983,
    #   0.03227148,  0.03479038,  0.03773177,  0.04122532,  0.04543961,  0.05061085,
    #   0.05710018,  0.06553213,  0.07690142,  0.09310018,  0.11811639,  0.16215195,
    #   0.26233294,  0.83321468,  0.99991455,  0.4672319,   0.2171238,   0.1442126,
    #   0.10842227,  0.08702495,  0.07270665,  0.06246511,  0.0547552,   0.04876873,
    #   0.04395861,  0.03999377,  0.03669765,  0.03390901,  0.03149998,  0.02941618,
    #   0.02760306,  0.02599722,  0.02456548,  0.02327461,  0.02212122,  0.02108119,
    #   0.02013257,  0.01926706,  0.01846762,  0.01773872,  0.01707368,  0.01645111,
    #   0.01586561,  0.0153235,   0.01481276,  0.01433922]

    if avg == None:
        gesturepath = c.getInstance().getPathsConfig()['gesturepath']
        g = GestureFileIO(gesturePath=gesturepath)
        avg = g.getAvgFrequency()
        avg = preprocessFrame(avg, cut, fold)
    return avg
def getAverage(cut, fold):
    global avg
    # Use this if reaults are too bad by creating avg on demand with recorded gestures
    # the avg from all gestures isn't correct anymore -> hardcoded avg
    #     avg = [ 0.01405917,  0.01451394,  0.01501277,  0.01552741,  0.01608232,  0.0166838,
    #   0.017318,    0.01801043,  0.01876477,  0.01958107,  0.02046903,  0.02144034,
    #   0.02251206,  0.02370547,  0.02503494,  0.02651884,  0.02819135,  0.03008983,
    #   0.03227148,  0.03479038,  0.03773177,  0.04122532,  0.04543961,  0.05061085,
    #   0.05710018,  0.06553213,  0.07690142,  0.09310018,  0.11811639,  0.16215195,
    #   0.26233294,  0.83321468,  0.99991455,  0.4672319,   0.2171238,   0.1442126,
    #   0.10842227,  0.08702495,  0.07270665,  0.06246511,  0.0547552,   0.04876873,
    #   0.04395861,  0.03999377,  0.03669765,  0.03390901,  0.03149998,  0.02941618,
    #   0.02760306,  0.02599722,  0.02456548,  0.02327461,  0.02212122,  0.02108119,
    #   0.02013257,  0.01926706,  0.01846762,  0.01773872,  0.01707368,  0.01645111,
    #   0.01586561,  0.0153235,   0.01481276,  0.01433922]

    if avg == None:
        gesturepath = c.getInstance().getPathsConfig()['gesturepath']
        g = GestureFileIO(gesturePath=gesturepath)
        avg = g.getAvgFrequency()
        avg = preprocessFrame(avg, cut, fold)
    return avg
 def __loadDataFromFile(merge67="false"):
     gesturepath = c.getInstance().getPathsConfig()['gesturepath']
     g = GestureFileIO(gesturePath=gesturepath, relative=relative)
     data = [0] * nClasses
     getData = None
     if (average == "false"):
         getData = g.getGesture3DNormalized
     else:
         getData = g.getGesture3DDiffAvg
     if (merge67 == "true"):
         merge67 = True
     else:
         merge67 = False
     for i in classes:
         data[i] = getData(i, [], merge67)
         if (i == 6 and merge67):
             data7 = getData(7, [], merge67)
             data[i] = np.append(data[i], data7, axis=0)
         print("data " + str(i) + " loaded shape: " +
               str(np.shape(data[i])))
     print("data loaded, now creating dataset")
     return data
 def __init__(self):
     self.fileIO = GestureFileIO(relative="")
class DataUtil:
    ''' Class for loading and preprocessing gesture-data '''
    
    def __init__(self):
        self.fileIO = GestureFileIO(relative="")

    def loadRaw3dGesture(self, recordClass, recordNames=None):
        ''' loads raw data from the gesture dir '''
        if recordNames is None:
            return self.fileIO.getGesture3D(recordClass, c.names)
        else:
            return self.fileIO.getGesture3D(recordClass, recordNames)


    def _reduceBins(self, data, leftBorder=c.leftBorder, rightBorder=c.rightBorder+1):
        ''' reduces array from 64 to 16 bins '''
        return data[:, :, leftBorder:rightBorder]

    def _amplifyFunction(self, x):
        return x * (2.8 * ( x - 1.15 )**2 + 0.75)

    def _normalize(self, data):
        ''' normalizes gesture between 0 and 1 '''
        
        result = []
        for gesture in data:
            aMax = np.amax(gesture)
            result.append(gesture/aMax)
        return np.array(result)
    
    def splitData(self, data):
        ''' splits data in 3/4 training, 1/4 test '''
        
        train, test = list(data[::4]) + list(data[1::4]) + list(data[2::4]), data[3::4]
        return np.array(train), test
    
    def _cutThresholdAndAmplify(self, data, lowerBound=0.15):
        '''
        Sets values under lowerBound to 0
        and amplifiy / reduce values
        (uses normalized data)
        '''
        
        result = np.where(data[:,:,:]<lowerBound, 0.0, self._amplifyFunction(data[:,:,:]))
        return result


    def preprocessData(self, data):
        ''' public method to send data through the preproc pipeline'''

        data = self._reduceBins(data)
        data = self._normalize(data)
        data = self._cutThresholdAndAmplify(data)
        data = np.round(data, 1)
        return data

    def loadData(self, gesture):
        ''' public method to load preproc data '''
        data= self.loadRaw3dGesture(gesture)
        data = self.preprocessData(data)
        return data

    def loadSplitData(self, gesture):
        ''' public method to load splitted preproc data '''
        data = self.loadData(gesture)
        return self.splitData(data)

    def _getHighestSum(self, gesture):
        highestValue = 0
        position = 0
        
        for i in range(len(gesture)):
            highTmp = np.sum(gesture[i])
            if highTmp > highestValue:
                highestValue = highTmp
                position = i
        return position
        '''
示例#7
0
 def __init__(self):
     self.fileIO = GestureFileIO(relative="")
示例#8
0
class DataUtil:
    ''' Class for loading and preprocessing gesture-data '''
    def __init__(self):
        self.fileIO = GestureFileIO(relative="")

    def loadRaw3dGesture(self, recordClass, recordNames=None):
        ''' loads raw data from the gesture dir '''
        if recordNames is None:
            return self.fileIO.getGesture3D(recordClass, c.names)
        else:
            return self.fileIO.getGesture3D(recordClass, recordNames)

    def _reduceBins(self,
                    data,
                    leftBorder=c.leftBorder,
                    rightBorder=c.rightBorder + 1):
        ''' reduces array from 64 to 16 bins '''
        return data[:, :, leftBorder:rightBorder]

    def _amplifyFunction(self, x):
        return x * (2.8 * (x - 1.15)**2 + 0.75)

    def _normalize(self, data):
        ''' normalizes gesture between 0 and 1 '''

        result = []
        for gesture in data:
            aMax = np.amax(gesture)
            result.append(gesture / aMax)
        return np.array(result)

    def splitData(self, data):
        ''' splits data in 3/4 training, 1/4 test '''

        train, test = list(data[::4]) + list(data[1::4]) + list(
            data[2::4]), data[3::4]
        return np.array(train), test

    def _cutThresholdAndAmplify(self, data, lowerBound=0.15):
        '''
        Sets values under lowerBound to 0
        and amplifiy / reduce values
        (uses normalized data)
        '''

        result = np.where(data[:, :, :] < lowerBound, 0.0,
                          self._amplifyFunction(data[:, :, :]))
        return result

    def preprocessData(self, data):
        ''' public method to send data through the preproc pipeline'''

        data = self._reduceBins(data)
        data = self._normalize(data)
        data = self._cutThresholdAndAmplify(data)
        data = np.round(data, 1)
        return data

    def loadData(self, gesture):
        ''' public method to load preproc data '''
        data = self.loadRaw3dGesture(gesture)
        data = self.preprocessData(data)
        return data

    def loadSplitData(self, gesture):
        ''' public method to load splitted preproc data '''
        data = self.loadData(gesture)
        return self.splitData(data)

    def _getHighestSum(self, gesture):
        highestValue = 0
        position = 0

        for i in range(len(gesture)):
            highTmp = np.sum(gesture[i])
            if highTmp > highestValue:
                highestValue = highTmp
                position = i
        return position
        '''