-
Notifications
You must be signed in to change notification settings - Fork 0
/
plate_generator.py
executable file
·44 lines (33 loc) · 1.26 KB
/
plate_generator.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
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import string
import random
from random import randint
import cv2
import numpy as np
import os
from PIL import Image, ImageFont, ImageDraw
path = os.path.dirname(os.path.realpath(__file__)) + "/"
NUMBER_OF_PLATES = 1000
for i in range(0, NUMBER_OF_PLATES):
# Pick two random letters
plate_alpha = ""
for _ in range(0, 2):
plate_alpha += (random.choice(string.ascii_uppercase))
# Pick two random numbers
num = randint(0, 99)
plate_num = "{:02d}".format(num)
# Write plate to image
blank_plate = cv2.imread(path+'blank_plate.png')
# Convert into a PIL image (this is so we can use the monospaced fonts)
blank_plate_pil = Image.fromarray(blank_plate)
# Get a drawing context
draw = ImageDraw.Draw(blank_plate_pil)
monospace = ImageFont.truetype("/usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf", 200)
draw.text((48, 50),plate_alpha + " " + plate_num, (255,0,0), font=monospace)
#28 has smt to do w the LHS
# Convert back to OpenCV image and save
blank_plate = np.array(blank_plate_pil)
# Write license plate to file
cv2.imwrite(os.path.join(path + "pictures/",
"plate_{}{}.png".format(plate_alpha, plate_num)),
blank_plate)