MCPcopy Create free account
hub / github.com/TaoRuijie/TalkNet-ASD / visualization

Function visualization

demoTalkNet.py:255–283  ·  view source on GitHub ↗
(tracks, scores, args)

Source from the content-addressed store, hash-verified

253 return allScores
254
255def visualization(tracks, scores, args):
256 # CPU: visulize the result for video format
257 flist = glob.glob(os.path.join(args.pyframesPath, '*.jpg'))
258 flist.sort()
259 faces = [[] for i in range(len(flist))]
260 for tidx, track in enumerate(tracks):
261 score = scores[tidx]
262 for fidx, frame in enumerate(track['track']['frame'].tolist()):
263 s = score[max(fidx - 2, 0): min(fidx + 3, len(score) - 1)] # average smoothing
264 s = numpy.mean(s)
265 faces[frame].append({'track':tidx, 'score':float(s),'s':track['proc_track']['s'][fidx], 'x':track['proc_track']['x'][fidx], 'y':track['proc_track']['y'][fidx]})
266 firstImage = cv2.imread(flist[0])
267 fw = firstImage.shape[1]
268 fh = firstImage.shape[0]
269 vOut = cv2.VideoWriter(os.path.join(args.pyaviPath, 'video_only.avi'), cv2.VideoWriter_fourcc(*'XVID'), 25, (fw,fh))
270 colorDict = {0: 0, 1: 255}
271 for fidx, fname in tqdm.tqdm(enumerate(flist), total = len(flist)):
272 image = cv2.imread(fname)
273 for face in faces[fidx]:
274 clr = colorDict[int((face['score'] >= 0))]
275 txt = round(face['score'], 1)
276 cv2.rectangle(image, (int(face['x']-face['s']), int(face['y']-face['s'])), (int(face['x']+face['s']), int(face['y']+face['s'])),(0,clr,255-clr),10)
277 cv2.putText(image,'%s'%(txt), (int(face['x']-face['s']), int(face['y']-face['s'])), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0,clr,255-clr),5)
278 vOut.write(image)
279 vOut.release()
280 command = ("ffmpeg -y -i %s -i %s -threads %d -c:v copy -c:a copy %s -loglevel panic" % \
281 (os.path.join(args.pyaviPath, 'video_only.avi'), os.path.join(args.pyaviPath, 'audio.wav'), \
282 args.nDataLoaderThread, os.path.join(args.pyaviPath,'video_out.avi')))
283 output = subprocess.call(command, shell=True, stdout=None)
284
285def evaluate_col_ASD(tracks, scores, args):
286 txtPath = args.videoFolder + '/col_labels/fusion/*.txt' # Load labels

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected