MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / save_structure_res

Function save_structure_res

tools/test_hubserving.py:75–97  ·  view source on GitHub ↗
(res, save_folder, image_file)

Source from the content-addressed store, hash-verified

73
74
75def save_structure_res(res, save_folder, image_file):
76 img = cv2.imread(image_file)
77 excel_save_folder = os.path.join(save_folder, os.path.basename(image_file))
78 os.makedirs(excel_save_folder, exist_ok=True)
79 # save res
80 with open(os.path.join(excel_save_folder, "res.txt"), "w", encoding="utf8") as f:
81 for region in res:
82 if region["type"] == "Table":
83 excel_path = os.path.join(
84 excel_save_folder, "{}.xlsx".format(region["bbox"])
85 )
86 to_excel(region["res"], excel_path)
87 elif region["type"] == "Figure":
88 x1, y1, x2, y2 = region["bbox"]
89 print(region["bbox"])
90 roi_img = img[y1:y2, x1:x2, :]
91 img_path = os.path.join(
92 excel_save_folder, "{}.jpg".format(region["bbox"])
93 )
94 cv2.imwrite(img_path, roi_img)
95 else:
96 for text_result in region["res"]:
97 f.write("{}\n".format(json.dumps(text_result)))
98
99
100def main(args):

Callers 1

mainFunction · 0.70

Calls 3

to_excelFunction · 0.85
imreadMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…