Ver código fonte

增加图片宽高标签

AnlaAnla 1 semana atrás
pai
commit
7592d1b732

+ 9 - 2
app/services/score_service.py

@@ -24,6 +24,7 @@ class ScoreService:
 
         logger.info("开始进行卡片居中和转正")
         img_bgr = self.rectify_center_service.rectify_and_center(img_bgr)
+        imageHeight, imageWidth = img_bgr.shape[:2]
 
         logger.info("开始进行卡片分数推理")
         if score_type == 'front_corner_edge' or score_type == 'front_face':
@@ -81,7 +82,9 @@ class ScoreService:
 
         result_json = self.card_scorer.formate_one_card_result(center_score_data, defect_score_data,
                                                                card_defect_type=card_defect_type,
-                                                               card_aspect=card_aspect)
+                                                               card_aspect=card_aspect,
+                                                               imageHeight=imageHeight,
+                                                               imageWidth=imageWidth)
 
         temp_score_json_path = settings.TEMP_WORK_DIR / f'{score_type}_score.json'
         with open(temp_score_json_path, 'w', encoding='utf-8') as f:
@@ -93,6 +96,8 @@ class ScoreService:
 
         center_json_data = json_data["result"]['center_result']
         defect_json_data = json_data["result"]['defect_result']
+        imageHeight = json_data["result"].get('imageHeight', 0)
+        imageWidth = json_data["result"].get('imageWidth', 0)
 
         # 边角和面 类型分类
         if score_type == 'front_corner_edge' or score_type == 'back_corner_edge':
@@ -132,7 +137,9 @@ class ScoreService:
 
         result_json = self.card_scorer.formate_one_card_result(center_score_data, defect_score_data,
                                                                card_defect_type=inference_type,
-                                                               card_aspect=card_aspect)
+                                                               card_aspect=card_aspect,
+                                                               imageHeight=imageHeight,
+                                                               imageWidth=imageWidth)
 
         temp_score_json_path = settings.TEMP_WORK_DIR / f're_{score_type}_score.json'
         with open(temp_score_json_path, 'w', encoding='utf-8') as f:

+ 5 - 1
app/utils/score_inference/CardScorer.py

@@ -202,7 +202,9 @@ class CardScorer:
     def formate_one_card_result(self, center_result: dict,
                                 defect_result: dict,
                                 card_defect_type: str,
-                                card_aspect: str):
+                                card_aspect: str,
+                                imageHeight: int,
+                                imageWidth: int):
         try:
             # 获取计算总分的权重
             card_config = self.config['card']['PSA']
@@ -242,6 +244,8 @@ class CardScorer:
             "result": {
                 "center_result": center_result,
                 "defect_result": defect_result,
+                "imageHeight": imageHeight,
+                "imageWidth": imageWidth,
                 "card_center_deduct_score": final_center_score,
                 "card_defect_deduct_score": final_defect_score,
                 "_used_compute_deduct_score": _used_compute_deduct_score,

+ 11 - 0
requirements.txt

@@ -0,0 +1,11 @@
+fastapi
+opencv-python
+numpy
+torch
+torchvision
+matplotlib
+shapely
+scikit-learn
+requests
+mysql-connector-python
+uvicorn