(self, img, return_ocr_result_in_table=False, img_idx=0)
| 96 | self.return_word_box = args.return_word_box |
| 97 | |
| 98 | def __call__(self, img, return_ocr_result_in_table=False, img_idx=0): |
| 99 | time_dict = { |
| 100 | "image_orientation": 0, |
| 101 | "layout": 0, |
| 102 | "table": 0, |
| 103 | "table_match": 0, |
| 104 | "formula": 0, |
| 105 | "det": 0, |
| 106 | "rec": 0, |
| 107 | "kie": 0, |
| 108 | "all": 0, |
| 109 | } |
| 110 | start = time.time() |
| 111 | |
| 112 | if self.image_orientation_predictor is not None: |
| 113 | tic = time.time() |
| 114 | cls_result = self.image_orientation_predictor.predict(input_data=img) |
| 115 | cls_res = next(cls_result) |
| 116 | angle = cls_res[0]["label_names"][0] |
| 117 | cv_rotate_code = { |
| 118 | "90": cv2.ROTATE_90_COUNTERCLOCKWISE, |
| 119 | "180": cv2.ROTATE_180, |
| 120 | "270": cv2.ROTATE_90_CLOCKWISE, |
| 121 | } |
| 122 | if angle in cv_rotate_code: |
| 123 | img = cv2.rotate(img, cv_rotate_code[angle]) |
| 124 | toc = time.time() |
| 125 | time_dict["image_orientation"] = toc - tic |
| 126 | |
| 127 | if self.mode == "structure": |
| 128 | ori_im = img.copy() |
| 129 | if self.layout_predictor is not None: |
| 130 | layout_res, elapse = self.layout_predictor(img) |
| 131 | time_dict["layout"] += elapse |
| 132 | else: |
| 133 | h, w = ori_im.shape[:2] |
| 134 | layout_res = [dict(bbox=None, label="table", score=0.0)] |
| 135 | |
| 136 | # As reported in issues such as #10270 and #11665, the old |
| 137 | # implementation, which recognizes texts from the layout regions, |
| 138 | # has problems with OCR recognition accuracy. |
| 139 | # |
| 140 | # To enhance the OCR recognition accuracy, we implement a patch fix |
| 141 | # that first use text_system to detect and recognize all text information |
| 142 | # and then filter out relevant texts according to the layout regions. |
| 143 | text_res = None |
| 144 | if self.text_system is not None: |
| 145 | text_res, ocr_time_dict = self._predict_text(img) |
| 146 | time_dict["det"] += ocr_time_dict["det"] |
| 147 | time_dict["rec"] += ocr_time_dict["rec"] |
| 148 | |
| 149 | res_list = [] |
| 150 | for region in layout_res: |
| 151 | res = "" |
| 152 | if region["bbox"] is not None: |
| 153 | x1, y1, x2, y2 = region["bbox"] |
| 154 | x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) |
| 155 | roi_img = ori_im[y1:y2, x1:x2, :] |
nothing calls this directly
no test coverage detected