Exemple #1
0
    def get_affinity_boxes_list(self, image, word_boxes, words):
        char_boxes_list = list()
        affinity_boxes_list = list()
        confidence_list = list()

        for word_box, word in zip(word_boxes, words):
            char_boxes, confidence = self.fake_char_boxes(image, word_box, len(word))
            affinity_boxes = cal_affinity_boxes(char_boxes)
            affinity_boxes_list.append((affinity_boxes))
            char_boxes_list.append(char_boxes)
            confidence_list.append(confidence)

        char_boxes_list = list(chain.from_iterable(char_boxes_list))
        affinity_boxes_list = list(chain.from_iterable(affinity_boxes_list))
        return char_boxes_list, affinity_boxes_list, confidence_list
def get_affinity_boxes_list(char_boxes_array, wordsList):
    """

    :param char_boxes_array: 字符边框矩阵
    :param wordsList: 从SynthText/gt.mat中读取到的文字列表
    :return: 字符边框列表和字间边框列表
    """
    # 字符索引,确定word中字符个数
    affinity_boxes_list = list()
    char_boxes_list = list()
    start = 0
    for word in wordsList:
        index = len(word)
        char_boxes = char_boxes_array[start:start + index, :, :]
        affinity_boxes_list.append(cal_affinity_boxes(char_boxes))
        char_boxes_list.append(char_boxes)
        start = start + index
    affinity_boxes_list = list(chain.from_iterable(affinity_boxes_list))
    char_boxes_list = list(chain.from_iterable(char_boxes_list))
    return char_boxes_list, affinity_boxes_list
def create_affinity_box(boxes):
    affinity_boxes = cal_affinity_boxes(boxes)
    return affinity_boxes
Exemple #4
0
def create_pseudo_gt(word_boxes, word_lengths, region, affinity, confidence,
                     pred_region):
    """
    Generate character boxes from each word-level annotation in a weakly-supervised manner.
    In order to reflect the reliability of the interim model’s prediction,
    the value of the confidence map over each word box is computed proportional to the number of
    the detected characters divided by the number of the ground truth characters,
    which is used for the learning weight during training.
    :param word_boxes: (word boxes, word_length).
    :param word_lengths: region map.
    :param region: region map.
    :param affinity: affinity map.
    :param confidence: confidence map.
    :param pred_region: region map.
    :return: region map, affinity map, confidence map.
    """
    gaussian_generator = GaussianGenerator()
    for word_box, word_length in zip(word_boxes, word_lengths):
        if word_length > 0:
            try:
                word_box = reorder_points(word_box)
                heat_map, src_points, crop_points = crop_image(
                    pred_region * 255., word_box)
                heat_map = heat_map.astype(np.uint8)
                marker_map = watershed(heat_map)
                region_boxes = find_box(marker_map)

                confidence_value = cal_confidence(region_boxes, word_length)
                if confidence_value <= 0.5:
                    confidence_value = 0.5
                    region_boxes = divide_region(word_box, word_length)
                    region_boxes = [
                        reorder_points(region_box)
                        for region_box in region_boxes
                    ]
                else:
                    region_boxes = enlarge_char_boxes(region_boxes,
                                                      crop_points)
                    region_boxes = [
                        un_warping(region_box, src_points, crop_points)
                        for region_box in region_boxes
                    ]

                tmp_confidence_mask = np.zeros(confidence.shape[:2],
                                               dtype=np.uint8)
                cv2.fillPoly(tmp_confidence_mask, [np.int32(word_box)], 1)
                tmp_confidence = tmp_confidence_mask.astype(
                    np.float32) * confidence_value
                confidence = (
                    1 - tmp_confidence_mask) * confidence + tmp_confidence

                tmp_region = np.float32(
                    gaussian_generator.gen(region.shape[:2], region_boxes))
                region = np.where(tmp_region > 0, tmp_region, region)

                affinity_boxes = cal_affinity_boxes(region_boxes)
                tmp_affinity = np.float32(
                    gaussian_generator.gen(affinity.shape[:2], affinity_boxes))
                affinity = np.where(tmp_affinity > 0, tmp_affinity, affinity)
            except Exception as e:
                print(e)
                traceback.print_exc()
        else:
            break

    return region, affinity, confidence