提高代码复用
This commit is contained in:
@@ -141,18 +141,8 @@ def handle_image_for_mask(split_result):
|
|||||||
return expand_img, split_result["x_offset"], split_result["y_offset"]
|
return expand_img, split_result["x_offset"], split_result["y_offset"]
|
||||||
|
|
||||||
|
|
||||||
def photo_mask(pk_phhd, name, id_card_num):
|
def mask_photo(img_url, name, id_card_num, color=(255, 255, 255)):
|
||||||
session = MysqlSession()
|
# 是否涂抹了
|
||||||
phrecs = session.query(ZxPhrec.cfjaddress).filter(and_(
|
|
||||||
ZxPhrec.pk_phhd == pk_phhd,
|
|
||||||
ZxPhrec.cRectype.in_(["3", "4"])
|
|
||||||
)).all()
|
|
||||||
session.close()
|
|
||||||
for phrec in phrecs:
|
|
||||||
img_url = ufile.get_private_url(phrec.cfjaddress)
|
|
||||||
if not img_url:
|
|
||||||
continue
|
|
||||||
# 是否有涂抹
|
|
||||||
is_masked = False
|
is_masked = False
|
||||||
# 打开图片
|
# 打开图片
|
||||||
image = image_util.read(img_url)
|
image = image_util.read(img_url)
|
||||||
@@ -171,8 +161,23 @@ def photo_mask(pk_phhd, name, id_card_num):
|
|||||||
result[2] + x_offset,
|
result[2] + x_offset,
|
||||||
result[3] + y_offset,
|
result[3] + y_offset,
|
||||||
)
|
)
|
||||||
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])),
|
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])), color, -1, 0)
|
||||||
(255, 255, 255), -1, 0)
|
return is_masked, image
|
||||||
|
|
||||||
|
|
||||||
|
def photo_mask(pk_phhd, name, id_card_num):
|
||||||
|
session = MysqlSession()
|
||||||
|
phrecs = session.query(ZxPhrec.cfjaddress).filter(and_(
|
||||||
|
ZxPhrec.pk_phhd == pk_phhd,
|
||||||
|
ZxPhrec.cRectype.in_(["3", "4"])
|
||||||
|
)).all()
|
||||||
|
session.close()
|
||||||
|
for phrec in phrecs:
|
||||||
|
img_url = ufile.get_private_url(phrec.cfjaddress)
|
||||||
|
if not img_url:
|
||||||
|
continue
|
||||||
|
|
||||||
|
is_masked, image = mask_photo(img_url, name, id_card_num)
|
||||||
|
|
||||||
# 如果涂抹了要备份以及更新
|
# 如果涂抹了要备份以及更新
|
||||||
if is_masked:
|
if is_masked:
|
||||||
|
|||||||
44
photo_mask_error_check.py
Normal file
44
photo_mask_error_check.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import cv2
|
||||||
|
from sqlalchemy import update
|
||||||
|
|
||||||
|
import util.util
|
||||||
|
from db import MysqlSession
|
||||||
|
from db.mysql import ZxIeOcrerror
|
||||||
|
from photo_mask.photo_mask import mask_photo
|
||||||
|
from ucloud import ufile
|
||||||
|
from util import image_util
|
||||||
|
|
||||||
|
|
||||||
|
def check_error(error_ocr):
|
||||||
|
img_url = ufile.get_private_url(error_ocr.cfjaddress, "drg2015")
|
||||||
|
if not img_url:
|
||||||
|
# 没有自动涂抹的图片
|
||||||
|
img_url = ufile.get_private_url(error_ocr.cfjaddress, "drg103")
|
||||||
|
name = error_ocr.cXm
|
||||||
|
id_card_num = error_ocr.cSfzh
|
||||||
|
|
||||||
|
return mask_photo(img_url, name, id_card_num, (0, 0, 0))[1]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
session = MysqlSession()
|
||||||
|
ocr_error = (session.query(ZxIeOcrerror.pk_phrec, ZxIeOcrerror.cXm, ZxIeOcrerror.cSfzh, ZxIeOcrerror.cfjaddress)
|
||||||
|
.filter(ZxIeOcrerror.checktime.is_(None)).order_by(ZxIeOcrerror.pk_phrec.desc()).limit(1).one())
|
||||||
|
session.close()
|
||||||
|
|
||||||
|
final_img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg100")
|
||||||
|
final_image = image_util.read(final_img_url)
|
||||||
|
cv2.imwrite(f"./mask_error_check/{ocr_error.cfjaddress}_final.jpg", final_image)
|
||||||
|
|
||||||
|
image = check_error(ocr_error)
|
||||||
|
cv2.imwrite(f"./mask_error_check/{ocr_error.cfjaddress}.jpg", image)
|
||||||
|
|
||||||
|
check_finish = input("是否完成(是/否):")
|
||||||
|
if check_finish == "是":
|
||||||
|
remarks = input("备注:")
|
||||||
|
session = MysqlSession()
|
||||||
|
update_flag = (update(ZxIeOcrerror).where(ZxIeOcrerror.pk_phrec == ocr_error.pk_phrec).values(
|
||||||
|
checktime=util.util.get_default_datetime(), cfjaddress2=remarks))
|
||||||
|
session.execute(update_flag)
|
||||||
|
session.commit()
|
||||||
|
session.close()
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
from paddlenlp import Taskflow
|
from paddlenlp import Taskflow
|
||||||
from paddleocr import PaddleOCR
|
from paddleocr import PaddleOCR
|
||||||
|
|
||||||
|
# 主机名
|
||||||
|
HOSTNAME = socket.gethostname()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
项目配置
|
项目配置
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from db.mysql import BdYljg, BdYlks, ZxOcr, ZxIeCost, ZxIeDischarge, ZxIeSettlem
|
|||||||
from photo_review import PATIENT_NAME, ADMISSION_DATE, DISCHARGE_DATE, MEDICAL_EXPENSES, PERSONAL_CASH_PAYMENT, \
|
from photo_review import PATIENT_NAME, ADMISSION_DATE, DISCHARGE_DATE, MEDICAL_EXPENSES, PERSONAL_CASH_PAYMENT, \
|
||||||
PERSONAL_ACCOUNT_PAYMENT, PERSONAL_FUNDED_AMOUNT, MEDICAL_INSURANCE_TYPE, HOSPITAL, DEPARTMENT, DOCTOR, \
|
PERSONAL_ACCOUNT_PAYMENT, PERSONAL_FUNDED_AMOUNT, MEDICAL_INSURANCE_TYPE, HOSPITAL, DEPARTMENT, DOCTOR, \
|
||||||
ADMISSION_ID, SETTLEMENT_ID, AGE, OCR, SETTLEMENT_IE, DISCHARGE_IE, COST_IE, PHHD_BATCH_SIZE, SLEEP_MINUTES, \
|
ADMISSION_ID, SETTLEMENT_ID, AGE, OCR, SETTLEMENT_IE, DISCHARGE_IE, COST_IE, PHHD_BATCH_SIZE, SLEEP_MINUTES, \
|
||||||
UPPERCASE_MEDICAL_EXPENSES
|
UPPERCASE_MEDICAL_EXPENSES, HOSTNAME
|
||||||
from ucloud import ufile
|
from ucloud import ufile
|
||||||
from util import image_util, util
|
from util import image_util, util
|
||||||
from util.data_util import handle_date, handle_decimal, parse_department, handle_name, \
|
from util.data_util import handle_date, handle_decimal, parse_department, handle_name, \
|
||||||
@@ -95,7 +95,7 @@ def information_extraction(ie, phrecs):
|
|||||||
zx_ocr = ZxOcr(pk_phhd=phrec.pk_phhd, pk_phrec=phrec.pk_phrec, id=identity, cfjaddress=phrec.cfjaddress,
|
zx_ocr = ZxOcr(pk_phhd=phrec.pk_phhd, pk_phrec=phrec.pk_phrec, id=identity, cfjaddress=phrec.cfjaddress,
|
||||||
content=result_json, rotation_angle=ie_result["angle"],
|
content=result_json, rotation_angle=ie_result["angle"],
|
||||||
x_offset=split_result["x_offset"], y_offset=split_result["y_offset"], create_time=now,
|
x_offset=split_result["x_offset"], y_offset=split_result["y_offset"], create_time=now,
|
||||||
update_time=now)
|
creator=HOSTNAME, update_time=now, updater=HOSTNAME)
|
||||||
session.add(zx_ocr)
|
session.add(zx_ocr)
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
@@ -146,12 +146,15 @@ def save_or_update_ie(table, pk_phhd, data):
|
|||||||
if db_data:
|
if db_data:
|
||||||
# 更新
|
# 更新
|
||||||
db_data.update_time = now
|
db_data.update_time = now
|
||||||
|
db_data.creator = HOSTNAME
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
setattr(db_data, k, v)
|
setattr(db_data, k, v)
|
||||||
else:
|
else:
|
||||||
# 新增
|
# 新增
|
||||||
obj.create_time = now
|
obj.create_time = now
|
||||||
|
obj.creator = HOSTNAME
|
||||||
obj.update_time = now
|
obj.update_time = now
|
||||||
|
obj.updater = HOSTNAME
|
||||||
session.add(obj)
|
session.add(obj)
|
||||||
session.commit()
|
session.commit()
|
||||||
session.close()
|
session.close()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import cv2
|
|||||||
|
|
||||||
from db import MysqlSession
|
from db import MysqlSession
|
||||||
from db.mysql import ZxIeOcrerror
|
from db.mysql import ZxIeOcrerror
|
||||||
from photo_mask.photo_mask import handle_image_for_mask, get_mask_layout
|
from photo_mask_error_check import check_error
|
||||||
from ucloud import ufile
|
from ucloud import ufile
|
||||||
from util import image_util
|
from util import image_util
|
||||||
|
|
||||||
@@ -16,30 +16,5 @@ if __name__ == '__main__':
|
|||||||
final_img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg100")
|
final_img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg100")
|
||||||
final_image = image_util.read(final_img_url)
|
final_image = image_util.read(final_img_url)
|
||||||
cv2.imwrite(f"./mask_optimization_result/answer/{ocr_error.cfjaddress}.jpg", final_image)
|
cv2.imwrite(f"./mask_optimization_result/answer/{ocr_error.cfjaddress}.jpg", final_image)
|
||||||
img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg2015")
|
image = check_error(ocr_error)
|
||||||
if not img_url:
|
|
||||||
# 没有自动涂抹的图片
|
|
||||||
img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg103")
|
|
||||||
name = ocr_error.cXm
|
|
||||||
id_card_num = ocr_error.cSfzh
|
|
||||||
|
|
||||||
image = image_util.read(img_url)
|
|
||||||
# image = image_util.rotate(image, 90)
|
|
||||||
split_results = image_util.split(image)
|
|
||||||
for split_result in split_results:
|
|
||||||
to_mask_img, x_offset, y_offset = handle_image_for_mask(split_result)
|
|
||||||
results = get_mask_layout(to_mask_img, name, id_card_num)
|
|
||||||
|
|
||||||
if results:
|
|
||||||
is_masked = True
|
|
||||||
|
|
||||||
for result in results:
|
|
||||||
result = (
|
|
||||||
result[0] + x_offset,
|
|
||||||
result[1] + y_offset,
|
|
||||||
result[2] + x_offset,
|
|
||||||
result[3] + y_offset,
|
|
||||||
)
|
|
||||||
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])),
|
|
||||||
(0, 0, 0), -1, 0)
|
|
||||||
cv2.imwrite(f"./mask_optimization_result/{ocr_error.cfjaddress}.jpg", image)
|
cv2.imwrite(f"./mask_optimization_result/{ocr_error.cfjaddress}.jpg", image)
|
||||||
|
|||||||
Reference in New Issue
Block a user