|
|
@@ -6,14 +6,15 @@ import os
|
|
|
from typing import Dict, Any, Tuple, Optional, List
|
|
|
from datetime import datetime
|
|
|
|
|
|
+from app.utils.scheme import IMAGE_TYPE_TO_SCORE_TYPE
|
|
|
+
|
|
|
# --- 配置区域 ---
|
|
|
# INFERENCE_SERVICE_URL = "http://127.0.0.1:7754"
|
|
|
# STORAGE_SERVICE_URL = "http://127.0.0.1:7755"
|
|
|
INFERENCE_SERVICE_URL = "http://192.168.77.249:7754"
|
|
|
STORAGE_SERVICE_URL = "http://192.168.77.249:7755"
|
|
|
|
|
|
-# 映射关系:后端 score_type 和 image_type 现在是一致的
|
|
|
-# 灰度图不需要映射,直接透传
|
|
|
+# 灰度图不需要推理 score_type,主图需要映射成推理服务允许的枚举值。
|
|
|
MAIN_IMAGE_TYPES = [
|
|
|
"front_ring",
|
|
|
"front_coaxial",
|
|
|
@@ -74,7 +75,7 @@ async def call_api_with_file(
|
|
|
async def process_main_image(
|
|
|
session: aiohttp.ClientSession,
|
|
|
image_path: str,
|
|
|
- score_type: str,
|
|
|
+ image_type: str,
|
|
|
is_reflect_card: str
|
|
|
) -> Dict[str, Any]:
|
|
|
"""
|
|
|
@@ -82,7 +83,11 @@ async def process_main_image(
|
|
|
1. 调用转正接口
|
|
|
2. 调用分数推理接口
|
|
|
"""
|
|
|
- print(f" [处理中] 主图: {score_type} -> {os.path.basename(image_path)}")
|
|
|
+ score_type = IMAGE_TYPE_TO_SCORE_TYPE.get(image_type)
|
|
|
+ if not score_type:
|
|
|
+ raise Exception(f"不支持的主图类型: {image_type}")
|
|
|
+
|
|
|
+ print(f" [处理中] 主图: image_type={image_type}, score_type={score_type} -> {os.path.basename(image_path)}")
|
|
|
|
|
|
# 1. 获取转正后的图片
|
|
|
rectify_url = f"{INFERENCE_SERVICE_URL}/api/card_inference/card_rectify_and_center"
|
|
|
@@ -90,7 +95,7 @@ async def process_main_image(
|
|
|
session, url=rectify_url, file_path=image_path
|
|
|
)
|
|
|
if rectify_status >= 300:
|
|
|
- raise Exception(f"转正失败: {score_type}")
|
|
|
+ raise Exception(f"转正失败: {image_type}")
|
|
|
|
|
|
# 2. 获取分数JSON
|
|
|
score_url = f"{INFERENCE_SERVICE_URL}/api/card_score/score_inference"
|
|
|
@@ -105,12 +110,12 @@ async def process_main_image(
|
|
|
params=score_params
|
|
|
)
|
|
|
if score_status >= 300:
|
|
|
- raise Exception(f"推理分数失败: {score_type}")
|
|
|
+ raise Exception(f"推理分数失败: {image_type}")
|
|
|
|
|
|
score_json = json.loads(score_json_bytes)
|
|
|
return {
|
|
|
"type": "main",
|
|
|
- "image_type": score_type, # 现在 score_type 等于 image_type
|
|
|
+ "image_type": image_type,
|
|
|
"rectified_image": rectified_image_bytes,
|
|
|
"score_json": score_json
|
|
|
}
|