| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- from app.utils.card_inference.handle_result import process_detection_result
- import cv2
- import matplotlib.pyplot as plt
- import json
- # 示例使用
- if __name__ == "__main__":
- img_path = r"C:\Users\wow38\Pictures\WhimsicottUnifiedMinds144.jpg"
- json_data_path = r"C:\Users\wow38\Pictures\123.json"
- with open(json_data_path, "r") as f:
- json_data = json.load(f)
- image = cv2.imread(img_path)
- # 为不同类别设置不同颜色
- label_colors = {
- 'baseboard': (0, 255, 0),
- }
- result = process_detection_result(image, json_data, label_colors)
- # 显示结果
- plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
- plt.show()
- # cv2.imshow("Result", result)
- # cv2.waitKey(0)
- # cv2.destroyAllWindows()
- # # 加载示例图像
- # image = cv2.imread("example.jpg")
- #
- # # 为不同类别设置不同颜色
- # label_colors = {
- # 'baseboard': (0, 255, 0),
- # }
- #
- # # 示例检测结果
- # detection_result = {
- # 'num': 1,
- # 'cls': [1],
- # 'names': ['baseboard'],
- # 'conf': 0.9966249431977074,
- # 'shapes': [{
- # 'class_num': 1,
- # 'label': 'baseboard',
- # 'probability': 0.9966249431977074,
- # 'points': [[5, 171], [4, 172], [0, 172], [0, 487], [34, 487],
- # # ... 其他点 ...
- # [1019, 172], [1018, 171]]
- # }]
- # }
- #
- # # 处理图像
- # result = process_detection_result(image, detection_result, label_colors)
- #
- # # 显示结果
- # cv2.imshow("Result", result)
- # cv2.waitKey(0)
- # cv2.destroyAllWindows()
|