可以成功动态更换yolo模型并重启服务生效
This commit is contained in:
		| @ -12,7 +12,7 @@ def save_face_to_up_images( | ||||
| ) -> Dict[str, str]: | ||||
|     """ | ||||
|     保存人脸图片到 `/up_images/用户IP/人脸名字/` 路径 | ||||
|     修复路径计算错误,确保所有路径在up_images根目录下,且统一使用正斜杠 | ||||
|     确保db_path以up_images开头,且统一使用正斜杠 | ||||
|  | ||||
|     参数: | ||||
|         client_ip: 客户端IP(原始格式,如192.168.1.101) | ||||
| @ -38,7 +38,7 @@ def save_face_to_up_images( | ||||
|         safe_face_name = "".join([c for c in safe_face_name if c not in r'\/:*?"<>|'])  # 过滤非法字符 | ||||
|  | ||||
|         # 3. 构建根目录(强制转为绝对路径,避免相对路径混淆) | ||||
|         root_dir = Path("up_images").resolve()  # 转为绝对路径 | ||||
|         root_dir = Path("up_images").resolve()  # 转为绝对路径(如D:/Git/bin/video/up_images) | ||||
|         if not root_dir.exists(): | ||||
|             root_dir.mkdir(parents=True, exist_ok=True) | ||||
|             print(f"[FileUtil] 已创建up_images根目录:{root_dir}") | ||||
| @ -60,9 +60,9 @@ def save_face_to_up_images( | ||||
|         if not local_abs_path.resolve().is_relative_to(root_dir.resolve()): | ||||
|             raise Exception(f"图片路径不在up_images根目录下(安全校验失败):{local_abs_path}") | ||||
|  | ||||
|         # 数据库存储路径:从root_dir开始的相对路径,强制替换为正斜杠 | ||||
|         relative_path = local_abs_path.relative_to(root_dir) | ||||
|         db_path = str(relative_path).replace("\\", "/")  # 关键修复:统一使用正斜杠 | ||||
|         # 数据库存储路径:强制包含up_images前缀,统一使用正斜杠 | ||||
|         relative_path = local_abs_path.relative_to(root_dir.parent)  # 相对于root_dir的父目录 | ||||
|         db_path = str(relative_path).replace("\\", "/")  # 此时会包含up_images部分 | ||||
|  | ||||
|         # 7. 写入图片文件 | ||||
|         with open(local_abs_path, "wb") as f: | ||||
| @ -73,8 +73,8 @@ def save_face_to_up_images( | ||||
|  | ||||
|         return { | ||||
|             "success": True, | ||||
|             "db_path": db_path,  # 存数据库的相对路径(使用正斜杠) | ||||
|             "local_abs_path": str(local_abs_path),  # 本地绝对路径 | ||||
|             "db_path": db_path,  # 格式为 up_images/192_168_110_31/小龙/xxx.jpg | ||||
|             "local_abs_path": str(local_abs_path),  # 本地绝对路径(完整路径) | ||||
|             "msg": "图片保存成功" | ||||
|         } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user