You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xBank-Code-AI/analysis_result/tools_analysis.py

75 lines
2.0 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

def iou_result_two(result_dict_list,iou_para):
result_0 = list(result_dict_list[0].values())[0]
result_1 = list(result_dict_list[1].values())[0]
label_0 = list(result_dict_list[0].keys())[0]
label_1 = list(result_dict_list[1].keys())[0]
return_lists = []
for re_0 in result_0:
for re_1 in result_1:
iou = calculate_iou(re_0, re_1)
if iou > iou_para:
label_dict_0 = {label_0: re_0}
label_dict_1 = {label_1: re_1}
return_lists.append(label_dict_0)
return_lists.append(label_dict_1)
return return_lists
def calculate_iou(box1, box2):
"""
计算两个边界框之间的IoU值
参数:
box1: 边界框1的坐标x1, y1, x2, y2
box2: 边界框2的坐标x1, y1, x2, y2
返回值:
iou: 两个边界框之间的IoU值
"""
x1 = max(box1[0], box2[0])
y1 = max(box1[1], box2[1])
x2 = min(box1[2], box2[2])
y2 = min(box1[3], box2[3])
# 计算交集区域面积
intersection_area = max(0, x2 - x1 + 1) * max(0, y2 - y1 + 1)
# 计算边界框1和边界框2的面积
box1_area = (box1[2] - box1[0] + 1) * (box1[3] - box1[1] + 1)
box2_area = (box2[2] - box2[0] + 1) * (box2[3] - box2[1] + 1)
# 计算并集区域面积
union_area = box1_area + box2_area - intersection_area
# 计算IoU值
iou = intersection_area / union_area
return iou
def select_bbox_by_labels(example_list, result_dicts_list):
'''
将result列表中的example列表内的bbox挑选出来,放到同一字典下
'''
result_dict_list_change = []
for label in example_list:
bbox_list = []
for result in result_dicts_list:
if list(result.keys())[0] == label:
bbox_list.append(list(result.values())[0])
result_dict_change = {label: bbox_list}
result_dict_list_change.append(result_dict_change)
return result_dict_list_change