def runFullSequential(src, cleanUp=False):
    if cleanUp:
        if os.path.exists('./videos_full'):
            shutil.rmtree('./videos_full')

    manager = FullStorageManager(None, CropSplitter(), 'videos_full')
    now = timer()
    manager.put(src,
                os.path.basename(src),
                parallel=False,
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': -1,
                    'batch_size': 50,
                    'num_processes': os.cpu_count()
                })
    put_time = timer() - now
    logrecord('full', ({'file': src}), 'put', str({'elapsed': put_time}), 's')

    clips = manager.get(os.path.basename(src), Condition())
    pipelines = []
    for c in clips:
        pipelines.append(c[KeyPoints()])
    result = counts(pipelines, ['one'], stats=True)
    logrecord('full', ({'file': src}), 'get', str(result), 's')
def runFullPutMany(src_list, cleanUp=False):
    if cleanUp:
        if os.path.exists('./videos_full'):
            shutil.rmtree('./videos_full')

    manager = FullStorageManager(None, CropSplitter(), 'videos_full')
    now = timer()
    targets = [os.path.basename(src) for src in src_list]
    logs = manager.put_many(src_list,
                            targets,
                            log=True,
                            args={
                                'encoding': XVID,
                                'size': -1,
                                'sample': 1.0,
                                'offset': 0,
                                'limit': -1,
                                'batch_size': 50,
                                'num_processes': os.cpu_count()
                            })
    put_time = timer() - now
    logrecord('full', ({
        'file': src_list
    }), 'put', str({'elapsed': put_time}), 's')
    for i, log in enumerate(logs):
        logrecord('fullMany', i, 'put', str({'elapsed': log}), 's')
def runSimple(src, cleanUp=False):
    if cleanUp:
        if os.path.exists('./videos_simple'):
            shutil.rmtree('./videos_simple')

    manager = SimpleStorageManager('videos_simple')
    now = timer()
    manager.put(src,
                os.path.basename(src),
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': -1,
                    'batch_size': 50
                })
    put_time = timer() - now
    logrecord('simple', ({
        'file': src
    }), 'put', str({'elapsed': put_time}), 's')

    clips = manager.get(os.path.basename(src), lambda f: True)
    pipelines = []
    for c in clips:
        pipelines.append(c[KeyPoints()])
    result = counts(pipelines, ['one'], stats=True)
    logrecord('simple', ({'file': src}), 'get', str(result), 's')
예제 #4
0
def test_put(src, cleanUp=False):
    if cleanUp:
        if os.path.exists('./videos'):
            shutil.rmtree('./videos')
    manager = FullStorageManager(None, CropSplitter(), 'videos')
    start = time.time()
    manager.put(src,
                os.path.basename(src),
                parallel=True,
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': -1,
                    'batch_size': 50,
                    'num_processes': 6
                })
    print("Put time:", time.time() - start)
    clips = manager.get(os.path.basename(src), Condition(label='person'))
    pipelines = []
    for c in clips:
        pipelines.append(c[KeyPoints()])
    result = counts(pipelines, ['one'], stats=True)
    logrecord('full', ({'file': src}), 'get', str(result), 's')
예제 #5
0
def runFull(src, cache=False, cleanUp=True, limit=6000, optimizer=True):
    if cleanUp:
        if os.path.exists('/tmp/videos'):
            shutil.rmtree('/tmp/videos')

    manager = FullStorageManager(CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=30), CropSplitter(),
                                 '/tmp/videos')
    manager.put(src, 'test',
                args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': limit, 'batch_size': 30,
                      'num_processes': 4, 'background_scale': 1}, hwang=False)
    if cache:
        manager.cache('test', Condition(label='foreground'), hwang=False)

    clips = manager.get('test', Condition(label='foreground'))

    region = Box(200, 550, 350, 750)

    pipelines = []
    d = SplitterOptimizer()
    for c in clips:
        pipeline = c[KeyPoints()][ActivityMetric('one', region)][
            Filter('one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
        if optimizer:
            pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['one'], stats=True)
    logrecord('full', ({'size': limit, 'cache': cache, 'optimizer': optimizer, 'file': src,
                         'folder_size': get_size('/tmp/videos')}), 'get', str(result), 's')
    if cache:
        manager.uncache('test', Condition(label='foreground'))
예제 #6
0
def runFull(src, cleanUp = False):
    if cleanUp:
        if os.path.exists('./videos_full'):
            shutil.rmtree('./videos_full')

    manager = FullStorageManager(None, CropSplitter(), 'videos_full')
    now = timer()
    manager.put(src, os.path.basename(src), parallel = True, args={'encoding': XVID, 'size': -1, 'sample': 1.0, 'offset': 0, 'limit': -1, 'batch_size': 30, 'num_processes': os.cpu_count()})
    put_time = timer() - now
    logrecord('full', ({'file': src}), 'put', str({'elapsed': put_time}), 's')
예제 #7
0
def runNaive(src, cleanUp = False):
    if cleanUp:
        if os.path.exists('./videos_naive'):
            shutil.rmtree('./videos_naive')

    c = VideoStream(src)
    pipelines = c[KeyPoints()]
    result = count(pipelines, ['one'], stats=True)

    logrecord('naive',({'file': src}), 'get', str(result), 's')
예제 #8
0
def fullQuality(index=0):

    if os.path.exists('videos'):
        shutil.rmtree('videos')

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter(blur=11,
                                              movement_threshold=11).segment,
                     batch_size=200), CropSplitter(), 'videos')

    now = datetime.datetime.now()

    filename = FOLDER + 'crash{0}.mp4'.format(index)

    manager.put(filename,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': -1,
                    'batch_size': 200,
                    'num_processes': 4,
                    'background_scale': 1
                },
                hwang=False)

    #no queries to the background, lowest quality for speed to be within 5%
    manager.set_quality('test',
                        Condition(label='background'),
                        qscale=52,
                        rscale=0.1)
    manager.set_quality('test',
                        Condition(label='foreground'),
                        qscale=44,
                        rscale=1)

    put_result = (datetime.datetime.now() - now).total_seconds()

    logrecord('fullq', ({
        'folder_size': get_size('videos')
    }), 'put', str(put_result), 's')

    now = datetime.datetime.now()

    clips = manager.get('test', Condition(label='foreground'))
    for c in clips:
        pipeline_get(c[MotionVectors()][Speed()])

    result = (datetime.datetime.now() - now).total_seconds()

    logrecord('fullq', ({
        'folder_size': get_size('videos')
    }), 'get', str(result), 's')
예제 #9
0
def runFull(src, cleanUp=True, limit=-1, background_scale=1, optimizer=False):
    if cleanUp:
        if os.path.exists('/tmp/videos'):
            shutil.rmtree('/tmp/videos')

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=30),
        CropSplitter(), '/tmp/videos')
    start = time.time()
    output = manager.put(src,
                         'test',
                         parallel=False,
                         args={
                             'encoding': XVID,
                             'size': -1,
                             'sample': 1.0,
                             'offset': 0,
                             'limit': limit,
                             'batch_size': 30,
                             'background_scale': background_scale
                         })
    end = time.time()

    clips = manager.get('test', Condition(label='foreground'))

    region = Box(200, 550, 350, 750)

    pipelines = []
    d = DeepLensOptimizer()
    for c in clips:
        pipeline = c[KeyPoints()][ActivityMetric('one', region)][Filter(
            'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
        if optimizer:
            pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['one'], stats=True)
    logrecord('full', ({
        'size': limit,
        'optimizer': optimizer,
        'file': src,
        'background_scale': background_scale,
        'folder_size': get_size('/tmp/videos')
    }), 'get', str(result), 's', 'put', str(end - start), 's')
예제 #10
0
def naive(index=0):

    if os.path.exists('videos'):
        shutil.rmtree('videos')

    now = datetime.datetime.now()

    filename = FOLDER + 'crash{0}.mp4'.format(index)

    v = VideoStream(filename)
    pipeline = v[MotionVectors()][Speed()]

    pipeline_get(pipeline)

    result = (datetime.datetime.now() - now).total_seconds()

    logrecord('naive', ({
        'folder_size': os.path.getsize(filename)
    }), 'get', str(result), 's')
예제 #11
0
def runFullPutMany(src_list, batch_size=30, cleanUp=False):
    if cleanUp:
        if os.path.exists('./videos_full'):
            shutil.rmtree('./videos_full')

    manager = FullStorageManager(None, CropSplitter(), 'videos_full')
    now = timer()
    targets = [os.path.basename(src) for src in src_list]
    logs = manager.put_many(src_list,
                            targets,
                            log=True,
                            args={
                                'encoding': XVID,
                                'size': -1,
                                'sample': 1.0,
                                'offset': 0,
                                'limit': -1,
                                'batch_size': batch_size,
                                'num_processes': os.cpu_count()
                            })
    put_time = timer() - now
    logrecord('full', ({
        'file': src_list
    }), 'put', str({'elapsed': put_time}), 's')
    for i, log in enumerate(logs):
        logrecord('fullMany', i, 'put', str({'elapsed': log}), 's')

    # Don't call get() for now
    for src in src_list:
        clips = manager.get(os.path.basename(src), Condition())
        pipelines = []
        for c in clips:
            pipelines.append(c[KeyPoints()])
        result = counts(pipelines, ['one'], stats=True)
        logrecord('full', ({'file': src}), 'get', str(result), 's')
pipeline = v
frame_rate = 10
writers = {}
width = {}
height = {}
filenames = {}
fourcc = cv2.VideoWriter_fourcc(*MP4V)
folder = '/tmp/miris/'

now = timer()
for i in pipeline:
    pass

logrecord('naive', ({
    'folder_size': os.path.getsize(sys.argv[1])
}), 'get', str(timer() - now), 's')

now = timer()
for p in pipeline:
    image = p['data']
    if labels[p['frame']] == None:
        continue
    bboxes = [(str(label['track_id']),
               (label['left'] // 2, label['top'] // 2, label['right'] // 2,
                label['bottom'] // 2)) for label in labels[p['frame']]]

    for id, bbox in bboxes:
        filenames[id] = folder + str(id) + '.avi'
        if id not in writers:
            width[id] = bbox[2] - bbox[0]