【发布时间】:2015-11-05 12:44:36
【问题描述】:
我是 Python 新手,并尝试运行以下代码。我收到以下错误"IOError: cannot open resource"。这是由于某些图像特征不再存在(例如 Coval.otf),还是可能由于写入/读取限制?请让我知道 - 非常感谢,W
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from skimage import transform as tf
def create_captcha(text, shear=0, size=(100,24)):
im = Image.new("L", size, "black")
draw = ImageDraw.Draw(im)
font = ImageFont.truetype(r"Coval.otf", 22)
draw.text((2, 2), text, fill=1, font=font)
image = np.array(im)
affine_tf = tf.AffineTransform(shear=shear)
image = tf.warp(image, affine_tf)
return image / image.max()
%matplotlib inline
from matplotlib import pyplot as plt
image = create_captcha("GENE", shear=0.5)
【问题讨论】:
-
你能发送错误堆栈吗?
-
我生成了一个可能匹配的:pastebin.com/C92Re7iQ。看起来像 Coval.otf 没有被发现?还发现此资源可能会提供更多信息:tiny.cc/1voo5x。看来必须安装了。这本书显示了一个下载链接。
标签: python io python-imaging-library