import numpy as np import cv2 from search import gen_im_from_params, get_bim_height, bim_compare_to_hd_roi, read_from_json from utils import get_hd_roi_from_txt roi_list_after_cal = [ np.array([[338, 164], [462, 164], [462, 289], [338, 289]], dtype=np.int32), np.array([[296, 86], [360, 86], [360, 151], [296, 151]], dtype=np.int32), np.array([[113, 1], [207, 1], [207, 88], [113, 88]], dtype=np.int32), np.array([[206, 259], [281, 259], [281, 335], [206, 335]], dtype=np.int32), np.array([[384, 35], [448, 35], [448, 102], [384, 102]], dtype=np.int32), np.array([[127, 180], [275, 180], [275, 241], [127, 241]], dtype=np.int32) ] image = cv2.imread("./result.png") for index in range(len(roi_list_after_cal)): item = roi_list_after_cal[index] cv2.polylines(image, [item], True, (0, 0, 255), 2) # index cv2.putText(image, str(index), (item[0][0], item[0][1]+5), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) cv2.imshow("image", image) cv2.waitKey(0) # ====================== 预埋件号码匹配 开始 ========================= data_bim_json = read_from_json("data_bim.json") # bim数据 bim_sub_area = {'code': 1, 'type': '250x1450', 'x': 945, 'y': 0, 'center': 351, 'w': 1450, 'h': 250, 'angle': '0', 'x1': 220, 'y1': 1833, 'x2': 1670, 'y2': 1833, 'x3': 1670, 'y3': 2083, 'x4': 220, 'y4': 2083, 'x_center': 945, 'y_center': 1958, 'effective_points': [[220, 1833, 0], [1670, 1833, 0], [1670, 2083, 0], [220, 2083, 0], [945, 1958, 0], [773, 1405, 1], [1073, 1405, 1], [1073, 1705, 1], [773, 1705, 1], [923, 1555, 1], [1388, 1005, 2], [1888, 1005, 2], [1888, 1506, 2], [1388, 1506, 2], [1638, 1255, 2], [393, 1035, 3], [1041, 1035, 3], [1041, 1285, 3], [393, 1285, 3], [717, 1160, 3], [1212, 641, 4], [1462, 641, 4], [1462, 891, 4], [1212, 891, 4], [1337, 766, 4], [1655, 435, 5], [1904, 435, 5], [1904, 684, 5], [1655, 684, 5], [1779, 559, 5], [349, 154, 6], [748, 154, 6], [748, 554, 6], [349, 554, 6], [548, 354, 6], [992, 0, 7], [1294, 0, 7], [1294, 300, 7], [992, 300, 7], [1143, 150, 7], [1594, 2, 8], [1896, 2, 8], [1896, 302, 8], [1594, 302, 8], [1745, 152, 8], [2215, 1840, 9], [2215, 2088, 9], [2938, 1964, 9], [2798, 1413, 10], [3095, 1413, 10], [3095, 1711, 10], [2798, 1711, 10], [2946, 1562, 10], [3390, 1020, 11], [3390, 1519, 11], [2419, 1041, 12], [3067, 1041, 12], [3067, 1286, 12], [2419, 1286, 12], [2743, 1163, 12], [3214, 636, 13], [3214, 883, 13], [3337, 759, 13], [2352, 155, 15], [2744, 155, 15], [2744, 553, 15], [2352, 553, 15], [2548, 354, 15], [2996, 12, 16], [3289, 12, 16], [3289, 312, 16], [2996, 312, 16], [3142, 162, 16]], 'start_point': (-643, -805), 'end_point': (3413, 2998), 'score': (0.9973816190955833, 73, 2007.9927917215468, -0.5308235609555432), 'match_score': 0.49774032187522993, 'hd_cam_x_bim': -135, 'hd_cam_y_bim': 304, 'hd_cam_w_bim': 2472, 'hd_cam_h_bim': 1854} bim_im = gen_im_from_params(data_bim_json) # bim图 hd_roi_list = get_hd_roi_from_txt("data_sub/test_1/roi_conners.txt") # 高清摄像头的ROI数据 hd_img_width = int(9344/16) hd_img_height = int(7000/16) bim_im_height = get_bim_height(data_bim_json) bim_rect_hit_list = bim_compare_to_hd_roi(roi_list_after_cal, hd_img_width, hd_img_height, bim_im_height, bim_sub_area, data_bim_json) print(f"[bim_rect_hit_list] ====== [{len(bim_rect_hit_list)}]") # ===================== 预埋件号码匹配 结束 ===========================