def test_fprint(self): face_anno = FaceAnnotator( detector=FaceDetectDlib(), embedding=FaceEmbedVgg2(), freq=4 ) fpobj = FrameProcessor() fpobj.load_annotator(face_anno) finput = FrameInput("test-data/video-clip.mp4", bsize=8) fpobj.process(finput, max_batch=2) obj_out = fpobj.collect_all() pa = PeopleAggregator( face_names=["person 1", "person 2"], fprint=obj_out["face"]["embed"][[0, 1]], ) agg = pa.aggregate(obj_out).todf() assert set(agg.keys()) == set( [ "video", "frame", "top", "bottom", "right", "left", "confidence", "person", "person-dist", ] )
def test_collect_all(self): fpobj = FrameProcessor() fpobj.load_annotator(FrameAnnotator()) fpobj.load_annotator(DiffAnnotator()) finput = FrameInput("test-data/video-clip.mp4", bsize=8) fpobj.process(finput, max_batch=2) output = fpobj.collect_all() assert output["base"] == DictFrame() assert output["diff"].shape[0] == (2 * 8)
def test_cutoff_empty(self): fpobj = FrameProcessor() fpobj.load_annotator(DiffAnnotator(quantiles=[40])) finput = FrameInput("test-data/video-clip.mp4", bsize=128) fpobj.process(finput, max_batch=2) obj_out = fpobj.collect_all() ca = CutAggregator() agg = ca.aggregate(obj_out) assert agg["frame_start"] == list(range(256))
def test_cutoff(self): fpobj = FrameProcessor() fpobj.load_annotator(DiffAnnotator(quantiles=[40])) finput = FrameInput("test-data/video-clip.mp4", bsize=128) fpobj.process(finput, max_batch=2) obj_out = fpobj.collect_all() ca = CutAggregator(cut_vals={"h40": 0.2, "q40": 3}) agg = ca.aggregate(obj_out) assert set(agg.keys()) == set(["video", "frame_start", "frame_end"])
def test_cutoff_ignore(self): fpobj = FrameProcessor() fpobj.load_annotator(DiffAnnotator(quantiles=[40])) finput = FrameInput("test-data/video-clip.mp4", bsize=128) fpobj.process(finput, max_batch=2) obj_out = fpobj.collect_all() ca = CutAggregator( cut_vals={"h40": 0.2, "q40": 3}, ignore_vals={"avg_value": 70} ) agg = ca.aggregate(obj_out) assert agg == DictFrame()
def main(argv): try: opts, args = getopt.getopt( argv, "hf:q:c:h:", ["file=", "quantiles=", "cutvals=", "histdiff="]) except getopt.GetoptError: print( 'dvt_to_sat.py -f <filename> -q <quantiles> -c <cutvals> -h <histdiff>' ) sys.exit(2) filename = '' quantiles = 40 cutvals = 3 histdiff = 0 for opt, arg in opts: if opt == '-h': print( 'dvt_to_sat.py -f <filename> -q <quantiles> -c <cutvals> -h <histdiff>' ) sys.exit() elif opt in ("-f", "--file"): filename = arg elif opt in ("-q", "--quantiles"): quantiles = arg elif opt in ("-c", "--cutvals"): cutvals = arg elif opt in ("-h", "--histdiff"): cutvals = arg if (filename == ''): print('missing param: filename is required') sys.exit(2) basename = os.path.basename(filename) logging.basicConfig(level='INFO') finput = FrameInput(filename, bsize=128) fpobj = FrameProcessor() fpobj.load_annotator(MetaAnnotator()) fpobj.load_annotator(DiffAnnotator(quantiles=[quantiles])) fpobj.process(finput) #fpobj.process(finput, max_batch=5) obj = fpobj.collect_all() meta = obj['meta'].todf() obj['diff'].todf().head() cagg = CutAggregator(cut_vals={ 'h40': histdiff, 'q' + str(quantiles): cutvals }) fps = meta['fps'][0] print(fps) df1 = cagg.aggregate(obj).todf() df1['seconds_start'] = df1['frame_start'] / fps df1['seconds_end'] = df1['frame_end'] / fps out = df1.to_csv() f = open(basename + ".csv", "w") f.write(out) f.close()