From baa306763eb45ad7a5c25dad48b2435b92dff1d6 Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 17 Nov 2017 16:41:51 +0100 Subject: [PATCH] Extra parsing --- parse_output.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/parse_output.py b/parse_output.py index 6ace657..e076a0c 100644 --- a/parse_output.py +++ b/parse_output.py @@ -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)