| 1234567891011121314151617181920212223242526272829303132 |
- import cv2
- from app.utils.arean_anylize_draw import DefectProcessor, to_json_serializable, DrawingParams
- import json
- if __name__ == '__main__':
- json_path = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\Test\output\final_face_defects.json"
- img = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg"
- with open(json_path, 'r', encoding='utf-8') as f:
- labelme_data = json.load(f)
- img_bgr = cv2.imread(img)
- processor = DefectProcessor(pixel_resolution=24.54)
- # result = processor.analyze_from_json(labelme_data)
- drawing_params_with_rect = DrawingParams(draw_min_rect=True)
- drawn_image_rect, result_rect = processor.analyze_and_draw(img_bgr, labelme_data,
- drawing_params_with_rect)
- cv2.imwrite("drawn_image_rect.jpg", drawn_image_rect)
- # print(result)
- # print(type(result))
- # with open('result.json', 'w', encoding='utf-8') as f:
- # f.write(result_json)
- # result_json = to_json_serializable(result.to_dict())
- # print(result_json)
- # print(json.loads(result_json))
- # with open('result.json', 'w', encoding='utf-8') as f:
- # json.dump(result_json, f, ensure_ascii=False, indent=2)
|