From 84d106c7deb037ea33dc02523cf3b0090e85e615 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Thu, 17 Oct 2024 13:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8=E6=B6=82?= =?UTF-8?q?=E6=8A=B9=E7=9A=84=E5=9B=BE=E7=89=87=E5=88=A0=E9=99=A4=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask/auto_photo_mask.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/photo_mask/auto_photo_mask.py b/photo_mask/auto_photo_mask.py index 1af3eaa..e4d92c0 100644 --- a/photo_mask/auto_photo_mask.py +++ b/photo_mask/auto_photo_mask.py @@ -1,6 +1,9 @@ import logging.config +import os import re +import shutil import time +import uuid from time import sleep import cv2 @@ -10,6 +13,7 @@ from db import MysqlSession from db.mysql import ZxPhrec, ZxPhhd from log import HOSTNAME from photo_mask import PHHD_BATCH_SIZE, SLEEP_MINUTES, NAME_KEYS, ID_CARD_NUM_KEYS, SIMILAR_CHAR +from photo_review import set_batch_id from ucloud import BUCKET, ufile from util import image_util, common_util, model_util @@ -218,17 +222,23 @@ def photo_mask(pk_phhd, name, id_card_num): ZxPhrec.cRectype.in_(["3", "4"]) )).all() session.close() + # 同一批图的标识 + set_batch_id(uuid.uuid4().hex) + processed_img_dir = common_util.get_processed_img_path('') + os.makedirs(processed_img_dir, exist_ok=True) for phrec in phrecs: img_url = ufile.get_private_url(phrec.cfjaddress) if not img_url: continue - img_path = common_util.save_to_local(img_url) + original_img_path = common_util.save_to_local(img_url) + img_path = common_util.get_processed_img_path(phrec.cfjaddress) + shutil.copy2(original_img_path, img_path) is_masked, image = mask_photo(img_path, name, id_card_num) # 如果涂抹了要备份以及更新 if is_masked: - ufile.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress) try: + ufile.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress) ufile.upload_file(phrec.cfjaddress, image) session = MysqlSession() update_flag = (update(ZxPhrec).where(ZxPhrec.pk_phrec == phrec.pk_phrec).values( @@ -239,8 +249,10 @@ def photo_mask(pk_phhd, name, id_card_num): session.close() except Exception as e: logging.error("上传图片出错", exc_info=e) - finally: - common_util.delete_temp_file(image) + + # 删除多余图片 + if os.path.exists(processed_img_dir) and os.path.isdir(processed_img_dir): + shutil.rmtree(processed_img_dir) def main():