优化命名,类与模块最好不要重名
This commit is contained in:
@@ -12,7 +12,7 @@ from db.mysql import ZxPhrec, ZxPhhd
|
||||
from log import HOSTNAME
|
||||
from photo_mask import OCR, PHHD_BATCH_SIZE, SLEEP_MINUTES, NAME_KEYS, ID_CARD_NUM_KEYS, SIMILAR_CHAR
|
||||
from ucloud import BUCKET, ufile
|
||||
from util import image_util, util
|
||||
from util import image_util, common_util
|
||||
|
||||
|
||||
def find_boxes(content, layout, offset=0, length=None, improve=False, image_path=None, extra_content=None):
|
||||
@@ -56,13 +56,13 @@ def find_boxes(content, layout, offset=0, length=None, improve=False, image_path
|
||||
# 再次识别,提高精度
|
||||
image = cv2.imread(image_path)
|
||||
# 截图时偏大一点
|
||||
capture_box = util.zoom_rectangle(box, 0.2)
|
||||
capture_box = common_util.zoom_rectangle(box, 0.2)
|
||||
captured_image = image_util.capture(image, capture_box)
|
||||
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
|
||||
captured_image, offset_x, offset_y = image_util.expand_to_a4_size(captured_image)
|
||||
cv2.imwrite(temp_file.name, captured_image)
|
||||
try:
|
||||
layouts = util.get_ocr_layout(OCR, temp_file.name)
|
||||
layouts = common_util.get_ocr_layout(OCR, temp_file.name)
|
||||
except TypeError:
|
||||
# 如果是类型错误,大概率是没识别到文字
|
||||
layouts = []
|
||||
@@ -86,7 +86,7 @@ def find_boxes(content, layout, offset=0, length=None, improve=False, image_path
|
||||
temp_box[3] + capture_box[1] - offset_y,
|
||||
])
|
||||
break
|
||||
util.delete_temp_file(temp_file.name)
|
||||
common_util.delete_temp_file(temp_file.name)
|
||||
|
||||
if not boxes:
|
||||
boxes.append(box)
|
||||
@@ -100,7 +100,7 @@ def get_mask_layout(image, name, id_card_num):
|
||||
result = []
|
||||
try:
|
||||
try:
|
||||
layouts = util.get_ocr_layout(OCR, temp_file.name)
|
||||
layouts = common_util.get_ocr_layout(OCR, temp_file.name)
|
||||
# layouts = OCR.parse({"doc": temp_file.name})["layout"]
|
||||
except TypeError:
|
||||
# 如果是类型错误,大概率是没识别到文字
|
||||
@@ -164,7 +164,7 @@ def get_mask_layout(image, name, id_card_num):
|
||||
logging.error("涂抹时出错!", exc_info=e)
|
||||
return result
|
||||
finally:
|
||||
util.delete_temp_file(temp_file.name)
|
||||
common_util.delete_temp_file(temp_file.name)
|
||||
|
||||
|
||||
def handle_image_for_mask(split_result):
|
||||
@@ -241,14 +241,14 @@ def photo_mask(pk_phhd, name, id_card_num):
|
||||
session = MysqlSession()
|
||||
update_flag = (update(ZxPhrec).where(ZxPhrec.pk_phrec == phrec.pk_phrec).values(
|
||||
paint_user=HOSTNAME,
|
||||
paint_date=util.get_default_datetime()))
|
||||
paint_date=common_util.get_default_datetime()))
|
||||
session.execute(update_flag)
|
||||
session.commit()
|
||||
session.close()
|
||||
except Exception as e:
|
||||
logging.error("上传图片出错", exc_info=e)
|
||||
finally:
|
||||
util.delete_temp_file(temp_file.name)
|
||||
common_util.delete_temp_file(temp_file.name)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -278,7 +278,7 @@ def main():
|
||||
update_flag = (update(ZxPhhd).where(ZxPhhd.pk_phhd == pk_phhd).values(
|
||||
paint_flag="8",
|
||||
paint_user=HOSTNAME,
|
||||
paint_date=util.get_default_datetime(),
|
||||
paint_date=common_util.get_default_datetime(),
|
||||
fZcfwfy=time.time() - start_time))
|
||||
session.execute(update_flag)
|
||||
session.commit()
|
||||
|
||||
@@ -8,7 +8,7 @@ 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
|
||||
from util import image_util, common_util
|
||||
|
||||
|
||||
def check_error(error_ocr):
|
||||
@@ -91,7 +91,7 @@ if __name__ == '__main__':
|
||||
|
||||
session = MysqlSession()
|
||||
update_error = (update(ZxIeOcrerror).where(ZxIeOcrerror.pk_phrec == ocr_error.pk_phrec).values(
|
||||
checktime=util.get_default_datetime(), cfjaddress2=error_descript))
|
||||
checktime=common_util.get_default_datetime(), cfjaddress2=error_descript))
|
||||
session.execute(update_error)
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
@@ -7,7 +7,7 @@ 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
|
||||
from util import common_util
|
||||
|
||||
if __name__ == '__main__':
|
||||
today = date.today()
|
||||
@@ -29,7 +29,7 @@ if __name__ == '__main__':
|
||||
if error_descript == "未知错误":
|
||||
check_time = None
|
||||
else:
|
||||
check_time = util.get_default_datetime()
|
||||
check_time = common_util.get_default_datetime()
|
||||
|
||||
session = MysqlSession()
|
||||
update_error = (update(ZxIeOcrerror).where(ZxIeOcrerror.pk_phrec == ocr_error.pk_phrec).values(
|
||||
@@ -41,5 +41,5 @@ if __name__ == '__main__':
|
||||
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())
|
||||
file.write(common_util.get_default_datetime())
|
||||
print("结果已保存。")
|
||||
|
||||
Reference in New Issue
Block a user