draw_potin.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from app.utils.card_inference.handle_result import process_detection_result
  2. import cv2
  3. import matplotlib.pyplot as plt
  4. import json
  5. # 示例使用
  6. if __name__ == "__main__":
  7. img_path = r"C:\Users\wow38\Pictures\WhimsicottUnifiedMinds144.jpg"
  8. json_data_path = r"C:\Users\wow38\Pictures\123.json"
  9. with open(json_data_path, "r") as f:
  10. json_data = json.load(f)
  11. image = cv2.imread(img_path)
  12. # 为不同类别设置不同颜色
  13. label_colors = {
  14. 'baseboard': (0, 255, 0),
  15. }
  16. result = process_detection_result(image, json_data, label_colors)
  17. # 显示结果
  18. plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
  19. plt.show()
  20. # cv2.imshow("Result", result)
  21. # cv2.waitKey(0)
  22. # cv2.destroyAllWindows()
  23. # # 加载示例图像
  24. # image = cv2.imread("example.jpg")
  25. #
  26. # # 为不同类别设置不同颜色
  27. # label_colors = {
  28. # 'baseboard': (0, 255, 0),
  29. # }
  30. #
  31. # # 示例检测结果
  32. # detection_result = {
  33. # 'num': 1,
  34. # 'cls': [1],
  35. # 'names': ['baseboard'],
  36. # 'conf': 0.9966249431977074,
  37. # 'shapes': [{
  38. # 'class_num': 1,
  39. # 'label': 'baseboard',
  40. # 'probability': 0.9966249431977074,
  41. # 'points': [[5, 171], [4, 172], [0, 172], [0, 487], [34, 487],
  42. # # ... 其他点 ...
  43. # [1019, 172], [1018, 171]]
  44. # }]
  45. # }
  46. #
  47. # # 处理图像
  48. # result = process_detection_result(image, detection_result, label_colors)
  49. #
  50. # # 显示结果
  51. # cv2.imshow("Result", result)
  52. # cv2.waitKey(0)
  53. # cv2.destroyAllWindows()