调整项目结构,模块命名最好不要和包名相同,容易导致导包问题
This commit is contained in:
35
photo_mask/photo_mask_batch_error_check.py
Normal file
35
photo_mask/photo_mask_batch_error_check.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from datetime import date, timedelta
|
||||
|
||||
import cv2
|
||||
from sqlalchemy import and_
|
||||
|
||||
from db import MysqlSession
|
||||
from db.mysql import ZxIeOcrerror
|
||||
from photo_mask.photo_mask_error_check import check_error
|
||||
|
||||
if __name__ == '__main__':
|
||||
today = date.today()
|
||||
session = MysqlSession()
|
||||
# 对涂抹错误的进行测试比较
|
||||
ocr_errors = (session.query(ZxIeOcrerror.pk_phrec, ZxIeOcrerror.cXm, ZxIeOcrerror.cSfzh, ZxIeOcrerror.cfjaddress)
|
||||
.filter(and_(ZxIeOcrerror.checktime.is_(None),
|
||||
ZxIeOcrerror.creationtime >= today,
|
||||
ZxIeOcrerror.creationtime < today + timedelta(days=1)))
|
||||
.order_by(ZxIeOcrerror.pk_phrec.desc()).limit(50).all())
|
||||
|
||||
# 对已涂抹的进行测试比较
|
||||
# ocr_errors = (session.query(ZxPhrec.pk_phrec, ZxPhhd.cXm, ZxPhhd.cSfzh, ZxPhrec.cfjaddress)
|
||||
# .join(ZxPhrec, ZxPhhd.pk_phhd == ZxPhrec.pk_phhd, isouter=True)
|
||||
# .filter(ZxPhhd.paint_flag >= '8')
|
||||
# .order_by(ZxPhrec.pk_phrec.desc())
|
||||
# .limit(50).all())
|
||||
session.close()
|
||||
|
||||
for ocr_error in ocr_errors:
|
||||
try:
|
||||
image = check_error(ocr_error)
|
||||
if image is None:
|
||||
continue
|
||||
cv2.imwrite(f"./mask_optimization_result/{ocr_error.cfjaddress}.jpg", image)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
98
photo_mask/photo_mask_error_check.py
Normal file
98
photo_mask/photo_mask_error_check.py
Normal file
@@ -0,0 +1,98 @@
|
||||
import sys
|
||||
from datetime import date, timedelta
|
||||
|
||||
import cv2
|
||||
from sqlalchemy import update, and_, select, exists
|
||||
|
||||
from db import MysqlSession
|
||||
from db.mysql import ZxIeOcrerror, ZxPhrec
|
||||
from photo_mask.auto_photo_mask import mask_photo
|
||||
from ucloud import ufile
|
||||
from util import image_util, 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")
|
||||
if not img_url:
|
||||
raise Exception("云空间已删除")
|
||||
name = error_ocr.cXm
|
||||
id_card_num = error_ocr.cSfzh
|
||||
|
||||
image = mask_photo(img_url, name, id_card_num, (0, 0, 0))[1]
|
||||
final_img_url = ufile.get_private_url(error_ocr.cfjaddress, "drg100")
|
||||
final_image = image_util.read(final_img_url)
|
||||
return image_util.combined(final_image, image)
|
||||
|
||||
|
||||
def auto_check_error(error_ocr):
|
||||
if error_ocr.cfjaddress2:
|
||||
return error_ocr.cfjaddress2
|
||||
|
||||
cfjaddress = error_ocr.cfjaddress
|
||||
if cfjaddress[17] == "1":
|
||||
return "图片类型错误"
|
||||
|
||||
session = MysqlSession()
|
||||
cfjaddress = cfjaddress.rsplit(".", 1)[0] + ".%"
|
||||
query = select(exists().where(ZxPhrec.cfjaddress.like(cfjaddress)))
|
||||
record_exists = session.execute(query).scalar()
|
||||
session.close()
|
||||
if not record_exists:
|
||||
return "未同步"
|
||||
|
||||
return "未知错误"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 默认
|
||||
today = date.today()
|
||||
session = MysqlSession()
|
||||
ocr_error = (session.query(ZxIeOcrerror.pk_phrec, ZxIeOcrerror.cXm, ZxIeOcrerror.cSfzh, ZxIeOcrerror.cfjaddress,
|
||||
ZxIeOcrerror.cfjaddress2)
|
||||
.filter(and_(ZxIeOcrerror.checktime.is_(None),
|
||||
# ZxIeOcrerror.creationtime >= today,
|
||||
ZxIeOcrerror.creationtime < today + timedelta(days=1)))
|
||||
.limit(1).one())
|
||||
session.close()
|
||||
# 手动填充
|
||||
# ocr_error = ZxIeOcrerror()
|
||||
# ocr_error.pk_phrec = 0
|
||||
# ocr_error.cXm = ""
|
||||
# ocr_error.cSfzh = ""
|
||||
# ocr_error.cfjaddress = ""
|
||||
# ocr_error.cfjaddress2 = ""
|
||||
# 手动选择pk
|
||||
# session = MysqlSession()
|
||||
# ocr_error = (session.query(ZxIeOcrerror.pk_phrec, ZxIeOcrerror.cXm, ZxIeOcrerror.cSfzh, ZxIeOcrerror.cfjaddress,
|
||||
# ZxIeOcrerror.cfjaddress2)
|
||||
# .filter(ZxIeOcrerror.pk_phrec == 0).one())
|
||||
# session.close()
|
||||
|
||||
error_descript = auto_check_error(ocr_error)
|
||||
try:
|
||||
img = check_error(ocr_error)
|
||||
cv2.imwrite(f"./mask_error_check/{ocr_error.cfjaddress}.jpg", img)
|
||||
except Exception as e:
|
||||
error_descript = str(e)
|
||||
|
||||
if error_descript == "未知错误":
|
||||
while True:
|
||||
check_finish = input("是否完成(是/否):")
|
||||
if check_finish == "是":
|
||||
error_descript = input("错误描述:")
|
||||
break
|
||||
elif check_finish == "否":
|
||||
sys.exit()
|
||||
else:
|
||||
print("无效输入!请输入“是”或者“否”")
|
||||
|
||||
session = MysqlSession()
|
||||
update_error = (update(ZxIeOcrerror).where(ZxIeOcrerror.pk_phrec == ocr_error.pk_phrec).values(
|
||||
checktime=util.get_default_datetime(), cfjaddress2=error_descript))
|
||||
session.execute(update_error)
|
||||
session.commit()
|
||||
session.close()
|
||||
print(f"【{ocr_error.pk_phrec}】错误分析已完成。错误描述:{error_descript}")
|
||||
45
photo_mask/photo_mask_error_report.py
Normal file
45
photo_mask/photo_mask_error_report.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import json
|
||||
from collections import defaultdict
|
||||
from datetime import date, timedelta
|
||||
|
||||
from sqlalchemy import update, and_
|
||||
|
||||
from db import MysqlSession
|
||||
from db.mysql import ZxIeOcrerror
|
||||
from photo_mask.photo_mask_error_check import auto_check_error
|
||||
from util import util
|
||||
|
||||
if __name__ == '__main__':
|
||||
today = date.today()
|
||||
session = MysqlSession()
|
||||
ocr_errors = (session.query(ZxIeOcrerror.pk_phrec, ZxIeOcrerror.cXm, ZxIeOcrerror.cSfzh, ZxIeOcrerror.cfjaddress,
|
||||
ZxIeOcrerror.pk_phhd, ZxIeOcrerror.cfjaddress2)
|
||||
.filter(and_(ZxIeOcrerror.creationtime >= today,
|
||||
ZxIeOcrerror.creationtime < today + timedelta(days=1))).all())
|
||||
session.close()
|
||||
|
||||
result = defaultdict(int)
|
||||
result[f"{today}涂抹错误图片总数"] = len(ocr_errors)
|
||||
for ocr_error in ocr_errors:
|
||||
if ocr_error.cfjaddress2:
|
||||
result[ocr_error.cfjaddress2] += 1
|
||||
continue
|
||||
|
||||
error_descript = auto_check_error(ocr_error)
|
||||
if error_descript == "未知错误":
|
||||
check_time = None
|
||||
else:
|
||||
check_time = util.get_default_datetime()
|
||||
|
||||
session = MysqlSession()
|
||||
update_error = (update(ZxIeOcrerror).where(ZxIeOcrerror.pk_phrec == ocr_error.pk_phrec).values(
|
||||
checktime=check_time, cfjaddress2=error_descript))
|
||||
session.execute(update_error)
|
||||
session.commit()
|
||||
session.close()
|
||||
result[error_descript] += 1
|
||||
print(result)
|
||||
with open("photo_mask_error_report.txt", 'w', encoding='utf-8') as file:
|
||||
file.write(json.dumps(result, indent=4, ensure_ascii=False))
|
||||
file.write(util.get_default_datetime())
|
||||
print("结果已保存。")
|
||||
Reference in New Issue
Block a user