45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import os
|
|
|
|
class Config:
|
|
# 获取当前文件所在目录的绝对路径
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
# 配置文件路径
|
|
CONFIG_DIR = os.path.join(BASE_DIR, "configs")
|
|
|
|
# 模型相关路径
|
|
MODEL_DIR = os.path.join(CONFIG_DIR, "pt")
|
|
LEG_MODEL_PATH = os.path.join(MODEL_DIR, "leg_16points.pt")
|
|
|
|
# 字体文件路径
|
|
FONT_DIR = os.path.join(CONFIG_DIR, "font")
|
|
FONT_PATHS = os.path.join(FONT_DIR, "heiti-Bold.ttc")
|
|
|
|
# 图片相关路径
|
|
IMAGE_DIR = os.path.join(CONFIG_DIR, "using_img")
|
|
LEG_IMAGE_DIR = os.path.join(IMAGE_DIR, "leg_img")
|
|
|
|
@classmethod
|
|
def get_font_path(cls):
|
|
"""获取可用的字体路径"""
|
|
if os.path.exists(cls.FONT_PATHS):
|
|
return cls.FONT_PATHS
|
|
return None
|
|
|
|
@classmethod
|
|
def ensure_dir(cls, dir_path):
|
|
"""确保目录存在,如果不存在则创建"""
|
|
if not os.path.exists(dir_path):
|
|
os.makedirs(dir_path)
|
|
return dir_path
|
|
|
|
@classmethod
|
|
def get_image_path(cls, image_name):
|
|
"""获取图片完整路径"""
|
|
return os.path.join(cls.IMAGE_DIR, image_name)
|
|
|
|
@classmethod
|
|
def get_output_path(cls, output_name):
|
|
"""获取输出图片完整路径"""
|
|
cls.ensure_dir(cls.LEG_IMAGE_DIR)
|
|
return os.path.join(cls.LEG_IMAGE_DIR, output_name) |