调整zx_ocr的存表

This commit is contained in:
2024-06-20 17:28:10 +08:00
parent 4cc89b24fc
commit e7105eb2e4

View File

@@ -4,6 +4,7 @@ import math
import os import os
import sys import sys
import tempfile import tempfile
import time
from io import BytesIO from io import BytesIO
import paddle import paddle
@@ -99,7 +100,7 @@ def information_extraction(ie, phrecs):
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file: with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
img["img"].save(temp_file.name) img["img"].save(temp_file.name)
docs.append({"doc": temp_file.name}) docs.append({"doc": temp_file.name})
doc_phrecs.append(phrec) doc_phrecs.append({"phrec": phrec, "x_offset": img["x_offset"], "y_offset": img["y_offset"]})
if not docs: if not docs:
return result return result
@@ -117,15 +118,18 @@ def information_extraction(ie, phrecs):
logging.info(f"删除临时文件 {temp_file['doc']} 时出错: {e}") logging.info(f"删除临时文件 {temp_file['doc']} 时出错: {e}")
now = get_default_datetime() now = get_default_datetime()
id = int(time.time())
for i in range(len(ie_results)): for i in range(len(ie_results)):
ie_result = ie_results[i] ie_result = ie_results[i]
phrec = doc_phrecs[i] doc_phrec = doc_phrecs[i]
phrec = doc_phrec["phrec"]
result_json = json.dumps(ie_result, ensure_ascii=False) result_json = json.dumps(ie_result, ensure_ascii=False)
if len(result_json) > 5000: if len(result_json) > 5000:
result_json = result_json[:5000] result_json = result_json[:5000]
session = MysqlSession() session = MysqlSession()
zx_ocr = ZxOcr(pk_phhd=phrec.pk_phhd, pk_phrec=phrec.pk_phrec, cfjaddress=phrec.cfjaddress, zx_ocr = ZxOcr(pk_phhd=phrec.pk_phhd, pk_phrec=phrec.pk_phrec, id=id, cfjaddress=phrec.cfjaddress,
content=result_json, create_time=now, update_time=now) content=result_json, x_offset=doc_phrec["x_offset"], y_offset=doc_phrec["y_offset"],
create_time=now, update_time=now)
session.add(zx_ocr) session.add(zx_ocr)
session.commit() session.commit()
session.close() session.close()