koishi70 / Style_Migration_For_Artistic_Font_With_CNN

基于卷积神经网络的风格迁移,制造出带有艺术风格的字体(艺术字),部分效果可达PS水平,可以辅助设计人员做设计;Convolutional neural network based style migration to create a font with artistic style (WordArt), some effects up to PhotoShop level, it can assist designers to do design
MIT License
229 stars 50 forks source link

OSError: cannot open resource #2

Closed jichunshen closed 6 years ago

jichunshen commented 6 years ago

When I use anaconda environment to run this command, it appears error: cannot open resource. Can you help me out?

(ml) JichunMacBook-Pro:Style_Migration_For_Artistic_Font_With_CNN SpringCurry$ python neural_style_transfer.py ./example/fire.png .             
/Users/SpringCurry/anaconda3/envs/ml/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Traceback (most recent call last):
  File "neural_style_transfer.py", line 171, in <module>
    smooth_times=smooth_times,noise=noise)
  File "neural_style_transfer.py", line 88, in char_to_picture
    font = ImageFont.truetype(font_dir, font_size)
  File "/Users/SpringCurry/anaconda3/envs/ml/lib/python3.6/site-packages/PIL/ImageFont.py", line 261, in truetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/Users/SpringCurry/anaconda3/envs/ml/lib/python3.6/site-packages/PIL/ImageFont.py", line 144, in __init__
    self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError: cannot open resource
koishi70 commented 6 years ago

you can see the code: `

由于系统内部不是使用汉字文件名,而是英文名,在此转换

if font_name == "宋体":
    font_name = "SIMSUN.ttc"
if font_name == "楷体":
    font_name = "SIMKAI.ttf"
if font_name == "黑体":
    font_name = "SIMHEI.ttf"
if font_name == "等线":
    font_name = "DENG.ttf"
if font_name == "仿宋":
    font_name = "SIMFANG.ttf"

# 取得字体文件的位置
font_dir = "C:\Windows\Fonts\\" + font_name
font_size = int(pictrue_size * 0.8 / len(text)) # 设定文字的大小
font = ImageFont.truetype(font_dir, font_size)

` may be your font file isn't in "C:\Windows\Fonts\" please correct it ; or your don't have the same font file as me, please go to your font folder and figger it out.

jichunshen commented 6 years ago

Thank you for replying me. The issue is the lack of the same font file. Thank you for your work.