将程序 stdout 写入文件
This commit is contained in:
parent
31ba144974
commit
8420b3471a
@ -177,15 +177,17 @@ def run_ocr(image):
|
|||||||
"sudo", "-u", "tmfc",
|
"sudo", "-u", "tmfc",
|
||||||
"/home/tmfc/miniconda3/envs/got/bin/python3", "/home/tmfc/apps/got-ocr/GOT/demo/run_ocr_2.0_crop.py",
|
"/home/tmfc/miniconda3/envs/got/bin/python3", "/home/tmfc/apps/got-ocr/GOT/demo/run_ocr_2.0_crop.py",
|
||||||
"--model-name", "/home/tmfc/apps/got-ocr/models/",
|
"--model-name", "/home/tmfc/apps/got-ocr/models/",
|
||||||
"--image-file", image_path,
|
"--image-file", image_path
|
||||||
"> /home/tmfc/apps/got-ocr/img.txt"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
out_file = "/home/tmfc/apps/got-ocr/img.txt"
|
||||||
try:
|
try:
|
||||||
subprocess.run(command, check=True)
|
with open(out_file, 'w') as f:
|
||||||
|
result = subprocess.run(command, stdout=f, stderr=subprocess.PIPE, text=True)
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
return f"识别失败: {e}"
|
return f"识别失败: {e}"
|
||||||
with open("/home/tmfc/apps/got-ocr/img.txt", 'r', encoding='utf-8') as f:
|
with open(out_file, 'r', encoding='utf-8') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user