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