| 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 | |
| 150 | def to_excel(html_table, excel_path): |