summaryrefslogtreecommitdiff
path: root/crop_frames.py
diff options
context:
space:
mode:
authorjules <jules@asdf.us>2019-01-17 22:10:14 +0100
committerjules <jules@asdf.us>2019-01-17 22:10:14 +0100
commit9325a3fa43b65ed6b5c69b95128db9c0a10d17b4 (patch)
tree018122720744919aad28a76598233f4c458dfa2a /crop_frames.py
parent2085a45ca753ac5fbcec677298442eb5a789c1c1 (diff)
fixes
Diffstat (limited to 'crop_frames.py')
-rw-r--r--crop_frames.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/crop_frames.py b/crop_frames.py
index 0773e86..6ce54d8 100644
--- a/crop_frames.py
+++ b/crop_frames.py
@@ -31,8 +31,9 @@ def crop_dir():
else:
height = round(width / args.ratio)
top_offset = round((old_height - height) / 2)
+ print('top offset: {}'.format(top_offset))
- print("{}x{} {}".format(width, height, step))
+ print("{}x{}, step {}".format(width, height, step))
for x in range(0, width, step):
for y in range(0, height, step):
xx = max(0, x - overlap)
@@ -40,17 +41,18 @@ def crop_dir():
w = min(side, width - xx)
h = min(side, height - yy)
crop_dir = "{}/crop_{}_{}_{}_{}".format(args.out_dir, x, y, w, h)
+ print(crop_dir)
if os.path.exists(crop_dir):
rmtree(crop_dir)
os.makedirs(crop_dir)
dataset = []
- for raw_fn in files:
+ for i, raw_fn in enumerate(sorted(files)):
fn, ext = os.path.splitext(os.path.basename(raw_fn))
partz = fn.split('_')
try:
num = int(partz[-1].replace('.png', ''))
- if num >= opt.start and num <= opt.end:
+ if i >= args.start and i <= args.end:
dataset.append((raw_fn, width, height, step, side, overlap, top_offset,))
except:
pass
@@ -71,6 +73,7 @@ def crop_image(raw_fn, width, height, step, side, overlap, top_offset):
crop_dir = "{}/crop_{}_{}_{}_{}".format(args.out_dir, x, y, w, h)
# print("{}x{} {}x{}".format(x, y, w, h))
crop = img.crop((xx, yy + top_offset, xx + w, yy + h + top_offset))
+ print("{}/{}".format(crop_dir, fn))
crop.save("{}/{}".format(crop_dir, fn))
if __name__ == "__main__":