【问题标题】:TypeError: expected a float for size, gotTypeError:预期大小为浮点数,得到
【发布时间】:2021-05-24 06:42:22
【问题描述】:

我正在尝试运行代码来生成字体模型,如下所示:

import pygame
from pygame import freetype
from text_utils import FontState
import numpy as np
import matplotlib.pyplot as plt
import _pickle 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 range(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)
# plt.plot(xs,ys[i])

当我跑的时候,我得到了错误:

enter image description here

请帮帮我!

【问题讨论】:

  • 作为第一次尝试,您可以尝试使用 float(y) 将 y 的值显式转换为浮动(如错误消息所述)。
  • 非常感谢。它有效!

标签: deep-learning ocr training-data cjk synthetic


【解决方案1】:

作为第一次尝试,您可以尝试使用 float(y)y 的值显式转换为 float(如错误消息所述)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 2016-08-29
    • 2019-10-16
    • 2018-05-18
    • 2021-04-17
    • 1970-01-01
    相关资源
    最近更新 更多