面积计算.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import cv2
  2. from app.utils.arean_anylize_draw import DefectProcessor, to_json_serializable, DrawingParams
  3. import json
  4. if __name__ == '__main__':
  5. json_path = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\Test\output\final_face_defects.json"
  6. img = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg"
  7. with open(json_path, 'r', encoding='utf-8') as f:
  8. labelme_data = json.load(f)
  9. img_bgr = cv2.imread(img)
  10. processor = DefectProcessor(pixel_resolution=24.54)
  11. # result = processor.analyze_from_json(labelme_data)
  12. drawing_params_with_rect = DrawingParams(draw_min_rect=True)
  13. drawn_image_rect, result_rect = processor.analyze_and_draw(img_bgr, labelme_data,
  14. drawing_params_with_rect)
  15. cv2.imwrite("drawn_image_rect.jpg", drawn_image_rect)
  16. # print(result)
  17. # print(type(result))
  18. # with open('result.json', 'w', encoding='utf-8') as f:
  19. # f.write(result_json)
  20. # result_json = to_json_serializable(result.to_dict())
  21. # print(result_json)
  22. # print(json.loads(result_json))
  23. # with open('result.json', 'w', encoding='utf-8') as f:
  24. # json.dump(result_json, f, ensure_ascii=False, indent=2)