-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
36 lines (30 loc) · 1.36 KB
/
main.py
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
from utils import *
import os, datetime
from multiprocessing import Pool
# This project was heavily inspired by z80z80z80 on https://github.com/z80z80z80/autocrop
# Thanks for that!
Input_Directory = "Original"
Output_Directory = "Cropped"
#TODO: include more settings (for example output filetype)
def main(input_dir, output_dir):
thread_count = get_thread_count()
params = []
create_file_structure(output_dir)
print("Setting up file parameters for threads...")
picture_counter = 0
tstart = datetime.datetime.now() # start timer
for filename in os.listdir(input_dir):
if filename.endswith(".jpg"):
picture_counter += 1
params.append({"input_path": os.path.join(input_dir, filename), # path of the image file
"output_dir": output_dir, # output directory where all data will be saved
"name": os.path.splitext(filename)[0], # get filename without extension
"border": 20}) # additional # of pixels cropped from border
print("Start cropping...")
with Pool(thread_count) as p:
p.map(crop_dias, params)
tend = datetime.datetime.now() # stop timer
tdelta = tend - tstart
print(f"Batch finished, {picture_counter} Pictures in {tdelta.seconds} Seconds")
if __name__ == "__main__":
main(Input_Directory, Output_Directory)