Download json2txt.py from kiaisoft/trace_src: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/kiaisoft/trace_src/resolve/main/json2txt.py
- Command line
-
hf download hf://kiaisoft/trace_src/json2txt.py
-
curl -L -o json2txt.py https://huggingface.co/kiaisoft/trace_src/resolve/main/json2txt.py
1.1 kB
| import json | |
| import cv2 | |
| import os | |
| page70_folder = "/home/tuvu/Downloads/9_11_2025" | |
| save_folder = "vis_img" | |
| os.makedirs(save_folder, exist_ok=True) | |
| for name in os.listdir(page70_folder): | |
| if name.endswith("json"): | |
| json_name = os.path.join(page70_folder, name) | |
| with open(json_name, "r") as f: | |
| data = json.load(f) | |
| items = data.get("items", []) | |
| img_name = name.split('.')[0] + ".png" | |
| print(img_name) | |
| image = cv2.imread(os.path.join(page70_folder,img_name)) | |
| print(image.shape) | |
| # Filter items where type == "label" | |
| tables = [item for item in items if item.get("type") == "table"] | |
| for table in tables: | |
| x, y = 2 * int(table["x"]),2* int(table["y"]) | |
| w, h =2* table["width"], 2 * table["height"] | |
| top_left = (x, y) | |
| bottom_right = (x + w, y + h) | |
| print(top_left, bottom_right) | |
| cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2) # green box | |
| # Save or show | |
| cv2.imwrite(os.path.join(save_folder, img_name), image) |