Exemple #1
0
import os
import os.path as osp
import numpy as np
import time
import sys

if len(sys.argv) <= 1:
    print('Usage: main.py <video_file>')
    exit(1)

video_path = sys.argv[1]
print('Performing optical flow on {}...'.format(video_path))
video_name = os.path.splitext(os.path.basename(video_path))[0]

db = Database()
if not db.has_table(video_name):
    db.ingest_videos([(video_name, video_path)])
input_table = db.table(video_name)

frame = db.sources.FrameColumn()
flow = db.ops.OpticalFlow(
    frame = frame,
    device=DeviceType.CPU)
sampled_flow = db.streams.Range(flow, 0, 60)
output = db.sinks.Column(columns={'flow': sampled_flow})

job = Job(op_args={
    frame: input_table.column('frame'),
    output: input_table.name() + '_flow'
})
[output_table] = db.run(output=output, jobs=[job],
Exemple #2
0
import math
import os
import subprocess
import cv2
import sys
import os.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../..')
import util
import numpy as np

util.download_video()

db = Database()

video_path = util.download_video()
if True or not db.has_table('example'):
    print('Ingesting video into Scanner ...')
    db.ingest_videos([('example', video_path)], force=True)

input_table = db.table('example')

descriptor = NetDescriptor.from_file(db, 'nets/faster_rcnn_coco.toml')
caffe_args = db.protobufs.CaffeArgs()
caffe_args.net_descriptor.CopyFrom(descriptor.as_proto())
caffe_args.batch_size = 1

frame = db.ops.FrameInput()
caffe_frame = db.ops.CaffeInput(frame=frame,
                                args=caffe_args,
                                device=DeviceType.CPU)
cls_prob, rois, fc7 = db.ops.FasterRCNN(caffe_input=caffe_frame,
Exemple #3
0
                y = int(pose[i, 1] * frame.shape[0])
                cv2.circle(frame, (x, y), 8, (255, 0, 0), 3)
        return frame


if len(sys.argv) <= 1:
    print('Usage: main.py <video_file>')
    exit(1)

movie_path = sys.argv[1]
print('Detecting poses in video {}'.format(movie_path))
movie_name = os.path.splitext(os.path.basename(movie_path))[0]

db = Database()
video_path = movie_path
if not db.has_table(movie_name):
    print('Ingesting video into Scanner ...')
    db.ingest_videos([(movie_name, video_path)], force=True)
input_table = db.table(movie_name)

sampler = db.streams.Range
sampler_args = {'start': 120, 'end': 480}

[poses_table] = pipelines.detect_poses(db, [input_table.column('frame')],
                                       sampler, sampler_args,
                                       '{:s}_poses'.format(movie_name))

print('Drawing on frames...')
frame = db.sources.FrameColumn()
sampled_frame = sampler(frame)
poses = db.sources.Column()
Exemple #4
0
from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import parsers
import os.path as osp
import numpy as np

db = Database()

if not db.has_table('example'):
    db.ingest_videos([('example', 'example.mp4')])
input_table = db.table('example')

frame, frame_info = input_table.as_op().all(warmup_size = 1)

flow = db.ops.OpticalFlow(
    frame = frame, frame_info = frame_info,
    device=DeviceType.GPU)

job = Job(columns = [flow, frame_info], name = 'example_flows')

output_table = db.run(job)

vid_flows = [flow for _, flow in output_table.load(['flow', 'frame_info'], parsers.flow)]
np.save('flows.npy', vid_flows)