Extra parsing

This commit is contained in:
Ruben 2017-11-17 16:41:51 +01:00
parent 4f58f1a3cc
commit baa306763e

View file

@ -9,11 +9,13 @@ parser.add_argument('--frameOutput', '-o', required=True, help='directory to loo
args = parser.parse_args()
faces = []
class Face:
def __init__(self, frame, data):
self.id = data['id']
self.frame = frame # Frame class
self.data = data # json data
self.disonanceScore = None
def getFaceImg(self):
r = self.data['rect']
@ -50,9 +52,27 @@ class Frame:
j = self.getJson()
self.faces = [Face(self, f) for f in j['faces']]
faces.extend(self.faces)
return self.faces
def updateDisonanceScores(self):
totalValence = 0.0
totalFaces = 0
for face in self.getFaces():
totalValence += face.data['valence']
totalFaces += 1
if totalFaces == 0:
return
avgValence = totalValence / totalFaces
for face in self.getFaces():
face.disonanceScore = abs(face.data['valence'] - avgValence)
def exists(self):
return os.path.exists(self.jsonPath) and os.path.exists(self.imgPath)
@ -83,9 +103,9 @@ frames = loadFrames(args.frameOutput)
lastTime = None
for frameNr, frame in frames.items():
thisTime = frame.getJson()['t']
#~ print(frameNr, thisTime)
#print(frameNr, thisTime)
if not (lastTime is None) and lastTime > thisTime:
print "ERRROR!!"
print "ERRROR!! Time error at %s. Restarted scanner there?" % frameNr
lastTime = thisTime
faceDir = os.path.join(args.frameOutput, 'faces')
@ -105,7 +125,19 @@ def sumEmotions():
average = summed / items
print ("Total emotion %d, positivity score %d (average: %s)" % (total, summed, average))
def getMostDisonant(nr = 5):
for frameNr, frame in frames.items():
frame.updateDisonanceScores()
faces.sort(key=lambda x: x.disonanceScore, reverse=True)
mostDisonantFaces = faces[:5]
for face in mostDisonantFaces:
print("Frame %d, face %d, score %d, valence %d" % (face.frame.nr, face.id, face.disonanceScore, face.data['valence']))
face.getFaceImg().show()
sumEmotions()
getMostDisonant()
#~ for frameNr, frame in frames.items():
#~ cutOutFaces(frame, faceDir)