Beispiel #1
0
def detection_filtering(detections, groundtruths, threshold=0.5):
    for gt_id, gt in enumerate(groundtruths):
        if (gt[5].size == 0 or gt[5] == '#') and (gt[1].shape[1] > 1):
            gt_x = list(map(int, np.squeeze(gt[1])))
            gt_y = list(map(int, np.squeeze(gt[3])))
            for det_id, detection in enumerate(detections):
                detection = detection.split(',')
                detection = list(map(int, detection[0:-1]))
                det_y = detection[0::2]
                det_x = detection[1::2]
                det_gt_iou = iod(det_x, det_y, gt_x, gt_y)
                if det_gt_iou > threshold:
                    detections[det_id] = []

            detections[:] = [item for item in detections if item != []]
    return detections
def detection_filtering(detections, groundtruths, threshold=0.5):
    """ignore detected illegal text region"""
    before_filter_num = len(detections)
    for gt_id, gt in enumerate(groundtruths):
        if (gt['transcription'] == '###') and (gt['points'].shape[1] > 1):
            gt_x = list(map(int, np.squeeze(gt['points'][:, 0])))
            gt_y = list(map(int, np.squeeze(gt['points'][:, 1])))
            for det_id, detection in enumerate(detections):
                det_x = list(map(int, np.squeeze(detection['points'][:, 0])))
                det_y = list(map(int, np.squeeze(detection['points'][:, 1])))
                det_gt_iou = iod(det_x, det_y, gt_x, gt_y)
                if det_gt_iou > threshold:
                    detections[det_id] = []

            detections[:] = [item for item in detections if item != []]

    # if before_filter_num - len(detections) > 0:
    #     print("Ignore {} illegal detections".format(before_filter_num - len(detections)))

    return detections