|
|
@@ -54,10 +54,10 @@ def update_card_scores_and_status(db_conn: PooledMySQLConnection, card_id: int):
|
|
|
db_conn.commit()
|
|
|
|
|
|
|
|
|
-def _construct_gray_image_json(gray_type: ImageType, ring_image_data: Optional[Dict[str, Any]]) -> Dict[str, Any]:
|
|
|
+def _construct_gray_image_json(gray_type: str, ring_image_data: Optional[Dict[str, Any]]) -> Dict[str, Any]:
|
|
|
"""
|
|
|
- 内部辅助:构建灰度图的 modified_json
|
|
|
- gray_type: front_gray 或 back_gray
|
|
|
+ 内部辅助:构建辅助图(灰度图/融合图)的 modified_json
|
|
|
+ gray_type: front_gray / back_gray / front_fusion / back_fusion
|
|
|
ring_image_data: 对应的 ring 图的数据库原始字典数据 (包含 detection_json/modified_json 字段)
|
|
|
"""
|
|
|
if not ring_image_data:
|
|
|
@@ -83,13 +83,16 @@ def _construct_gray_image_json(gray_type: ImageType, ring_image_data: Optional[D
|
|
|
filtered_defects = []
|
|
|
|
|
|
for defect in defects:
|
|
|
- # 寻找存在 "gray_id" 字段的数据
|
|
|
- if "gray_id" in defect:
|
|
|
+ # 判断当前缺陷是否属于当前这张辅助图
|
|
|
+ # 如果是融合图,就找 fusion_id;如果是灰度图,就找 gray_id
|
|
|
+ is_fusion = gray_type in ("front_fusion", "back_fusion")
|
|
|
+ key_to_check = "fusion_id" if is_fusion else "gray_id"
|
|
|
+
|
|
|
+ if key_to_check in defect:
|
|
|
filtered_defects.append(defect)
|
|
|
|
|
|
- if not filtered_defects:
|
|
|
- return None # 这里暂定如果没有相关缺陷,modified_json 为 None
|
|
|
-
|
|
|
+ # 即使没有缺陷,也最好返回一个空的结构,不要返回 None
|
|
|
+ # 不然前端可能会觉得没这个字段或者解析报错
|
|
|
gray_modified_json = copy.deepcopy(EMPTY_DETECTION_JSON)
|
|
|
gray_modified_json["result"]["defect_result"]["defects"] = filtered_defects
|
|
|
|