소스 검색

增加labelme格式的导入与导出

AnlaAnla 6 일 전
부모
커밋
8bd4990f23
3개의 변경된 파일37개의 추가작업 그리고 35개의 파일을 삭제
  1. 2 0
      .idea/encodings.xml
  2. 5 5
      Test/img_score_and_insert2.py
  3. 30 30
      app/utils/labelme_process.py

+ 2 - 0
.idea/encodings.xml

@@ -9,8 +9,10 @@
     <file url="file://$PROJECT_DIR$/Test/test01.py" charset="GBK" />
     <file url="file://$PROJECT_DIR$/app/api/cards.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/app/api/images.py" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/app/api/labelme.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/app/crud/crud_card.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/app/utils/card_score_calculate.py" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/app/utils/labelme_process.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/app/utils/scheme.py" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/run_card_score_server.py" charset="UTF-8" />
     <file url="PROJECT" charset="GBK" />

+ 5 - 5
Test/img_score_and_insert2.py

@@ -7,10 +7,10 @@ from typing import Dict, Any, Tuple, List
 from datetime import datetime
 
 # --- 配置区域 (可根据需要修改) ---
-INFERENCE_SERVICE_URL = "http://127.0.0.1:7744"
-STORAGE_SERVICE_URL = "http://127.0.0.1:7745"
-# INFERENCE_SERVICE_URL = "http://192.168.77.249:7744"
-# STORAGE_SERVICE_URL = "http://192.168.77.249:7745"
+# INFERENCE_SERVICE_URL = "http://127.0.0.1:7744"
+# STORAGE_SERVICE_URL = "http://127.0.0.1:7745"
+INFERENCE_SERVICE_URL = "http://192.168.77.249:7744"
+STORAGE_SERVICE_URL = "http://192.168.77.249:7745"
 
 # 固定的处理类型映射
 SCORE_TYPES = [
@@ -256,7 +256,7 @@ if __name__ == "__main__":
     # !!!!!🪸是否反光
     my_is_reflect = False
 
-    for img_num in range(1, 2):
+    for img_num in range(1, 47):
         base_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250919_1500_no_reflect_nature_defect"
         p1 = os.path.join(base_path, f"{img_num}_front_coaxial_1_0.jpg")
         p2 = os.path.join(base_path, f"{img_num}_front_ring_0_1.jpg")

+ 30 - 30
app/utils/labelme_process.py

@@ -7,7 +7,7 @@ def convert_internal_to_labelme(image_path: str, internal_json: dict) -> dict:
     img_w = result.get("imageWidth", 0)
 
     labelme_data = {
-        "version": "5.0.1",
+        "version": "5.5.0",
         "flags": {},
         "shapes": [],
         "imagePath": image_path.lstrip("/\\"),  # 去除开头的斜杠
@@ -16,32 +16,8 @@ def convert_internal_to_labelme(image_path: str, internal_json: dict) -> dict:
         "imageWidth": img_w
     }
 
-    # 1. 处理缺陷 (Defects)
-    defect_result = result.get("defect_result", {})
-    defects = defect_result.get("defects", [])
-
-    for defect in defects:
-        shape = {
-            "label": defect.get("label", "unknown"),
-            "points": defect.get("points", []),
-            "group_id": None,
-            "description": "",
-            "shape_type": "polygon",
-            "flags": {},
-            # 我们将系统特有的字段暂存到 extra_info 中,或者直接放在 shape 根目录下
-            # LabelMe 打开时会忽略这些额外字段,但保存时通常会保留它们 (取决于版本)
-            # 为了安全,关键信息最好也保留
-            "system_data": {
-                "confidence": defect.get("confidence"),
-                "defect_type": defect.get("defect_type"),
-                "score": defect.get("score"),
-                "edit_type": defect.get("edit_type", "edit")
-            }
-        }
-        labelme_data["shapes"].append(shape)
-
-    # 2. 处理框 (Center Result -> Inner/Outer Box)
-    # 按照需求:inner_box 放在倒数第二个,outer_box 放在最下面 (列表最后)
+    # 1. 处理框 (Center Result -> Inner/Outer Box)
+    # inner_box 放在第二个,outer_box 放在最上面
     center_result = result.get("center_result", {})
     box_result = center_result.get("box_result", {})
 
@@ -76,12 +52,36 @@ def convert_internal_to_labelme(image_path: str, internal_json: dict) -> dict:
                     "flags": {}
                 }
 
-    # 添加到列表尾部
+    # 添加到列表头部
+    if outer_shape:
+        labelme_data["shapes"].append(outer_shape)
+
     if inner_shape:
         labelme_data["shapes"].append(inner_shape)
 
-    if outer_shape:
-        labelme_data["shapes"].append(outer_shape)
+    # 2. 处理缺陷 (Defects)
+    defect_result = result.get("defect_result", {})
+    defects = defect_result.get("defects", [])
+
+    for defect in defects:
+        shape = {
+            "label": defect.get("label", "unknown"),
+            "points": defect.get("points", []),
+            "group_id": None,
+            "description": "",
+            "shape_type": "polygon",
+            "flags": {},
+            # 我们将系统特有的字段暂存到 extra_info 中,或者直接放在 shape 根目录下
+            # LabelMe 打开时会忽略这些额外字段,但保存时通常会保留它们 (取决于版本)
+            # 为了安全,关键信息最好也保留
+            "system_data": {
+                "confidence": defect.get("confidence"),
+                "defect_type": defect.get("defect_type"),
+                "score": defect.get("score"),
+                "edit_type": defect.get("edit_type", "edit")
+            }
+        }
+        labelme_data["shapes"].append(shape)
 
     return labelme_data