def main(invideofilename, facechainfilename, outvideofilename): faces = FaceChains() faces.__setstate__(common.json.loadfile(facechainfilename)) dir = tempfile.mkdtemp() try: from collections import defaultdict frames = defaultdict(list) maxframe = 0 for chain in faces.chains: # print chain color = ["red", "yellow", "green", "blue", "purple", "orange"][chain.__hash__() % 6] for i, face in chain.data: frames[i].append((face, color)) if i > maxframe: maxframe = i # print >> sys.stderr, frames for i, f, totframes in common.video.frames(invideofilename, maxframes=maxframe): outf = os.path.join(dir, "out%05d.jpg" % i) print >> sys.stderr, "Processing %s to %s, image %s" % ( f, outf, common.str.percent(i + 1, totframes)) print >> sys.stderr, stats() draw_faces(frames[i], f, outf) # I learned this command from here: http://electron.mit.edu/~gsteele/ffmpeg/ cmd = "ffmpeg -y -r 30 -b 10000k -i %s %s" % (os.path.join( dir, 'out%05d.jpg'), outvideofilename) print >> sys.stderr, "Stitching video together as test1800.mp4" print >> sys.stderr, cmd # import time # time.sleep(30) common.misc.runcmd(cmd) print >> sys.stderr, stats() finally: print >> sys.stderr, "Removing dir %s" % dir shutil.rmtree(dir)
def main(invideofilename, facechainfilename, outvideofilename): faces = FaceChains() faces.__setstate__(common.json.loadfile(facechainfilename)) dir = tempfile.mkdtemp() try: from collections import defaultdict frames = defaultdict(list) maxframe = 0 for chain in faces.chains: # print chain color = ["red", "yellow", "green", "blue", "purple", "orange"][chain.__hash__() % 6] for i, face in chain.data: frames[i].append((face, color)) if i > maxframe: maxframe = i # print >> sys.stderr, frames for i, f, totframes in common.video.frames(invideofilename, maxframes=maxframe): outf = os.path.join(dir, "out%05d.jpg" % i) print >> sys.stderr, "Processing %s to %s, image %s" % (f, outf, common.str.percent(i+1, totframes)) print >> sys.stderr, stats() draw_faces(frames[i], f, outf) # I learned this command from here: http://electron.mit.edu/~gsteele/ffmpeg/ cmd = "ffmpeg -y -r 30 -b 10000k -i %s %s" % (os.path.join(dir, 'out%05d.jpg'), outvideofilename) print >> sys.stderr, "Stitching video together as test1800.mp4" print >> sys.stderr, cmd # import time # time.sleep(30) common.misc.runcmd(cmd) print >> sys.stderr, stats() finally: print >> sys.stderr, "Removing dir %s" % dir shutil.rmtree(dir)
def main(facefilename): faces = Faces("") faces.__setstate__(common.json.loadfile(facefilename)) showedcnt = 0 # Construct one chain per face chains = [] for i, frame in enumerate(faces.frames): for face in frame: assert face.is_face() chain = [(i, face)] chains.append(FaceChain(chain)) chains.sort() facechains = FaceChains() facechains.copy_from_faces(faces) facechains.chains = chains facechains.join_nearby(1) facechains.deleteshortchains() facechains.gaussiansmoothchains() facechains.gaussiansmoothchains() print common.json.dumps(facechains.__getstate__())