区分角和边.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import json
  2. from app.utils.defect_inference.ClassifyEdgeCorner import ClassifyEdgeCorner
  3. def load_json_data(json_file):
  4. """辅助函数,从JSON文件加载点"""
  5. with open(json_file, 'r') as f:
  6. data = json.load(f)
  7. return data
  8. # --- 全局配置 ---
  9. # 像素分辨率 (来自你的问题描述)
  10. PIXEL_RESOLUTION_UM = 24.54 # 单位: μm/pixel
  11. # 角区的定义尺寸
  12. CORNER_SIZE_MM = 3.0
  13. if __name__ == '__main__':
  14. # --- 文件路径配置 ---
  15. DEFECT_JSON_PATH = r"..\_temp_work\pokemon_front_corner_no_reflect_defect-area_result.json"
  16. OUTER_BOX_JSON_PATH = '../temp/outer/250805_pokemon_0001.json' # 包含外框坐标的文件
  17. OUTPUT_JSON_PATH = '23.json'
  18. # 加载数据
  19. defect_data = load_json_data(DEFECT_JSON_PATH)
  20. outer_box_data = load_json_data(OUTER_BOX_JSON_PATH)
  21. classifier = ClassifyEdgeCorner(PIXEL_RESOLUTION_UM, CORNER_SIZE_MM)
  22. classified_data = classifier.classify_defects_location(defect_data, outer_box_data)
  23. print(classified_data)
  24. # if classified_data:
  25. # # 保存结果到新文件
  26. # with open(OUTPUT_JSON_PATH, 'w', encoding='utf-8') as f:
  27. # json.dump(classified_data, f, indent=2, ensure_ascii=False)
  28. # print(f"\n成功!分类后的结果已保存到: {OUTPUT_JSON_PATH}")