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

Method _ocr

ppstructure/table/predict_table.py:121–147  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

119 return structure_res, elapse
120
121 def _ocr(self, img):
122 h, w = img.shape[:2]
123 dt_boxes, det_elapse = self.text_detector(copy.deepcopy(img))
124 dt_boxes = sorted_boxes(dt_boxes)
125
126 r_boxes = []
127 for box in dt_boxes:
128 x_min = max(0, box[:, 0].min() - 1)
129 x_max = min(w, box[:, 0].max() + 1)
130 y_min = max(0, box[:, 1].min() - 1)
131 y_max = min(h, box[:, 1].max() + 1)
132 box = [x_min, y_min, x_max, y_max]
133 r_boxes.append(box)
134 dt_boxes = np.array(r_boxes)
135 logger.debug("dt_boxes num : {}, elapse : {}".format(len(dt_boxes), det_elapse))
136 if dt_boxes is None:
137 return None, None
138
139 img_crop_list = []
140 for i in range(len(dt_boxes)):
141 det_box = dt_boxes[i]
142 x0, y0, x1, y1 = expand(2, det_box, img.shape)
143 text_rect = img[int(y0) : int(y1), int(x0) : int(x1), :]
144 img_crop_list.append(text_rect)
145 rec_res, rec_elapse = self.text_recognizer(img_crop_list)
146 logger.debug("rec_res num : {}, elapse : {}".format(len(rec_res), rec_elapse))
147 return dt_boxes, rec_res, det_elapse, rec_elapse
148
149
150def to_excel(html_table, excel_path):

Callers 2

mainFunction · 0.95
__call__Method · 0.95

Calls 4

sorted_boxesFunction · 0.90
minFunction · 0.85
expandFunction · 0.85
formatMethod · 0.80

Tested by

no test coverage detected