在自动识别时将图片转正并上传到云端

This commit is contained in:
2024-08-13 14:10:35 +08:00
parent d0b9370b60
commit 52c74062e1
3 changed files with 42 additions and 18 deletions

View File

@@ -105,4 +105,8 @@
1. 照片涂抹重新添加方向识别与矫正,因为照片审核人员暂无法保证所有图片的方向正确 1. 照片涂抹重新添加方向识别与矫正,因为照片审核人员暂无法保证所有图片的方向正确
2. 添加照片涂抹错误分析 2. 添加照片涂抹错误分析
3. 优化图片分割和拓展,对横竖图片分别进行优化 3. 优化图片分割和拓展,对横竖图片分别进行优化
4. 优化镜像构建,将依赖与内容分开,显著提高构建速度 4. 优化镜像构建,将依赖与内容分开,显著提高构建速度
18. 版本号1.11.0
1. 修正含旋转的信息抽取结果的绘制
2. 调整zx_ocr表名为zx_ie_result
3. 在自动识别时将图片转正并上传到云端

View File

@@ -1,6 +1,6 @@
x-env: x-env:
&template &template
image: fcb_photo_review:1.10.4 image: fcb_photo_review:1.11.0
restart: always restart: always
services: services:

View File

@@ -3,6 +3,7 @@ import logging
import os import os
import tempfile import tempfile
import time import time
from collections import defaultdict
from time import sleep from time import sleep
import cv2 import cv2
@@ -67,25 +68,25 @@ def request_ie_result(task_enum, phrecs):
# 关键信息提取 # 关键信息提取
def information_extraction(ie, phrecs): def information_extraction(ie, phrecs, identity):
result = {} result = {}
# 同一批图的标识
identity = int(time.time())
for phrec in phrecs: for phrec in phrecs:
img_path = ufile.get_private_url(phrec.cfjaddress) img_path = ufile.get_private_url(phrec.cfjaddress)
if not img_path: if not img_path:
continue continue
split_results = image_util.split(img_path) image = image_util.read(img_path)
angles = image_util.parse_rotation_angles(image)
angle_count = defaultdict(int, {"0": 0})
split_results = image_util.split(image)
for split_result in split_results: for split_result in split_results:
angles = image_util.parse_rotation_angles(split_result["img"])
rotated_img = image_util.rotate(split_result["img"], int(angles[0])) rotated_img = image_util.rotate(split_result["img"], int(angles[0]))
ie_results = [{"result": ie_temp_image(ie, OCR, rotated_img), "angle": angles[0]}] ie_results = [{"result": ie_temp_image(ie, OCR, rotated_img), "angle": angles[0]}]
if not ie_results[0] or len(ie_results[0]) < len(ie.kwargs.get("schema")): if not ie_results[0]["result"] or len(ie_results[0]["result"]) < len(ie.kwargs.get("schema")):
rotated_img = image_util.rotate(split_result["img"], int(angles[1])) rotated_img = image_util.rotate(split_result["img"], int(angles[1]))
ie_results.append({"result": ie_temp_image(ie, OCR, rotated_img), "angle": angles[1]}) ie_results.append({"result": ie_temp_image(ie, OCR, rotated_img), "angle": angles[1]})
now = util.get_default_datetime() now = util.get_default_datetime()
best_angle = ["0", 0]
for ie_result in ie_results: for ie_result in ie_results:
result_json = json.dumps(ie_result["result"], ensure_ascii=False) result_json = json.dumps(ie_result["result"], ensure_ascii=False)
if len(result_json) > 5000: if len(result_json) > 5000:
@@ -101,6 +102,23 @@ def information_extraction(ie, phrecs):
result = merge_result(result, ie_result["result"]) result = merge_result(result, ie_result["result"])
if len(ie_result["result"]) > best_angle[1]:
best_angle = [ie_result["angle"], len(ie_result["result"])]
angle_count[best_angle[0]] += 1
img_angle = max(angle_count, key=angle_count.get)
if img_angle != "0":
image = image_util.rotate(image, int(img_angle))
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
cv2.imwrite(temp_file.name, image)
try:
ufile.upload_file(phrec.cfjaddress, temp_file.name)
except Exception as e:
logging.error(f"上传图片({phrec.cfjaddress})失败", exc_info=e)
finally:
util.delete_temp_file(temp_file.name)
return result return result
@@ -159,8 +177,8 @@ def save_or_update_ie(table, pk_phhd, data):
session.close() session.close()
def settlement_task(pk_phhd, settlement_list): def settlement_task(pk_phhd, settlement_list, identity):
settlement_list_ie_result = information_extraction(SETTLEMENT_IE, settlement_list) settlement_list_ie_result = information_extraction(SETTLEMENT_IE, settlement_list, identity)
settlement_data = { settlement_data = {
"pk_phhd": pk_phhd, "pk_phhd": pk_phhd,
"name": handle_name(get_best_value_in_keys(settlement_list_ie_result, PATIENT_NAME)), "name": handle_name(get_best_value_in_keys(settlement_list_ie_result, PATIENT_NAME)),
@@ -192,8 +210,8 @@ def settlement_task(pk_phhd, settlement_list):
save_or_update_ie(ZxIeSettlement, pk_phhd, settlement_data) save_or_update_ie(ZxIeSettlement, pk_phhd, settlement_data)
def discharge_task(pk_phhd, discharge_record): def discharge_task(pk_phhd, discharge_record, identity):
discharge_record_ie_result = information_extraction(DISCHARGE_IE, discharge_record) discharge_record_ie_result = information_extraction(DISCHARGE_IE, discharge_record, identity)
discharge_data = { discharge_data = {
"pk_phhd": pk_phhd, "pk_phhd": pk_phhd,
"hospital": handle_hospital(get_best_value_in_keys(discharge_record_ie_result, HOSPITAL)), "hospital": handle_hospital(get_best_value_in_keys(discharge_record_ie_result, HOSPITAL)),
@@ -233,8 +251,8 @@ def discharge_task(pk_phhd, discharge_record):
save_or_update_ie(ZxIeDischarge, pk_phhd, discharge_data) save_or_update_ie(ZxIeDischarge, pk_phhd, discharge_data)
def cost_task(pk_phhd, cost_list): def cost_task(pk_phhd, cost_list, identity):
cost_list_ie_result = information_extraction(COST_IE, cost_list) cost_list_ie_result = information_extraction(COST_IE, cost_list, identity)
cost_data = { cost_data = {
"pk_phhd": pk_phhd, "pk_phhd": pk_phhd,
"name": handle_name(get_best_value_in_keys(cost_list_ie_result, PATIENT_NAME)), "name": handle_name(get_best_value_in_keys(cost_list_ie_result, PATIENT_NAME)),
@@ -266,9 +284,11 @@ def photo_review(pk_phhd):
elif phrec.cRectype == "4": elif phrec.cRectype == "4":
cost_list.append(phrec) cost_list.append(phrec)
settlement_task(pk_phhd, settlement_list) # 同一批图的标识
discharge_task(pk_phhd, discharge_record) identity = int(time.time())
cost_task(pk_phhd, cost_list) settlement_task(pk_phhd, settlement_list, identity)
discharge_task(pk_phhd, discharge_record, identity)
cost_task(pk_phhd, cost_list, identity)
def main(): def main():