def interpolateEmotion(arListRatio, rNeutral=0.): "create a position intermediary mixed from 6 emotions and a neutral" "arListRatio: the ratio of each emotions: [Proud, Happy, Excitement, Fear, Sadness, Anger]" " if sum is greater than 1, it would be normalised" " if sum is lower than 1, a neutral position would be added" "rNeutral: to force an addition of a proportion of the neutral pose" # preparation of the ratio if (len(arListRatio) > 6): arListRatio = arListRatio[:6] rSum = arraytools.arraySum(arListRatio) # rEpsilon = 0.1; if (rSum + rNeutral < 1.): rNeutral = 1. - rSum rSumTotal = rSum + rNeutral if (rSumTotal > 1.): # normalisation for i in range(len(arListRatio)): arListRatio[i] /= rSumTotal rNeutral /= rSumTotal # push zeroes for others emotions: for i in range(len(arListRatio), 6): arListRatio.append(0.) print( "interpolateEmotion: using emotions ratio: %s and neutral ratio: %5.2f" % (str(arListRatio), rNeutral)) arListRatio.append(rNeutral) listPosEmotion = PoseLibrary.getEmotionPose(True) # True => ajoute la neutre ! # print( "listPosEmotion has %d poses" % len( listPosEmotion ) ); listPosResult = {} for k, v in listPosEmotion[0].iteritems(): rVal = v * arListRatio[0] bKeyInAllPos = True for i in range(1, len(listPosEmotion)): if (k in listPosEmotion[i]): rVal += listPosEmotion[i][k] * arListRatio[i] else: bKeyInAllPos = False if (bKeyInAllPos): listPosResult[k] = rVal # for - end return listPosResult
def interpolateEmotion( arListRatio, rNeutral = 0. ): "create a position intermediary mixed from 6 emotions and a neutral" "arListRatio: the ratio of each emotions: [Proud, Happy, Excitement, Fear, Sadness, Anger]" " if sum is greater than 1, it would be normalised" " if sum is lower than 1, a neutral position would be added" "rNeutral: to force an addition of a proportion of the neutral pose" # preparation of the ratio if( len( arListRatio ) > 6 ): arListRatio = arListRatio[:6]; rSum = arraytools.arraySum( arListRatio ); # rEpsilon = 0.1; if( rSum + rNeutral < 1. ): rNeutral = 1. - rSum; rSumTotal = rSum + rNeutral; if( rSumTotal > 1. ): # normalisation for i in range( len( arListRatio ) ): arListRatio[i] /= rSumTotal; rNeutral /= rSumTotal; # push zeroes for others emotions: for i in range( len( arListRatio ), 6 ): arListRatio.append( 0. ); print( "interpolateEmotion: using emotions ratio: %s and neutral ratio: %5.2f" % ( str( arListRatio ), rNeutral ) ); arListRatio.append( rNeutral ); listPosEmotion = PoseLibrary.getEmotionPose( True ); # True => ajoute la neutre ! # print( "listPosEmotion has %d poses" % len( listPosEmotion ) ); listPosResult = {}; for k, v in listPosEmotion[0].iteritems(): rVal = v * arListRatio[0]; bKeyInAllPos = True; for i in range( 1, len( listPosEmotion ) ): if( k in listPosEmotion[i] ): rVal += listPosEmotion[i][k] * arListRatio[i]; else: bKeyInAllPos = False; if( bKeyInAllPos ): listPosResult[k] = rVal; # for - end return listPosResult;
def interpolateTrackingEmotion( arListRatio, arPosHead, rNeutral = 0. ): "create a position intermediary mixed from 6 emotions and a neutral, related to some specific angle of the head" "arListRatio: the ratio of each emotions: [Proud, Happy, Excitement, Fear, Sadness, Anger]" " if sum is greater than 1, it would be normalised" " if sum is lower than 1, a neutral position would be added" "rNeutral: to force an addition of a proportion of the neutral pose" # preparation of the ratio if( len( arListRatio ) > 6 ): arListRatio = arListRatio[:6]; rSum = arraytools.arraySum( arListRatio ); # rEpsilon = 0.1; if( rSum + rNeutral < 1. ): rNeutral = 1. - rSum; rSumTotal = rSum + rNeutral; if( rSumTotal > 1. ): # normalisation for i in range( len( arListRatio ) ): arListRatio[i] /= rSumTotal; rNeutral /= rSumTotal; # push zeroes for others emotions: for i in range( len( arListRatio ), 6 ): arListRatio.append( 0. ); print( "interpolateTrackingEmotion(head:%5.2f,%5.2f): using emotions ratio: %s and neutral ratio: %f" % ( arPosHead[0], arPosHead[1], str( arListRatio ), rNeutral ) ); arListRatio.append( rNeutral ); listPosTrackingEmotion = PoseLibrary.getTrackingEmotionPose( True ); # True => ajoute la neutre ! # in fact we will allways generate from a square from center to left side, and we mirror it if we are in the right area # first we compute the 4 poses from emotion mixes: # print( "arListRatio final: %s, len: %d" % ( str( arListRatio ), len( arListRatio ) ) ); listPosResult = [{},{},{},{}]; # for each corner to generate for indexSquare in range( 4 ): # for each joint for k, v in listPosTrackingEmotion[0][indexSquare].iteritems(): rVal = v * arListRatio[0]; bKeyInAllPos = True; # for each emotion, sum the ratio concerning this joint for i in range( 1, len( listPosTrackingEmotion ) ): # print( "i: %d / %d" % (i,len( listPosTrackingEmotion) ) ); # print( "ratio: %f" % arListRatio[i] ); if( k in listPosTrackingEmotion[i][indexSquare] ): rVal += listPosTrackingEmotion[i][indexSquare][k] * arListRatio[i]; else: bKeyInAllPos = False; if( bKeyInAllPos ): # print( "k: %s, rVal: %f" % ( k, rVal ) ); listPosResult[indexSquare][k] = rVal; # for - each point of square end # for - end square # then we compute the center position relative of the 4 pose listPosResult = PoseLibrary.interpolatePositionXY_Mirror( listPosResult[0], listPosResult[1], listPosResult[2], listPosResult[3], arPosHead[0], arPosHead[1] ); return listPosResult;
def interpolateTrackingEmotion(arListRatio, arPosHead, rNeutral=0.): "create a position intermediary mixed from 6 emotions and a neutral, related to some specific angle of the head" "arListRatio: the ratio of each emotions: [Proud, Happy, Excitement, Fear, Sadness, Anger]" " if sum is greater than 1, it would be normalised" " if sum is lower than 1, a neutral position would be added" "rNeutral: to force an addition of a proportion of the neutral pose" # preparation of the ratio if (len(arListRatio) > 6): arListRatio = arListRatio[:6] rSum = arraytools.arraySum(arListRatio) # rEpsilon = 0.1; if (rSum + rNeutral < 1.): rNeutral = 1. - rSum rSumTotal = rSum + rNeutral if (rSumTotal > 1.): # normalisation for i in range(len(arListRatio)): arListRatio[i] /= rSumTotal rNeutral /= rSumTotal # push zeroes for others emotions: for i in range(len(arListRatio), 6): arListRatio.append(0.) print( "interpolateTrackingEmotion(head:%5.2f,%5.2f): using emotions ratio: %s and neutral ratio: %f" % (arPosHead[0], arPosHead[1], str(arListRatio), rNeutral)) arListRatio.append(rNeutral) listPosTrackingEmotion = PoseLibrary.getTrackingEmotionPose(True) # True => ajoute la neutre ! # in fact we will allways generate from a square from center to left side, and we mirror it if we are in the right area # first we compute the 4 poses from emotion mixes: # print( "arListRatio final: %s, len: %d" % ( str( arListRatio ), len( arListRatio ) ) ); listPosResult = [{}, {}, {}, {}] # for each corner to generate for indexSquare in range(4): # for each joint for k, v in listPosTrackingEmotion[0][indexSquare].iteritems(): rVal = v * arListRatio[0] bKeyInAllPos = True # for each emotion, sum the ratio concerning this joint for i in range(1, len(listPosTrackingEmotion)): # print( "i: %d / %d" % (i,len( listPosTrackingEmotion) ) ); # print( "ratio: %f" % arListRatio[i] ); if (k in listPosTrackingEmotion[i][indexSquare]): rVal += listPosTrackingEmotion[i][indexSquare][ k] * arListRatio[i] else: bKeyInAllPos = False if (bKeyInAllPos): # print( "k: %s, rVal: %f" % ( k, rVal ) ); listPosResult[indexSquare][k] = rVal # for - each point of square end # for - end square # then we compute the center position relative of the 4 pose listPosResult = PoseLibrary.interpolatePositionXY_Mirror( listPosResult[0], listPosResult[1], listPosResult[2], listPosResult[3], arPosHead[0], arPosHead[1]) return listPosResult
def interpolateColorEmotion( arListRatio, rNeutral = 0. ): "create a color for each eyes mixed from 6 emotions colors and a neutral" "arListRatio: the ratio of each emotions: [Proud, Happy, Excitement, Fear, Sadness, Anger]" " if sum is greater than 1, it would be normalised" " if sum is lower than 1, a neutral position would be added" "rNeutral: to force an addition of a proportion of the neutral pose" "return a RGB hexa code describing the left eyes (use mirror for right eye)" debug.debug( "interpolateColorEmotion( %s, %f )" % ( str( arListRatio ), rNeutral ) ); # preparation of the ratio rSum = arraytools.arraySum( arListRatio ); rEpsilon = 0.001; if( rNeutral < rEpsilon and rSum < 1. ): rNeutral = 1. - rSum; rSumTotal = rSum + rNeutral; if( rSumTotal > 1. ): # normalisation for i in range( len( arListRatio ) ): arListRatio[i] /= rSumTotal; rNeutral /= rSumTotal; # push zeroes for others emotions: for i in range( len( arListRatio ), 6 ): arListRatio.append( 0. ); anColorNeutral = arraytools.arrayCreate( 8, 0x0000FF ); listColorEmotion = getListColorEmotion(); if( rNeutral > 0.001 ): listColorEmotion.append( anColorNeutral ); arListRatio.append( rNeutral ); anColor = arraytools.arrayCreate( 8, [0.,0.,0.] ); #~ print( "arListRatio: %s" % str( arListRatio ) ); #~ print( "listColorEmotion: %s" % str( listColorEmotion ) ); #~ print( "anColorNeutral: %s" % str( anColorNeutral ) ); #~ print( "anColor: %s" % str( anColor ) ); # hexa to comp rgb arListColorEmotionRGB = []; for nNumEmotion in range( len( listColorEmotion ) ): arListColorEmotionRGB.append( [] ); for led in listColorEmotion[nNumEmotion]: arListColorEmotionRGB[nNumEmotion].append( color.colorHexaToComp( led ) ); # interpolation stuff for nNumEmotion in range( len( arListColorEmotionRGB ) ): for nNumLed in range( len( anColor ) ): for nNumComposanteRGB in range( 3 ): anColor[nNumLed][nNumComposanteRGB] += arListRatio[nNumEmotion] * arListColorEmotionRGB[nNumEmotion][nNumLed][nNumComposanteRGB]; # print( "anColor2: %s" % str( anColor ) ); # median and rgb to hexa for nNumLed in range( len( anColor ) ): # we haven't to divide in rgb space ! #~ for nNumComposanteRGB in range( 3 ): #~ anColor[nNumLed][nNumComposanteRGB] = anColor[nNumLed][nNumComposanteRGB] / len( arListColorEmotionRGB ); anColor[nNumLed] = color.colorCompToHexa( anColor[nNumLed][2], anColor[nNumLed][1], anColor[nNumLed][0] ); return anColor;