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'))
def runSimpleOpt(src, tot=-1, sel=0.1):
    cleanUp()

    manager = SimpleStorageManager('videos')
    now = timer()
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 100,
                    'num_processes': 4
                })
    put_time = timer() - now
    print("Put time for simple:", put_time)

    region = Box(515, 200, 700, 600)

    sel = sel / 2

    clips = manager.get('test', lambda f: True)
    pipelines = []
    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)]
        d = SplitterOptimizer()
        pipelines.append(d.optimize(pipeline))

    result = counts(pipelines, ['one'], stats=True)

    logrecord('simple', ({'file': src}), 'get', str(result), 's')
def runFullOpt(src, tot=1000, sel=0.1):
    cleanUp()

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=20),
        CropSplitter(), 'videos')
    now = timer()
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 20,
                    'num_processes': 4,
                    'background_scale': 1
                })
    put_time = timer() - now
    print("Put time for full opt:", put_time)

    left = Box(1600, 1600, 1700, 1800)
    middle = Box(1825, 1600, 1975, 1800)
    right = Box(2050, 1600, 2175, 1800)
    sel = sel / 2

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

    pipelines = []
    d = SplitterOptimizer()
    for c in clips:
        pipeline = c[GoodKeyPoints()][ActivityMetric(
            'left', left)][ActivityMetric('middle', middle)][ActivityMetric(
                'right',
                right)][Filter('left', [1, 1, 1], 3,
                               delay=25)][Filter('middle', [1, 1, 1],
                                                 3,
                                                 delay=25)][Filter('right',
                                                                   [1, 1, 1],
                                                                   3,
                                                                   delay=25)]
        pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['left', 'middle', 'right'], stats=True)

    logrecord('fullopt', ({
        'size': tot,
        'sel': sel,
        'file': src
    }), 'get', str(result), 's')
def runNaiveOpt(src, tot=-1, sel=0.1):
    cleanUp()

    c = VideoStream(src, limit=tot)
    sel = sel / 2
    region = Box(515, 200, 700, 600)
    pipelines = \
    c[KeyPoints()][ActivityMetric('one', region)][
        Filter('one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
    d = SplitterOptimizer()
    pipelines = d.optimize(pipelines)
    result = count(pipelines, ['one'], stats=True)

    logrecord('naive', ({'file': src}), 'get', str(result), 's')
def runFullOpt(src, tot=1000, sel=0.1):
    cleanUp()

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=20),
        CropSplitter(), 'videos')
    now = timer()
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 20,
                    'num_processes': 4,
                    'background_scale': 1
                })
    put_time = timer() - now
    print("Put time for simple:", put_time)

    region = Box(200, 550, 350, 750)
    sel = sel / 2

    clips = manager.get(
        'test',
        Condition(label='foreground',
                  custom_filter=time_filter(tot // 2 - int(tot * sel),
                                            tot // 2 + int(tot * sel))))

    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)]
        pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['one'], stats=True)

    logrecord('fullopt', ({
        'size': tot,
        'sel': sel,
        'file': src
    }), 'get', str(result), 's')
Exemple #6
0
def runFullOpt(src, tot=1000, sel=0.1):
    cleanUp()

    manager = FullStorageManager(
        CustomTagger(FixedCameraBGFGSegmenter(movement_threshold=21,
                                              blur=7,
                                              movement_prob=0.10).segment,
                     batch_size=100), CropSplitter(), 'videos')
    manager.put(src,
                'test',
                args={
                    'encoding': XVID,
                    'size': -1,
                    'sample': 1.0,
                    'offset': 0,
                    'limit': tot,
                    'batch_size': 100
                })

    region = Box(500, 350, 750, 450)
    sel = sel / 2

    clips = manager.get(
        'test',
        Condition(label='foreground',
                  custom_filter=time_filter(tot // 2 - int(tot * sel),
                                            tot // 2 + int(tot * sel))))

    pipelines = []
    d = SplitterOptimizer()
    for c in clips:
        pipeline = c[KeyPoints(blur=3)][ActivityMetric('one', region)][Filter(
            'one', [-0.5, 1, -0.5], 0.25, delay=40)]
        pipeline = d.optimize(pipeline)
        pipelines.append(pipeline)

    result = counts(pipelines, ['one'], stats=True)

    logrecord('fullopt', ({
        'size': tot,
        'sel': sel,
        'file': src
    }), 'get', str(result), 's')
Exemple #7
0
def doexperiments_ks(budget=1000000000):

    for i in range(0, 300, 50):
        cleanUp()

        manager = FullStorageManager(
            CustomTagger(FixedCameraBGFGSegmenter().segment, batch_size=100),
            CropSplitter(), 'videos')
        manager.put('tcam.mp4',
                    'test',
                    args={
                        'encoding': XVID,
                        'size': -1,
                        'sample': 1.0,
                        'offset': 0,
                        'limit': 2000,
                        'batch_size': 100,
                        'num_processes': 4,
                        'background_scale': 1
                    })
        clips = manager.get('test', Condition(label='foreground'))

        region = spatial_selectivity(buffer=i)

        d = SplitterOptimizer()
        pipelines = []
        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)]
            pipeline = d.optimize(pipeline)
            pipelines.append(pipeline)

        result, time1 = counts(pipelines, ['one'], stats=True)
        d.cacheKnapsack(manager, budget)

        clips = manager.get('test', Condition(label='foreground'))
        pipelines = []
        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)]
            pipeline = d.optimize(pipeline)
            pipelines.append(pipeline)

        result, time2 = counts(pipelines, ['one'], stats=True)

        print(i, budget, time1['elapsed'], time2['elapsed'])
from splitter.full_manager.full_manager import FullStorageManager
from splitter.optimizer.splitter import SplitterOptimizer
from splitter.struct import CustomTagger, VideoStream, Box
from splitter.tracking.contour import KeyPoints
from splitter.tracking.event import Filter, ActivityMetric

if len(sys.argv) < 2:
    print("Enter filename as argv[1]")
    exit(1)
filename = sys.argv[1]

vs = VideoStream(filename, hwang=True, rows=range(0, 8000, 400))

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

d = SplitterOptimizer()
pipeline = vs[KeyPoints()][ActivityMetric('one', region)][Filter(
    'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
# pipeline = d.optimize(pipeline)

result = count(pipeline, ['one'], stats=True)
print("Hwang:", result)

vs = VideoStream(filename, hwang=False, limit=500)

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

d = SplitterOptimizer()
pipeline = vs[KeyPoints()][ActivityMetric('one', region)][Filter(
    'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
# pipeline = d.optimize(pipeline)
Exemple #9
0
from splitter.optimizer.splitter import SplitterOptimizer

for i in range(10, 1, -1):
    scale = i / 10.0
    new_file = set_quality('tcam.mp4', 'tcam-' + str(scale) + ".avi", 25,
                           scale)
    c = VideoStream('tcam-' + str(scale) + ".avi", limit=1000)
    region = Box(200, 550, 350, 750)

    #print(scale, )
    #region2 = Box(region.x0*scale, region.y0*scale, region.x1*scale, region.y1*scale)
    #region3 = Box(region.x0*scale*1.1, region.y0*scale*1.1, region.x1*scale*1.1, region.y1*scale*1.1)
    #scale = get_scale('tcam-'+str(scale)+".avi")

    d = SplitterOptimizer(adaptive_blur=True)
    pipelines = c[KeyPoints()][ActivityMetric('one', region)][Filter(
        'one', [-0.25, -0.25, 1, -0.25, -0.25], 1.5, delay=10)]
    d.optimize(pipelines)

    result = count(pipelines, ['one'], stats=True)
    print('Resolution', scale, result)
"""
for i in range(25,60,3):
	region = Box(200,550,350,750)
	from splitter.optimizer.splitter import SplitterOptimizer
	d = SplitterOptimizer(adaptive_blur=True)
	v = VideoStream(str(i)+'tcam.avi', limit=1000)
	v = v[KeyPoints()][ActivityMetric('one', region)][Filter('one', [-0.25,-0.25,1,-0.25,-0.25],1.5, delay=10)]
	#c = IteratorVideoStream(itertools.chain(*v), v)
	d.optimize(v)