优化自动涂抹的图片删除逻辑
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import logging.config
|
import logging.config
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@@ -10,6 +13,7 @@ from db import MysqlSession
|
|||||||
from db.mysql import ZxPhrec, ZxPhhd
|
from db.mysql import ZxPhrec, ZxPhhd
|
||||||
from log import HOSTNAME
|
from log import HOSTNAME
|
||||||
from photo_mask import PHHD_BATCH_SIZE, SLEEP_MINUTES, NAME_KEYS, ID_CARD_NUM_KEYS, SIMILAR_CHAR
|
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 ucloud import BUCKET, ufile
|
||||||
from util import image_util, common_util, model_util
|
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"])
|
ZxPhrec.cRectype.in_(["3", "4"])
|
||||||
)).all()
|
)).all()
|
||||||
session.close()
|
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:
|
for phrec in phrecs:
|
||||||
img_url = ufile.get_private_url(phrec.cfjaddress)
|
img_url = ufile.get_private_url(phrec.cfjaddress)
|
||||||
if not img_url:
|
if not img_url:
|
||||||
continue
|
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)
|
is_masked, image = mask_photo(img_path, name, id_card_num)
|
||||||
|
|
||||||
# 如果涂抹了要备份以及更新
|
# 如果涂抹了要备份以及更新
|
||||||
if is_masked:
|
if is_masked:
|
||||||
ufile.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
|
|
||||||
try:
|
try:
|
||||||
|
ufile.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
|
||||||
ufile.upload_file(phrec.cfjaddress, image)
|
ufile.upload_file(phrec.cfjaddress, image)
|
||||||
session = MysqlSession()
|
session = MysqlSession()
|
||||||
update_flag = (update(ZxPhrec).where(ZxPhrec.pk_phrec == phrec.pk_phrec).values(
|
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()
|
session.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("上传图片出错", exc_info=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():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user