计算居中.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import dataclasses
  2. import cv2
  3. import numpy as np
  4. import json
  5. from app.utils.defect_inference.AnalyzeCenter import analyze_centering_rotated, draw_rotated_bounding_boxes
  6. if __name__ == "__main__":
  7. img_path = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\250805_pokemon_0001.jpg"
  8. inner_file_path = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\inner\250805_pokemon_0001.json"
  9. outer_file_path = r"C:\Code\ML\Project\CheckCardBoxAndDefectServer\temp\outer\250805_pokemon_0001.json"
  10. # center_result = analyze_centering_rotated(inner_file_path, outer_file_path)
  11. # draw_rotated_bounding_boxes(img_path, inner_file_path, outer_file_path)
  12. with open(inner_file_path, "r", encoding="utf-8") as f:
  13. inner_data = json.load(f)
  14. with open(outer_file_path, "r", encoding="utf-8") as f:
  15. outer_data = json.load(f)
  16. inner_points = inner_data['shapes'][0]['points']
  17. outer_points = outer_data['shapes'][0]['points']
  18. center_result = analyze_centering_rotated(inner_points, outer_points)
  19. data = {
  20. "img_id": 2,
  21. "img_url": "",
  22. "inference_result": {
  23. "center_inference": {
  24. "angel_diff": center_result[2],
  25. "center_left": center_result[0][0],
  26. "center_right": center_result[0][1],
  27. "center_top": center_result[1][0],
  28. "center_bottom": center_result[1][1]
  29. }
  30. }
  31. }
  32. data['inference_result']['inner_box'] = inner_data
  33. data['inference_result']['outer_box'] = outer_data
  34. print(data)