In [34]:
import os
import cv2
import numpy as np
from app.models import Label

In [35]:
outpath = 'plates'
if not os.path.exists(outpath):
    os.mkdir(outpath)

In [17]:
all_readable_plates = Label.objects.filter(brand=u'ป้ายทะเบียน').exclude(model=u'')

In [36]:
all_chars = set()
for i, plate in enumerate(all_readable_plates):
    all_chars = set(plate.model).union(all_chars)
    imgpath = "static/dataset/{}".format(plate.image.src_path)
    img = cv2.imread(imgpath)
    x, y, w, h = plate.x, plate.y, plate.width, plate.height
    img = img[y:y+h, x:x+w]
    cv2.imwrite(os.path.join(outpath, '{}.png'.format(i)), img)

In [20]:
len(all_readable_plates)


Out[20]:
531

In [24]:
len(all_chars)


Out[24]:
50

In [ ]: