forked from sparkfish/shabby-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_shabby.py
34 lines (29 loc) · 891 Bytes
/
generate_shabby.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
import os
import cv2
from multiprocessing import Pool
from pathlib import Path
from augraphy import *
from PIL import Image
import os
import random
import cv2
from glob import glob
import numpy as np
from daily_pipeline import get_pipeline
def run_pipeline(filename):
image = cv2.imread(filename.as_posix())
print(f"Processing {filename.stem}")
# returns the current Shabby Pages pipeline
pipeline = get_pipeline()
data = pipeline.augment(image)
shabby_image = data["output"]
output_filename = f"shabby150/{filename.stem}.png"
cv2.imwrite(output_filename, shabby_image)
if __name__ == "__main__":
input_path = Path("clean150")
filenames = [(input_path / name) for name in os.listdir(input_path)]
pool = Pool(os.cpu_count())
pool.imap_unordered(run_pipeline, filenames)
# wait for everything to finish
pool.close()
pool.join()