diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-15 02:55:51 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-15 02:55:51 +0200 |
| commit | c0ac5b0820c70bccd828526f0fffa53047b72ff9 (patch) | |
| tree | b47c05d62edf516f0bdff4930d7626800e4ac394 | |
| parent | 30d23e0f445f2d0a2ca67499987ea079ba920de8 (diff) | |
test
| -rw-r--r-- | test-mogrify.py | 145 |
1 files changed, 72 insertions, 73 deletions
diff --git a/test-mogrify.py b/test-mogrify.py index 2ffadbb..3365126 100644 --- a/test-mogrify.py +++ b/test-mogrify.py @@ -36,96 +36,95 @@ if __name__ == '__main__': opt.render_dir = render_dir = opt.results_dir + opt.name + "/" + tag + "/" - print("create render_dir: {}".format(render_dir)) - if os.path.exists(render_dir): - rmtree(render_dir) - mkdirs(render_dir) + # print("create render_dir: {}".format(render_dir)) + # if os.path.exists(render_dir): + # rmtree(render_dir) + # mkdirs(render_dir) - # cmd = ("convert", opt.start_img, '-canny', '0x1+10%+30%', render_dir + "frame_00000.png") - # process = subprocess.Popen(cmd, stdout=subprocess.PIPE) - # output, error = process.communicate() + # # cmd = ("convert", opt.start_img, '-canny', '0x1+10%+30%', render_dir + "frame_00000.png") + # # process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + # # output, error = process.communicate() - copyfile(opt.start_img, render_dir + "frame_00000.png") + # copyfile(opt.start_img, render_dir + "frame_00000.png") - data_loader = CreateRecursiveDataLoader(opt) - dataset = data_loader.load_data() - ds = dataset.dataset - model = create_model(opt) - visualizer = Visualizer(opt) - # create website - # web_dir = os.path.join(opt.results_dir, opt.name, '%s_%s' % (opt.phase, opt.which_epoch)) - # webpage = html.HTML(web_dir, 'Experiment = %s, Phase = %s, Epoch = %s' % (opt.name, opt.phase, opt.which_epoch)) - # test - last_im = None - for i, data in enumerate(data_loader): - print(i) - if i >= opt.how_many: - break - model.set_input(data) - model.test() - visuals = model.get_current_visuals() - img_path = model.get_image_paths() + # data_loader = CreateRecursiveDataLoader(opt) + # dataset = data_loader.load_data() + # ds = dataset.dataset + # model = create_model(opt) + # visualizer = Visualizer(opt) + # # create website + # # web_dir = os.path.join(opt.results_dir, opt.name, '%s_%s' % (opt.phase, opt.which_epoch)) + # # webpage = html.HTML(web_dir, 'Experiment = %s, Phase = %s, Epoch = %s' % (opt.name, opt.phase, opt.which_epoch)) + # # test + # last_im = None + # for i, data in enumerate(data_loader): + # if i >= opt.how_many: + # break + # model.set_input(data) + # model.test() + # visuals = model.get_current_visuals() + # img_path = model.get_image_paths() - if (i % 100) == 0: - print('%04d: process image... %s' % (i, img_path)) - # ims = visualizer.save_images(webpage, visuals, img_path, aspect_ratio=opt.aspect_ratio) + # if (i % 20) == 0: + # print('%04d: process image... %s' % (i, img_path)) + # # ims = visualizer.save_images(webpage, visuals, img_path, aspect_ratio=opt.aspect_ratio) - im = visuals['fake_B'] - tmp_path = render_dir + "frame_{:05d}_tmp.png".format(i+1) - edges_path = render_dir + "frame_{:05d}.png".format(i+1) - render_path = render_dir + "ren_{:05d}.png".format(i+1) + # im = visuals['fake_B'] + # tmp_path = render_dir + "frame_{:05d}_tmp.png".format(i+1) + # edges_path = render_dir + "frame_{:05d}.png".format(i+1) + # render_path = render_dir + "ren_{:05d}.png".format(i+1) - image_pil = Image.fromarray(im, mode='RGB') - image_pil.save(tmp_path) - os.rename(tmp_path, render_path) + # image_pil = Image.fromarray(im, mode='RGB') + # image_pil.save(tmp_path) + # os.rename(tmp_path, render_path) - if dataset.name() == 'RecursiveDatasetDataLoader': - if data_opt.recursive and last_im is not None: - tmp_im = im.copy() + # if dataset.name() == 'RecursiveDatasetDataLoader': + # if data_opt.recursive and last_im is not None: + # tmp_im = im.copy() - frac_a = data_opt.recursive_frac - frac_b = 1.0 - frac_a + # frac_a = data_opt.recursive_frac + # frac_b = 1.0 - frac_a - array_a = np.multiply(im.astype('float64'), frac_a) - array_b = np.multiply(last_im.astype('float64'), frac_b) - im = np.add(array_a, array_b).astype('uint8') - # print(im.shape, im.dtype) - last_im = np.roll(tmp_im, 1, axis=1) - else: - last_im = im.copy().astype('uint8') - tmp_im = im.copy().astype('uint8') - #print(im.shape, im.dtype) + # array_a = np.multiply(im.astype('float64'), frac_a) + # array_b = np.multiply(last_im.astype('float64'), frac_b) + # im = np.add(array_a, array_b).astype('uint8') + # # print(im.shape, im.dtype) + # last_im = np.roll(tmp_im, 1, axis=1) + # else: + # last_im = im.copy().astype('uint8') + # tmp_im = im.copy().astype('uint8') + # #print(im.shape, im.dtype) - image_pil = Image.fromarray(im, mode='RGB') - im = np.asarray(image_pil).astype('uint8') - #print(im.shape, im.dtype) + # image_pil = Image.fromarray(im, mode='RGB') + # im = np.asarray(image_pil).astype('uint8') + # #print(im.shape, im.dtype) - img = im[:, :, ::-1].copy() + # img = im[:, :, ::-1].copy() - if data_opt.clahe is True: - lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) - l, a, b = cv2.split(lab) - clahe = cv2.createCLAHE(clipLimit=data_opt.clip_limit, tileGridSize=(8,8)) - l = clahe.apply(l) - limg = cv2.merge((l,a,b)) - img = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR) + # if data_opt.clahe is True: + # lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) + # l, a, b = cv2.split(lab) + # clahe = cv2.createCLAHE(clipLimit=data_opt.clip_limit, tileGridSize=(8,8)) + # l = clahe.apply(l) + # limg = cv2.merge((l,a,b)) + # img = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR) - if data_opt.posterize is True: - img = cv2.pyrMeanShiftFiltering(img, data_opt.spatial_window, data_opt.color_window) - if data_opt.grayscale is True: - img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - if data_opt.blur is True: - img = cv2.GaussianBlur(img, (data_opt.blur_radius, data_opt.blur_radius), data_opt.blur_sigma) - if data_opt.canny is True: - img = cv2.Canny(img, data_opt.canny_lo, data_opt.canny_hi) + # if data_opt.posterize is True: + # img = cv2.pyrMeanShiftFiltering(img, data_opt.spatial_window, data_opt.color_window) + # if data_opt.grayscale is True: + # img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + # if data_opt.blur is True: + # img = cv2.GaussianBlur(img, (data_opt.blur_radius, data_opt.blur_radius), data_opt.blur_sigma) + # if data_opt.canny is True: + # img = cv2.Canny(img, data_opt.canny_lo, data_opt.canny_hi) - cv2.imwrite(tmp_path, img) - os.rename(tmp_path, edges_path) + # cv2.imwrite(tmp_path, img) + # os.rename(tmp_path, edges_path) - webpage.save() + # webpage.save() - os.remove(render_dir + "frame_00000.png") + # os.remove(render_dir + "frame_00000.png") video_fn = tag + "_mogrify.mp4" |
