summaryrefslogtreecommitdiff
path: root/canny-single.py
blob: 749067ad176a627fef288548b9decf1e1ed146dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from options.test_options import TestOptions
from shutil import move, copyfile
from PIL import Image, ImageOps
from shutil import copyfile, rmtree
import numpy as np
import cv2

import subprocess
from time import sleep

if __name__ == '__main__':
    opt = TestOptions().parse()
    opt.nThreads = 1   # test code only supports nThreads = 1
    opt.batchSize = 1  # test code only supports batchSize = 1
    opt.serial_batches = True  # no shuffle
    opt.no_flip = True  # no flip
    opt.experiment = opt.start_img

    render_dir = opt.results_dir + opt.experiment + "/"

    if os.path.exists(render_dir):
        rmtree(render_dir)
    mkdirs(render_dir)
    i = 0
    for f in sorted(os.listdir(opt.start_img)):
        if not os.path.isfile(f):
            continue
        pil_image = Image.open(f).convert('RGB')
        opencv_image = np.array(pil_image)
        opencv_image = opencv_image[:, :, ::-1].copy()
        opencv_image = cv2.GaussianBlur(opencv_image, (3,3), 1)
        opencv_image = cv2.Canny(opencv_image, 100, 200)
        cv2.imwrite(render_dir + "frame_{:04d}.png".format(i), opencv_image)
        i += 1