|
|
@@ -12,6 +12,13 @@ from app.utils.scheme import CardType
|
|
|
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(
|
|
|
@@ -54,11 +61,15 @@ async def process_main_image(
|
|
|
session: aiohttp.ClientSession,
|
|
|
file_bytes: bytes,
|
|
|
filename: str,
|
|
|
- score_type: str,
|
|
|
+ image_type: str,
|
|
|
is_reflect_card: str
|
|
|
) -> Dict[str, Any]:
|
|
|
"""调用推理服务,处理主图片"""
|
|
|
- logger.info(f"处理主图: {score_type} -> {filename}")
|
|
|
+ score_type = AUTO_IMPORT_IMAGE_TYPE_TO_SCORE_TYPE.get(image_type)
|
|
|
+ if not score_type:
|
|
|
+ raise HTTPException(status_code=400, detail=f"不支持的主图类型: {image_type}")
|
|
|
+
|
|
|
+ logger.info(f"处理主图: image_type={image_type}, score_type={score_type} -> {filename}")
|
|
|
inference_base_url = settings.SCORE_UPDATE_SERVER_URL
|
|
|
|
|
|
# 1. 获取转正后的图片
|
|
|
@@ -67,7 +78,7 @@ async def process_main_image(
|
|
|
session, url=rectify_url, file_bytes=file_bytes, filename=filename
|
|
|
)
|
|
|
if rectify_status >= 300:
|
|
|
- raise HTTPException(status_code=500, detail=f"图片转正失败: {score_type}")
|
|
|
+ raise HTTPException(status_code=500, detail=f"图片转正失败: {image_type}")
|
|
|
|
|
|
# 2. 获取分数JSON
|
|
|
score_url = f"{inference_base_url}/api/card_score/score_inference"
|
|
|
@@ -77,10 +88,10 @@ async def process_main_image(
|
|
|
session, url=score_url, file_bytes=file_bytes, filename=filename, params=score_params
|
|
|
)
|
|
|
if score_status >= 300:
|
|
|
- raise HTTPException(status_code=500, detail=f"推理分数失败: {score_type}")
|
|
|
+ raise HTTPException(status_code=500, detail=f"推理分数失败: {image_type}")
|
|
|
|
|
|
return {
|
|
|
- "image_type": score_type,
|
|
|
+ "image_type": image_type,
|
|
|
"rectified_image": rectified_image_bytes,
|
|
|
"score_json": json.loads(score_json_bytes)
|
|
|
}
|