|
|
@@ -51,58 +51,3 @@ class TableRecResult(BaseCVResult):
|
|
|
box = np.reshape(np.array(box), [-1, 1, 2]).astype(np.int64)
|
|
|
image = cv2.polylines(np.array(image), [box], True, (255, 0, 0), 2)
|
|
|
return image
|
|
|
-
|
|
|
-
|
|
|
-class StructureTableResult(TableRecResult, HtmlMixin, XlsxMixin):
|
|
|
- """StructureTableResult"""
|
|
|
-
|
|
|
- def __init__(self, data):
|
|
|
- super().__init__(data)
|
|
|
- HtmlMixin.__init__(self)
|
|
|
- XlsxMixin.__init__(self)
|
|
|
-
|
|
|
- def _to_html(self):
|
|
|
- return self["html"]
|
|
|
-
|
|
|
-
|
|
|
-class TableResult(BaseCVResult, HtmlMixin, XlsxMixin):
|
|
|
- """TableResult"""
|
|
|
-
|
|
|
- def __init__(self, data):
|
|
|
- super().__init__(data)
|
|
|
- HtmlMixin.__init__(self)
|
|
|
- XlsxMixin.__init__(self)
|
|
|
-
|
|
|
- def save_to_html(self, save_path):
|
|
|
- if not save_path.lower().endswith(("html")):
|
|
|
- input_path = self["input_path"]
|
|
|
- save_path = Path(save_path) / f"{Path(input_path).stem}"
|
|
|
- else:
|
|
|
- save_path = Path(save_path).stem
|
|
|
- for table_result in self["table_result"]:
|
|
|
- table_result.save_to_html(save_path)
|
|
|
-
|
|
|
- def save_to_xlsx(self, save_path):
|
|
|
- if not save_path.lower().endswith(("xlsx")):
|
|
|
- input_path = self["input_path"]
|
|
|
- save_path = Path(save_path) / f"{Path(input_path).stem}"
|
|
|
- else:
|
|
|
- save_path = Path(save_path).stem
|
|
|
- for table_result in self["table_result"]:
|
|
|
- table_result.save_to_xlsx(save_path)
|
|
|
-
|
|
|
- def save_to_img(self, save_path):
|
|
|
- if not save_path.lower().endswith((".jpg", ".png")):
|
|
|
- input_path = self["input_path"]
|
|
|
- save_path = Path(save_path) / f"{Path(input_path).stem}"
|
|
|
- else:
|
|
|
- save_path = Path(save_path).stem
|
|
|
- layout_save_path = f"{save_path}_layout.jpg"
|
|
|
- ocr_save_path = f"{save_path}_ocr.jpg"
|
|
|
- table_save_path = f"{save_path}_table"
|
|
|
- layout_result = self["layout_result"]
|
|
|
- layout_result.save_to_img(layout_save_path)
|
|
|
- ocr_result = self["ocr_result"]
|
|
|
- ocr_result.save_to_img(ocr_save_path)
|
|
|
- for idx, table_result in enumerate(self["table_result"]):
|
|
|
- table_result.save_to_img(f"{table_save_path}_{idx}.jpg")
|