Forráskód Böngészése

修改调用推荐分数接口映射关系

袁威 2 hete
szülő
commit
c5346aded9
3 módosított fájl, 27 hozzáadás és 21 törlés
  1. 12 7
      Test/img_score_and_insert2.py
  2. 2 10
      app/api/auto_import.py
  3. 13 4
      app/utils/scheme.py

+ 12 - 7
Test/img_score_and_insert2.py

@@ -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
     }

+ 2 - 10
app/api/auto_import.py

@@ -7,19 +7,11 @@ from fastapi import APIRouter, HTTPException, Request, UploadFile, File, Form
 
 from app.core.config import settings
 from app.core.logger import get_logger
-from app.utils.scheme import CardType
+from app.utils.scheme import CardType, IMAGE_TYPE_TO_SCORE_TYPE
 
 logger = get_logger(__name__)
 router = APIRouter()
 
-AUTO_IMPORT_IMAGE_TYPE_TO_SCORE_TYPE = {
-    "front_ring": "front_corner_edge",
-    "back_ring": "back_corner_edge",
-    "front_coaxial": "front_face",
-    "back_coaxial": "back_face",
-}
-
-
 # --- 内部辅助函数 ---
 async def call_api_with_bytes(
         session: aiohttp.ClientSession,
@@ -65,7 +57,7 @@ async def process_main_image(
         is_reflect_card: str
 ) -> Dict[str, Any]:
     """调用推理服务,处理主图片"""
-    score_type = AUTO_IMPORT_IMAGE_TYPE_TO_SCORE_TYPE.get(image_type)
+    score_type = IMAGE_TYPE_TO_SCORE_TYPE.get(image_type)
     if not score_type:
         raise HTTPException(status_code=400, detail=f"不支持的主图类型: {image_type}")
 

+ 13 - 4
app/utils/scheme.py

@@ -21,6 +21,15 @@ class ImageType(str, Enum):
     back_fusion = "back_fusion"
 
 
+class ScoreType(str, Enum):
+    front_corner_edge = "front_corner_edge"
+    front_face = "front_face"
+    front_face_ring_light = "front_face_ring_light"
+    back_corner_edge = "back_corner_edge"
+    back_face = "back_face"
+    back_face_ring_light = "back_face_ring_light"
+
+
 class CardType(str, Enum):
     pokemon = "pokemon"
     basketball = "basketball"
@@ -51,10 +60,10 @@ class CardNoList(BaseModel):
 
 # 图片类型和推理服务 score_type 映射表
 IMAGE_TYPE_TO_SCORE_TYPE = {
-    "front_coaxial": "front_face",
-    "back_coaxial": "back_face",
-    "front_ring": "front_corner_edge",
-    "back_ring": "back_corner_edge",
+    ImageType.front_coaxial.value: ScoreType.front_face.value,
+    ImageType.back_coaxial.value: ScoreType.back_face.value,
+    ImageType.front_ring.value: ScoreType.front_corner_edge.value,
+    ImageType.back_ring.value: ScoreType.back_corner_edge.value,
     "front_gray": None,
     "back_gray": None,
     "front_fusion": None,