-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_res.py
More file actions
45 lines (36 loc) · 1.19 KB
/
parse_res.py
File metadata and controls
45 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import numpy as np
import pandas as pd
import os
import subprocess
file_path = ""
if not file_path:
file_path_answer = input("file to parse: ")
file_path = file_path_answer
def parse_res(file_path: str) -> str:
with open(file_path) as f:
text = f.read()
data = json.loads(text)
print(data["input_path"])
# I think this whole thing assumes we only have one grouping of data that the ocr outputs
rec_texts = data["rec_texts"]
print(rec_texts)
arr1 = np.array(rec_texts)
arr2 = arr1.reshape(arr1.size, 1)
print(arr2)
# df = pd.DataFrame(arr2).T
# df = pd.DataFrame(arr1).T
df = pd.DataFrame({"col1": arr1})
name, ext = os.path.splitext(file_path)
df.to_excel(excel_writer = f"{name}.xlsx", columns=['col1'])
print("done.")
return f"{name}.xlsx"
val = parse_res(file_path)
print (val)
open_answer = input("do you want to open the image and the spreadsheet? (Y/N): ")
if open_answer == "Y" or open_answer == "y":
name, ext = os.path.splitext(file_path)
base = name.rsplit("res", 1)[0]
img_name = f"{base}ocr_res_img.png"
subprocess.call(("open", f"{name}.xlsx"))
subprocess.call(("open", img_name))