diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-15 19:23:30 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-15 19:23:30 +0100 |
| commit | 1e545a8a40b289123570ade0dd871c2beb1e43d2 (patch) | |
| tree | 368c6a372cb0acf54c5ae12efd6823b49d49f3fd | |
| parent | da98f77fb24c5f88df9f0af0c4237e52bd5b6f67 (diff) | |
properly merging
| -rw-r--r-- | merge_frames.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/merge_frames.py b/merge_frames.py index bae78b6..ed7b9ff 100644 --- a/merge_frames.py +++ b/merge_frames.py @@ -16,7 +16,7 @@ def split_crop_dir(fn): crop, x, y, w, h = os.path.basename(fn).split("_") return int(x), int(y), int(w), int(h) -def merge_files(file, crop_dir_list, ww, hh): +def merge_files(file, crop_dir_list, ww, hh, overlap, merge_dir): fn = os.path.basename(file) print(fn) canvas = Image.new('RGB', (ww, hh,)) @@ -24,8 +24,8 @@ def merge_files(file, crop_dir_list, ww, hh): x, y, w, h = crop_dir_tuple crop_dir = "crop_{}_{}_{}_{}".format(x, y, w, h) image = Image.open("{}/{}/{}".format(args.dir, crop_dir, fn)) - crop = image.crop((overlap, overlap, image.size[0] - overlap * 2, [1] - overlap * 2)) - canvas.paste(image, (x * args.scale, y * args.scale,), mask) + crop = image.crop((overlap, overlap, image.size[0] - overlap * 2, image.size[1] - overlap * 2)) + canvas.paste(image, (x * args.scale, y * args.scale,)) canvas.save("{}/{}".format(merge_dir, fn)) def merge_dir(): @@ -42,18 +42,21 @@ def merge_dir(): for crop_dir in crop_dirs: x, y, w, h = split_crop_dir(crop_dir) if x == 0: - hh = max(y + h, hh) + hh = max(y + h - args.overlap * 2, hh) if y == 0: - ww = max(x + w, ww) + ww = max(x + w - args.overlap * 2, ww) crop_dir_list.append((x, y, w, h,)) crop_dir_list = sorted(crop_dir_list, key=operator.itemgetter(0, 1)) print("{}x{}".format(ww, hh)) + ww *= args.scale + hh *= args.scale + files = sorted(glob.glob("{}/*.png".format(crop_dirs[0]))) dataset = [] for file in files: - dataset.append((file, crop_dir_list, ww, hh,)) + dataset.append((file, crop_dir_list, ww, hh, overlap, merge_dir,)) chunksize = 3 with Pool(processes=cpu_count()) as pool: |
