识别结果保存到对应目录下后不显示完整路径
This commit is contained in:
@ -45,8 +45,8 @@ def create_directory_structure():
|
||||
|
||||
# 6. 为每个IP在每个模型文件夹下创建年->月的目录结构
|
||||
for ip in ip_addresses:
|
||||
# 处理IP地址中的特殊字符(如果有)
|
||||
safe_ip = ip.replace(".", "_")
|
||||
# 直接使用原始IP格式
|
||||
safe_ip = ip
|
||||
|
||||
for model in model_dirs:
|
||||
# 构建路径: resource/dect/{model}/{ip}/{year}/{month}
|
||||
@ -67,15 +67,15 @@ def create_directory_structure():
|
||||
print(f"创建目录结构时发生错误: {str(e)}")
|
||||
|
||||
|
||||
def get_image_save_path(model_type: str) -> str:
|
||||
def get_image_save_path(model_type: str) -> tuple:
|
||||
"""
|
||||
获取图片保存的完整路径(不依赖原始图片名称)
|
||||
获取图片保存的完整路径和显示用路径
|
||||
|
||||
参数:
|
||||
model_type: 模型类型,应为"ocr"、"face"或"yolo"
|
||||
|
||||
返回:
|
||||
完整的图片保存路径
|
||||
元组 (完整保存路径, 显示用路径)
|
||||
"""
|
||||
try:
|
||||
# 读取IP地址(假设只有一个IP或使用第一个IP)
|
||||
@ -86,7 +86,7 @@ def get_image_save_path(model_type: str) -> str:
|
||||
raise ValueError("ip.txt文件中未找到有效的IP地址")
|
||||
|
||||
ip = ip_addresses[0]
|
||||
safe_ip = ip.replace(".", "_")
|
||||
safe_ip = ip # 直接使用原始IP格式
|
||||
|
||||
# 获取当前日期和时间(精确到毫秒,确保文件名唯一)
|
||||
now = datetime.datetime.now()
|
||||
@ -96,16 +96,21 @@ def get_image_save_path(model_type: str) -> str:
|
||||
# 生成时间戳字符串(格式:年月日时分秒毫秒)
|
||||
timestamp = now.strftime("%Y%m%d%H%M%S%f")[:-3] # 去除最后三位,保留到毫秒
|
||||
|
||||
# 构建路径: resource/dect/{model}/{ip}/{year}/{month}/{day}
|
||||
day_dir = Path("resource") / "dect" / model_type / safe_ip / current_year / current_month / current_day
|
||||
# 构建基础目录路径
|
||||
base_dir = Path("resource") / "dect"
|
||||
# 构建完整路径: resource/dect/{model}/{ip}/{year}/{month}/{day}
|
||||
day_dir = base_dir / model_type / safe_ip / current_year / current_month / current_day
|
||||
day_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 构建图片文件名(使用时间戳确保唯一性)
|
||||
image_filename = f"resource_dect_{model_type}_{safe_ip}_{current_year}_{current_month}_{current_day}_{timestamp}.jpg"
|
||||
image_path = day_dir / image_filename
|
||||
# 构建图片文件名(简化名称,去掉resource_dect_前缀)
|
||||
image_filename = f"{model_type}_{safe_ip}_{current_year}_{current_month}_{current_day}_{timestamp}.jpg"
|
||||
full_path = day_dir / image_filename
|
||||
|
||||
return str(image_path)
|
||||
# 计算显示用路径(相对于resource/dect的路径)
|
||||
display_path = full_path.relative_to(base_dir)
|
||||
|
||||
return str(full_path), str(display_path)
|
||||
|
||||
except Exception as e:
|
||||
print(f"获取图片保存路径时发生错误: {str(e)}")
|
||||
return ""
|
||||
return "", ""
|
||||
|
Reference in New Issue
Block a user