MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / decode

Method decode

openrec/postprocess/char_postprocess.py:58–108  ·  view source on GitHub ↗

convert text-index into text-label.

(
        self,
        text_index,
        text_prob=None,
        char_text_index=None,
        char_text_prob=None,
        is_remove_duplicate=False,
    )

Source from the content-addressed store, hash-verified

56 return dict_character
57
58 def decode(
59 self,
60 text_index,
61 text_prob=None,
62 char_text_index=None,
63 char_text_prob=None,
64 is_remove_duplicate=False,
65 ):
66 """convert text-index into text-label."""
67 result_list = []
68 box_result_list = []
69 batch_size = len(text_index)
70 for batch_idx in range(batch_size):
71 char_list = []
72 conf_list = []
73 char_box_list = []
74 conf_box_list = []
75 for idx in range(len(text_index[batch_idx])):
76 try:
77 char_idx = self.character[int(text_index[batch_idx][idx])]
78 if char_text_index is not None:
79 char_box_idx = self.character[int(
80 char_text_index[batch_idx][idx])]
81 except:
82 continue
83 if char_idx == '</s>': # end
84 break
85 char_list.append(char_idx)
86
87 if char_text_index is not None:
88 char_box_list.append(char_box_idx)
89
90 if text_prob is not None:
91 conf_list.append(text_prob[batch_idx][idx])
92 else:
93 conf_list.append(1)
94
95 if char_text_prob is not None:
96 conf_box_list.append(char_text_prob[batch_idx][idx])
97 else:
98 conf_box_list.append(1)
99 text = ''.join(char_list)
100 result_list.append((text, np.mean(conf_list).tolist()))
101
102 if char_text_index is not None:
103 text_box = ''.join(char_box_list)
104 box_result_list.append(
105 (text_box, np.mean(conf_box_list).tolist()))
106 if char_text_index is not None:
107 return result_list, box_result_list
108 return result_list

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected