예제 #1
0
def process_video(video_in, checkpoint, video_out):
    in_dir = os.path.join(TMP_DIR, 'in')
    out_dir = os.path.join(TMP_DIR, 'out')
    if not os.path.exists(in_dir):
        os.makedirs(in_dir)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    in_args = [
        'ffmpeg',
        '-i', video_in,
        '%s/frame_%%d.png' % in_dir
    ]

    subprocess.call(" ".join(in_args), shell=True)
    base_names = list_files(in_dir)
    in_files = [os.path.join(in_dir, x) for x in base_names]
    out_files = [os.path.join(out_dir, x) for x in base_names]
    evaluate.ffwd(in_files, out_files, checkpoint, device_t=DEVICE,
                  batch_size=BATCH_SIZE)
    fr = 30  # wtf
    out_args = [
        'ffmpeg',
        '-i', '%s/frame_%%d.png' % out_dir,
        '-f', 'mp4',
        '-q:v', '0',
        '-vcodec', 'mpeg4',
        '-r', str(fr),
        video_out
    ]

    subprocess.call(" ".join(out_args), shell=True)
    print('Video at: %s' % video_out)
    shutil.rmtree(TMP_DIR)
예제 #2
0
파일: app.py 프로젝트: enkeboll/demo-0826
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)

            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            ffwd(['uploads/' + filename], ['results/' + filename], batch_size=1)
            return redirect(url_for('uploaded_file',
                                    filename=filename))
    template = Template('''
    <!doctype html>
    <title>Upload new File</title>
    <h1>Upload new File</h1>
    <h3>My secret is {{ secret }}</h3>
    <form method=post enctype=multipart/form-data>
      <input type=file name=file>
      <input type=submit value=Upload>
    </form>
    ''')
    secret = os.getenv('MY_SECRET_PASSWORD')
    return template.render(secret=secret)
예제 #3
0
def main():
    parser = build_parser()
    opts = parser.parse_args()

    in_dir = os.path.join(opts.tmp_dir, 'in')
    out_dir = os.path.join(opts.tmp_dir, 'out')
    if not os.path.exists(in_dir):
        os.makedirs(in_dir)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    in_args = ['ffmpeg', '-i', opts.in_path, '%s/frame_%%d.png' % in_dir]

    subprocess.call(" ".join(in_args), shell=True)
    base_names = list_files(in_dir)
    in_files = map(lambda x: os.path.join(in_dir, x), base_names)
    out_files = map(lambda x: os.path.join(out_dir, x), base_names)
    evaluate.ffwd(in_files,
                  out_files,
                  opts.checkpoint,
                  device_t=opts.device,
                  batch_size=opts.batch_size)
    fr = 30  # wtf
    out_args = [
        'ffmpeg', '-i',
        '%s/frame_%%d.png' % out_dir, '-f', 'mp4', '-q:v', '0', '-vcodec',
        'mpeg4', '-r',
        str(fr), opts.out
    ]

    subprocess.call(" ".join(out_args), shell=True)
    print 'Video at: %s' % opts.out
    shutil.rmtree(opts.tmp_dir)
예제 #4
0
def random_style_transfer(in_path = 'images/', out_path = 'processed_images/', checkpoint_path = 'checkpoints', allow_different_dimensions = True, batch_size = 1, device = '/gpu:0'):
    checkpoints = list_files(checkpoint_path)
    files = [fname for fname in list_files(in_path) if fname not in list_files('processed_images/')]
    fullprocess = [(os.path.join(in_path,x),os.path.join(out_path,x),f'{checkpoint_path}/{random.sample(checkpoints,1)[0]}') for x in files]
    for tup in fullprocess:
        print(tup)
        if allow_different_dimensions:
            ffwd_different_dimensions([tup[0]], [tup[1]], tup[2], 
                    device_t=device, batch_size=batch_size)
        else :
            ffwd([tup[0]], [tup[1]], tup[2], device_t=device,
                    batch_size=batch_size)
예제 #5
0
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)

            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            ffwd(['uploads/' + filename], ['results/' + filename], batch_size=1)
            return redirect(url_for('uploaded_file',
                                    filename=filename))
    return '''
def main():
    parser = build_parser()
    opts = parser.parse_args()

    if opts.no_disk:
        evaluate.from_pipe(opts)
    else:
        in_dir = os.path.join(opts.tmp_dir, 'in')
        out_dir = os.path.join(opts.tmp_dir, 'out')
        if not os.path.exists(in_dir):
            os.makedirs(in_dir)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        in_args = [
            'ffmpeg',
            '-i', opts.in_path,
            '%s/frame_%%d.png' % in_dir
        ]

        subprocess.call(" ".join(in_args), shell=True)
        base_names = list_files(in_dir)
        in_files = list(map(lambda x: os.path.join(in_dir, x), base_names))
        out_files = list(map(lambda x: os.path.join(out_dir, x), base_names))
        evaluate.ffwd(in_files, out_files, opts.checkpoint, device_t=opts.device,
                      batch_size=opts.batch_size)
        fr = 30 # wtf
        out_args = [
            'ffmpeg',
            '-i', '%s/frame_%%d.png' % out_dir,
            '-f', 'mp4',
            '-q:v', '0',
            '-vcodec', 'mpeg4',
            '-r', str(fr),
            opts.out
        ]

        subprocess.call(" ".join(out_args), shell=True)
        print('Video at: %s' % opts.out)
        shutil.rmtree(opts.tmp_dir)
예제 #7
0
os.system('sudo service motion stop')

pygame.init()

screen = pygame.display.set_mode((1040, 780))

styles = [r'./style/'+i+r'.ckpt' for i in ['la_muse','rain_princess','scream','udnie','wave','wreck']]

inpath=r'./in/'
outpath=r'./out/'

count=0

while(True):
    realinpath = inpath+str(count)+'.jpg'
    realoutpath = outpath+str(count)+'.jpg'
    curtime = time.time()
    os.system('fswebcam -r 640x480 -S 20  --no-banner --save '+realinpath)    
    evaluate.ffwd([realinpath],
     [realoutpath],
     styles[count%len(styles)], device_t='/gpu:0', batch_size=4)
    print('PROCESSING TOOK {:.1f} SECONDS'.format(time.time()-curtime))
    image = pygame.image.load(realoutpath)
    image = pygame.transform.scale(image, (1040, 780))
    retarea = screen.blit(image, (0, 0))
    pygame.display.update(retarea)
    count+=1



예제 #8
0
def getstyled(data_in):
    paths_out = "styled"
    checkpoint_dir = random.choice(ckpoints)
    ffwd(data_in, paths_out, checkpoint_dir, device_t='/cpu:0', batch_size=1)
    return paths_out