Sketchback/PencilSketch/sketch.py

22 lines
585 B
Python
Raw Permalink Normal View History

2017-04-09 02:43:24 +03:00
import cv2 as cv
import numpy as np
import os
from filters import PencilSketch
2017-06-01 18:46:09 +03:00
m = 240
n = 320
DIR_PATH = 'ZuBuD'
SKETCH_PATH = 'ZuBuD_Sketch'
2017-04-09 02:43:24 +03:00
2017-06-01 18:46:09 +03:00
for file in os.listdir(DIR_PATH):
file_path = os.path.join(DIR_PATH, file)
2017-04-09 02:43:24 +03:00
img = cv.imread(file_path)
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
height, width, channels = img.shape
2017-06-01 18:46:09 +03:00
if (height, width, channels) != (m, n, 3):
img = np.resize(img, (m, n, 3))
2017-04-09 02:43:24 +03:00
pencil = PencilSketch(width, height)
sketch = pencil.render(img)
2017-06-01 18:46:09 +03:00
write_path = os.path.join(SKETCH_PATH, file)
2017-04-09 02:43:24 +03:00
cv.imwrite(write_path, sketch)