MCPcopy Create free account
hub / github.com/PaddlePaddle/PaddleOCR / _predict_text

Method _predict_text

ppstructure/predict_system.py:204–253  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

202 return None, None
203
204 def _predict_text(self, img):
205 filter_boxes, filter_rec_res, ocr_time_dict = self.text_system(img)
206
207 # remove style char,
208 # when using the recognition model trained on the PubtabNet dataset,
209 # it will recognize the text format in the table, such as <b>
210 style_token = [
211 "<strike>",
212 "<strike>",
213 "<sup>",
214 "</sub>",
215 "<b>",
216 "</b>",
217 "<sub>",
218 "</sup>",
219 "<overline>",
220 "</overline>",
221 "<underline>",
222 "</underline>",
223 "<i>",
224 "</i>",
225 ]
226 res = []
227 for box, rec_res in zip(filter_boxes, filter_rec_res):
228 rec_str, rec_conf = rec_res[0], rec_res[1]
229 for token in style_token:
230 if token in rec_str:
231 rec_str = rec_str.replace(token, "")
232 if self.return_word_box:
233 word_box_content_list, word_box_list = cal_ocr_word_box(
234 rec_str, box, rec_res[2]
235 )
236 res.append(
237 {
238 "text": rec_str,
239 "confidence": float(rec_conf),
240 "text_region": box.tolist(),
241 "text_word": word_box_content_list,
242 "text_word_region": word_box_list,
243 }
244 )
245 else:
246 res.append(
247 {
248 "text": rec_str,
249 "confidence": float(rec_conf),
250 "text_region": box.tolist(),
251 }
252 )
253 return res, ocr_time_dict
254
255 def _filter_text_res(self, text_res, bbox):
256 res = []

Callers 1

__call__Method · 0.95

Calls 1

cal_ocr_word_boxFunction · 0.90

Tested by

no test coverage detected