写入 *.boxs
Browse files- ocr/gendatav2.py +15 -1
ocr/gendatav2.py
CHANGED
|
@@ -2,13 +2,20 @@
|
|
| 2 |
转换一章数据
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import json
|
| 6 |
import glob
|
| 7 |
from pathlib import Path
|
| 8 |
import cv2
|
| 9 |
import numpy as np
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
raw_jsons = glob.glob('./out/raw/**/*.json', recursive=True)
|
|
@@ -39,6 +46,13 @@ for page in pages:
|
|
| 39 |
if pageId not in box_jsons:
|
| 40 |
raise Exception(f"pageId {pageId} no box_json")
|
| 41 |
boxs = box_jsons[pageId]['wordBoxList']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
pass
|
| 43 |
|
| 44 |
|
|
|
|
| 2 |
转换一章数据
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
import json
|
| 8 |
import glob
|
| 9 |
from pathlib import Path
|
| 10 |
import cv2
|
| 11 |
import numpy as np
|
| 12 |
|
| 13 |
+
dir_out2 = "out2"
|
| 14 |
+
if Path(dir_out2).exists():
|
| 15 |
+
shutil.rmtree(dir_out2)
|
| 16 |
+
|
| 17 |
+
if not Path(dir_out2).exists():
|
| 18 |
+
os.makedirs(dir_out2)
|
| 19 |
|
| 20 |
|
| 21 |
raw_jsons = glob.glob('./out/raw/**/*.json', recursive=True)
|
|
|
|
| 46 |
if pageId not in box_jsons:
|
| 47 |
raise Exception(f"pageId {pageId} no box_json")
|
| 48 |
boxs = box_jsons[pageId]['wordBoxList']
|
| 49 |
+
pth_boxs = str( dir_out2 / Path( imageName.replace(".webp", ".boxs") ) )
|
| 50 |
+
|
| 51 |
+
shutil.copy(pth_img, str( dir_out2 / Path(imageName) ) )
|
| 52 |
+
with open(pth_boxs, 'w', encoding='utf-8') as fp:
|
| 53 |
+
json.dump(boxs, fp, indent=4, ensure_ascii=False)
|
| 54 |
+
fp.close()
|
| 55 |
+
|
| 56 |
pass
|
| 57 |
|
| 58 |
|