opencv_webcam/utils/plot.py

45 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 作图
# 创建人:曾逸夫
# 创建时间2022-01-27
import os
import sys
fonts_list = ['SimSun.ttc', 'TimesNewRoman.ttf'] # 字体列表
fonts_suffix = ['ttc', 'ttf', 'otf'] # 字体后缀
# 创建字体库
def add_fronts(fonts_file="./fonts.sh"):
os.system(f'bash {fonts_file}')
print(f'字体文件加载完成!')
# 判断字体文件
def is_fonts(fonts_dir):
if (os.path.isdir(fonts_dir)):
# 如果字体库存在
fonts_flag = 0 # 判别标志
f_list = os.listdir(fonts_dir) # 本地字体库
for i in fonts_list:
if (i not in f_list):
# 字体不存在
fonts_flag = 1
if (fonts_flag == 1):
# 字体不存在
print(f'字体不存在,正在加载。。。')
add_fronts() # 创建字体库
else:
print(f'{fonts_list}字体已存在!')
else:
# 字体库不存在,创建字体库
print(f'字体库不存在,正在创建。。。')
add_fronts() # 创建字体库
if __name__ == "__main__":
# add_fronts("./fonts.sh")
is_fonts("./fonts")