예제 #1
0
def start():
    pygame.init()

    ys = np.arange(8, 200)
    A = np.c_[ys, np.ones_like(ys)]

    xs = []
    models = {}  #linear model

    FS = FontState()
    #plt.figure()
    #plt.hold(True)
    for i in range(len(FS.fonts)):

        font = freetype.Font(FS.fonts[i], size=40)
        print(font.size, font.get_sized_height)
        h = []
        for y in ys:
            h.append(font.get_sized_glyph_height(float(y)))
        h = np.array(h)
        #print(h)
        m, _, _, _ = np.linalg.lstsq(A, h)
        models[font.name] = m
        xs.append(h)
        #print(font.name)

    with open('data/models/font_px2pt.cp', 'wb') as f:
        cp.dump(models, f)
def main():

    textSource = TextSource(r'data\words/')
    textRegion = TextRegions()
    FS = FontState()
    maxNumImages = 5
    for i in range(0, maxNumImages):
        ITBF = ImageTextBoxFactory()
        img = Image.new("RGB", (512, 512), "white")
        img = img.resize((600, 400), Image.ANTIALIAS)
        generateData(FS, ITBF, img, textRegion, textSource, i)

    print("total image number:%s" % (maxNumImages))
예제 #3
0
import pygame
from pygame import freetype
from text_utils import FontState
import numpy as np
import matplotlib.pyplot as plt
import cPickle as cp

pygame.init()

ys = np.arange(8, 200)
A = np.c_[ys, np.ones_like(ys)]

xs = []
models = {}  # linear model

FS = FontState()
# plt.figure()
# plt.hold(True)
for i in xrange(len(FS.fonts)):
    font = freetype.Font(FS.fonts[i], size=12)
    h = []
    for y in ys:
        h.append(font.get_sized_glyph_height(y))
    h = np.array(h)
    m, _, _, _ = np.linalg.lstsq(A, h)
    models[font.name] = m
    print("{}:\t{}".format(i, font.name))
    xs.append(h)

with open('font_px2pt.cp', 'w') as f:
    cp.dump(models, f)
예제 #4
0
from text_utils import FontState
import pygame
from pygame import freetype
import numpy as np
import pickle

pygame.init()
FS = FontState()

for i in range(len(FS.fonts)):
    print(i)
    font = freetype.Font(FS.fonts[i], size=12)
    print(font.name)
FS.sample()