AnlaAnla před 3 měsíci
rodič
revize
41ba573c51

+ 0 - 0
Model/pokemon_outer_box.pth → Model/outer_box.pth


binární
Model/pokemon_back_face_defect.pth


binární
Model/pokemon_back_inner_box.pth


binární
Model/pokemon_front_corner_no_reflect_defect.pth


binární
Model/pokemon_front_corner_reflect_defect.pth


binární
Model/pokemon_front_face_no_reflect_defect.pth


binární
Model/pokemon_front_face_reflect_defect.pth


+ 0 - 0
Model/pokemon_inner_box.pth → Model/pokemon_front_inner_box.pth


+ 10 - 55
Test/model_test01.py

@@ -1,5 +1,6 @@
 import os
 from pathlib import Path
+from app.core.config import settings
 import json
 import cv2
 
@@ -54,68 +55,22 @@ def predict_single_image(config_params: dict,
 
 
 if __name__ == '__main__':
-    config = {
-        "pokemon_outer_box": {
-            "pth_path": "Model/pokemon_outer_box.pth",
-            "class_dict": {1: 'outer_box'},
-            "img_size": {'width': 1280, 'height': 1280},
-            "confidence": 0.5,
-            "input_channels": 3,
-        },
-        "pokemon_inner_box": {
-            "pth_path": "Model/pokemon_inner_box.pth",
-            "class_dict": {1: 'inner_box'},
-            "img_size": {'width': 1280, 'height': 1280},
-            "confidence": 0.5,
-            "input_channels": 3,
-        },
-        "pokemon_back_corner_defect": {
-            "pth_path": "Model/pokemon_back_corner_defect.pth",
-            "class_dict": {
-                1: 'wear', 2: 'wear_and_impact', 3: 'impact',
-                4: 'damaged', 5: 'wear_and_stain',
-            },
-            "img_size": {'width': 512, 'height': 512},
-            "confidence": 0.5,
-            "input_channels": 3,
-        },
-        "pokemon_front_corner_reflect_defect": {
-            "pth_path": "Model/pokemon_front_corner_reflect_defect.pth",
-            "class_dict": {"1": "impact", "2": "wear_and_impact", "3": "wear"},
-            "img_size": {'width': 512, 'height': 512},
-            "confidence": 0.5,
-            "input_channels": 3,
-        },
-        "pokemon_front_corner_no_reflect_defect": {
-            "pth_path": "Model/pokemon_front_corner_no_reflect_defect.pth",
-            "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact", "4": "damaged"},
-            "img_size": {'width': 512, 'height': 512},
-            "confidence": 0.5,
-            "input_channels": 3,
-        },
-        "pokemon_front_face_no_reflect_defect": {
-            "pth_path": "Model/pokemon_front_face_no_reflect_defect.pth",
-            "class_dict": {"1": "scratch", "2": "pit", "3": "stain"},
-            "img_size": {'width': 512, 'height': 512},
-            "confidence": 0.5,
-            "input_channels": 3,
-        },
-    }
-    predict_single_image(config['pokemon_inner_box'],
-                         img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg",
+    config = settings.CARD_MODELS_CONFIG
+    predict_single_image(config['pokemon_front_inner_box'],
+                         img_path=r"C:\Users\wow38\Downloads\_250829_1656_最新模型汇总\_250829_1814_宝可梦背面内框模型\pth_and_images\images\Pokémon_back_0805_0001.jpg",
                          output_dir=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\inner")
 
-    predict_single_image(config['pokemon_outer_box'],
-                         img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg",
-                         output_dir=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\outer")
+    # predict_single_image(config['outer_box'],
+    #                      img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg",
+    #                      output_dir=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\outer")
 
     # predict_single_image(config['pokemon_back_corner_defect'],
     #                      img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\img_2.png",
     #                      output_dir=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\back_corner")
 
-    predict_single_image(config['pokemon_front_face_no_reflect_defect'],
-                         img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg",
-                         output_dir=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\face_no_reflect")
+    # predict_single_image(config['pokemon_front_face_no_reflect_defect'],
+    #                      img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg",
+    #                      output_dir=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\face_no_reflect")
 
     # result = predict_single_image(config['pokemon_front_corner_no_reflect_defect'],
     #                               img_path=r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\00006_250805_pokemon_0001_bottom_grid_r0_c5.jpg",

+ 4 - 26
Test/test01.py

@@ -1,28 +1,6 @@
-import cv2
-import matplotlib.pyplot as plt
+import json
 
-img = cv2.imread(r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\_temp_work\temp_area_result.jpg")
+text = '''{"asda": 666, "abb": 656, "gsd": 123}'''
+data = json.loads(text)
 
-x1_min = 251
-y1_min = 273
-x1_max = 2636
-y1_max = 3662
-
-x2_min = 146
-y2_min = 177
-x2_max = 2735
-y2_max = 3767
-
-img = cv2.line(img, pt1=(x1_min, y1_min), pt2=(x1_min, y1_max), color=(0, 0, 255), thickness=4)
-img = cv2.line(img, pt1=(x1_min, y1_min), pt2=(x1_max, y1_min), color=(0, 0, 255), thickness=4)
-img = cv2.line(img, pt1=(x1_max, y1_max), pt2=(x1_min, y1_max), color=(0, 0, 255), thickness=4)
-img = cv2.line(img, pt1=(x1_max, y1_max), pt2=(x1_max, y1_min), color=(0, 0, 255), thickness=4)
-
-img = cv2.line(img, pt1=(x2_min, y2_min), pt2=(x2_min, y2_max), color=(0, 200, 255), thickness=4)
-img = cv2.line(img, pt1=(x2_min, y2_min), pt2=(x2_max, y2_min), color=(0, 200, 255), thickness=4)
-img = cv2.line(img, pt1=(x2_max, y2_max), pt2=(x2_min, y2_max), color=(0, 200, 255), thickness=4)
-img = cv2.line(img, pt1=(x2_max, y2_max), pt2=(x2_max, y2_min), color=(0, 200, 255), thickness=4)
-
-
-plt.imshow(img)
-plt.show()
+print(data)

+ 42 - 9
app/core/config.py

@@ -28,15 +28,22 @@ class Settings:
     # 使用一个字典来管理所有卡片检测模型
     # key (如 'outer_box') 将成为 API 路径中的 {inference_type}
     CARD_MODELS_CONFIG: Dict[str, CardModelConfig] = {
-        "pokemon_outer_box": {
-            "pth_path": "Model/pokemon_outer_box.pth",
+        "outer_box": {
+            "pth_path": "Model/outer_box.pth",
             "class_dict": {1: 'outer_box'},
             "img_size": {'width': 1280, 'height': 1280},
             "confidence": 0.5,
             "input_channels": 3,
         },
-        "pokemon_inner_box": {
-            "pth_path": "Model/pokemon_inner_box.pth",
+        "pokemon_front_inner_box": {
+            "pth_path": "Model/pokemon_front_inner_box.pth",
+            "class_dict": {1: 'inner_box'},
+            "img_size": {'width': 1280, 'height': 1280},
+            "confidence": 0.5,
+            "input_channels": 3,
+        },
+        "pokemon_back_inner_box": {
+            "pth_path": "Model/pokemon_back_inner_box.pth",
             "class_dict": {1: 'inner_box'},
             "img_size": {'width': 1280, 'height': 1280},
             "confidence": 0.5,
@@ -52,6 +59,23 @@ class Settings:
             "confidence": 0.5,
             "input_channels": 3,
         },
+        "pokemon_back_face_defect": {
+            "pth_path": "Model/pokemon_back_face_defect.pth",
+            "class_dict": {"1": "wear", "2": "scratch", "3": "stain",
+                           "4": "scuff", "5": "impact", "6": "damaged",
+                           "7": "wear_and_impact"},
+            "img_size": {'width': 512, 'height': 512},
+            "confidence": 0.5,
+            "input_channels": 3,
+        },
+        "pokemon_front_face_reflect_defect": {
+            "pth_path": "Model/pokemon_front_face_reflect_defect.pth",
+            "class_dict": {"1": "scratch", "2": "stain", "3": "wear",
+                           "4": "impact", "5": "stain_and_scratch"},
+            "img_size": {'width': 512, 'height': 512},
+            "confidence": 0.5,
+            "input_channels": 3,
+        },
         "pokemon_front_corner_reflect_defect": {
             "pth_path": "Model/pokemon_front_corner_reflect_defect.pth",
             "class_dict": {"1": "impact", "2": "wear_and_impact", "3": "wear"},
@@ -61,14 +85,16 @@ class Settings:
         },
         "pokemon_front_corner_no_reflect_defect": {
             "pth_path": "Model/pokemon_front_corner_no_reflect_defect.pth",
-            "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact", "4": "damaged"},
+            "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact",
+                           "4": "damaged", "5": "stain"},
             "img_size": {'width': 512, 'height': 512},
             "confidence": 0.5,
             "input_channels": 3,
         },
         "pokemon_front_face_no_reflect_defect": {
             "pth_path": "Model/pokemon_front_face_no_reflect_defect.pth",
-            "class_dict": {"1": "scratch", "2": "pit", "3": "stain"},
+            "class_dict": {"1": "wear", "2": "scratch", "3": "damaged",
+                           "4": "stain", "5": "impact", "6": "pit"},
             "img_size": {'width': 512, 'height': 512},
             "confidence": 0.5,
             "input_channels": 3,
@@ -78,9 +104,16 @@ class Settings:
     # 包含, 环形光居中计算, 环形光正反边角缺陷, 同轴光正反表面缺陷
     # 里面存储需要用到的模型类型
     DEFECT_TYPE: Dict[str, dict] = {
-        "pokemon_card_center": {
-            "inner_box": "pokemon_inner_box",
-            "outer_box": "pokemon_outer_box",
+        "pokemon_front_card_center": {
+            "inner_box": "pokemon_front_inner_box",
+            "outer_box": "outer_box",
+        },
+        "pokemon_back_card_center": {
+            "inner_box": "pokemon_back_inner_box",
+            "outer_box": "outer_box",
+        },
+        "pokemon_back_face_defect": {
+            'model_type': "pokemon_back_face_defect"
         },
         "pokemon_back_corner_defect": {
             'model_type': "pokemon_back_corner_defect"

+ 4 - 2
app/services/defect_service.py

@@ -113,7 +113,7 @@ class DefectInferenceService:
                 area_json = processor.analyze_from_json(json_data)
 
             # 推理外框
-            predictor_outer = get_predictor("pokemon_outer_box")
+            predictor_outer = get_predictor("outer_box")
             outer_result = predictor_outer.predict_from_image(img_bgr)
 
             classifier = ClassifyEdgeCorner(settings.PIXEL_RESOLUTION, settings.CORNER_SIZE_MM)
@@ -125,7 +125,9 @@ class DefectInferenceService:
 
             return edge_corner_data
 
-        elif inference_type == "pokemon_card_center":
+        elif inference_type == "pokemon_front_card_center" \
+                or inference_type == "pokemon_back_card_center":
+
             predictor_inner = get_predictor(settings.DEFECT_TYPE[inference_type]['inner_box'])
             predictor_outer = get_predictor(settings.DEFECT_TYPE[inference_type]['outer_box'])
 

+ 6 - 1
app/services/score_service.py

@@ -16,7 +16,10 @@ class ScoreService:
         card_scorer = CardScorer(config_path=self.scoring_config_path)
 
         logger.info("开始进行卡片分数推理")
-        center_data = defect_service.defect_inference("pokemon_card_center", image_bytes)
+        if score_type == 'front_corner_edge' or score_type == 'front_face':
+            center_data = defect_service.defect_inference("pokemon_front_card_center", image_bytes)
+        else:
+            center_data = defect_service.defect_inference("pokemon_back_card_center", image_bytes)
 
         if is_reflect_card:
             if score_type == 'front_corner_edge':
@@ -59,6 +62,8 @@ class ScoreService:
             defect_score_data = card_scorer.calculate_defect_score('edge', 'back', corner_score_data, True)
         elif score_type == 'back_face':
             defect_score_data = card_scorer.calculate_defect_score('face', 'back', defect_data, True)
+        else:
+            return {}
 
         result_json = formate_one_card_result(center_score_data, defect_score_data)