Created
August 3, 2016 11:39
-
-
Save twmht/f25b4b7146cc90ad1f0af28e0371874b to your computer and use it in GitHub Desktop.
font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import PIL | |
| import cv2 | |
| from PIL import ImageFont | |
| from PIL import Image | |
| from PIL import ImageDraw | |
| import string | |
| import os | |
| import shutil | |
| import random | |
| from collections import defaultdict | |
| import numpy as np | |
| symbol_dir = 'symbol' | |
| UPPERCASE = string.uppercase | |
| DIGIT = ''.join(map(str,range(0, 10))) | |
| if os.path.exists(symbol_dir): | |
| shutil.rmtree(symbol_dir) | |
| os.makedirs(symbol_dir) | |
| symbols = UPPERCASE + DIGIT | |
| counter = defaultdict(int) | |
| for symbol in symbols: | |
| print symbol | |
| img = Image.new("RGBA", (256,256), (0,0,0,0)) | |
| font = ImageFont.truetype("BEBAS___.TTF",50) | |
| draw = ImageDraw.Draw(img) | |
| intensity = random.randint(150, 255) | |
| draw.text((80, 80), symbol, (intensity, intensity, intensity), font=font) | |
| draw = ImageDraw.Draw(img) | |
| symbol_loc = os.path.join(symbol_dir, symbol) | |
| os.makedirs(symbol_loc) | |
| img = np.asarray(img) | |
| img_loc = os.path.join(symbol_loc, str(counter[symbol]) + '.png') | |
| print img_loc | |
| cv2.imwrite(img_loc, img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment