增加身份证号涂抹
This commit is contained in:
@@ -217,7 +217,7 @@ def find_box_of_content(content, layout):
|
||||
)
|
||||
|
||||
|
||||
def find_box_of_value(key, layout):
|
||||
def find_box_of_value(key, layout, length):
|
||||
full_box = layout[0]
|
||||
x_len = full_box[2] - full_box[0]
|
||||
y_len = full_box[3] - full_box[1]
|
||||
@@ -239,7 +239,7 @@ def find_box_of_value(key, layout):
|
||||
return (
|
||||
full_box[0] + (index + len(key)) * char_len,
|
||||
full_box[1],
|
||||
full_box[0] + (index + len(key) + 4) * char_len,
|
||||
full_box[0] + (index + len(key) + length) * char_len,
|
||||
full_box[3],
|
||||
)
|
||||
else:
|
||||
@@ -248,11 +248,11 @@ def find_box_of_value(key, layout):
|
||||
full_box[0],
|
||||
full_box[1] + (index + len(key)) * char_len,
|
||||
full_box[2],
|
||||
full_box[1] + (index + len(key) + 4) * char_len,
|
||||
full_box[1] + (index + len(key) + length) * char_len,
|
||||
)
|
||||
|
||||
|
||||
def get_mask_layout(image, content):
|
||||
def get_mask_layout(image, contents):
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
||||
cv2.imwrite(temp_file.name, image)
|
||||
|
||||
@@ -274,16 +274,19 @@ def get_mask_layout(image, content):
|
||||
else:
|
||||
# 涂抹
|
||||
for layout in layouts:
|
||||
for content in contents:
|
||||
if content in layout[1]:
|
||||
result.append(find_box_of_content(content, layout))
|
||||
if "姓名" in layout[1]:
|
||||
result.append(find_box_of_value("姓名", layout))
|
||||
result.append(find_box_of_value("姓名", layout, 4))
|
||||
if "交款人" in layout[1]:
|
||||
result.append(find_box_of_value("交款人", layout))
|
||||
result.append(find_box_of_value("交款人", layout, 4))
|
||||
if "文款人" in layout[1]:
|
||||
result.append(find_box_of_value("文款人", layout))
|
||||
result.append(find_box_of_value("文款人", layout, 4))
|
||||
if "购买方名称" in layout[1]:
|
||||
result.append(find_box_of_value("购买方名称", layout))
|
||||
result.append(find_box_of_value("购买方名称", layout, 4))
|
||||
if "身份证号" in layout[1]:
|
||||
result.append(find_box_of_value("身份证号", layout, 19))
|
||||
return result
|
||||
except Exception as e:
|
||||
logging.error("涂抹时出错", exc_info=e)
|
||||
@@ -294,7 +297,7 @@ def get_mask_layout(image, content):
|
||||
logging.info(f"删除临时文件 {temp_file.name} 时出错", exc_info=e)
|
||||
|
||||
|
||||
def photo_mask(pk_phhd, content):
|
||||
def photo_mask(pk_phhd, contents):
|
||||
session = MysqlSession()
|
||||
phrecs = session.query(ZxPhrec.pk_phrec, ZxPhrec.pk_phhd, ZxPhrec.cfjaddress) \
|
||||
.filter(ZxPhrec.pk_phhd == pk_phhd) \
|
||||
@@ -314,14 +317,14 @@ def photo_mask(pk_phhd, content):
|
||||
angles = get_image_rotation_angles(img["img"])
|
||||
angle = int(angles[0])
|
||||
rotated_img = rotate_image(img["img"], angle)
|
||||
results = get_mask_layout(rotated_img, content)
|
||||
results = get_mask_layout(rotated_img, contents)
|
||||
if not results:
|
||||
angle = int(angles[1])
|
||||
rotated_img = rotate_image(img["img"], angle)
|
||||
results = get_mask_layout(rotated_img, content)
|
||||
results = get_mask_layout(rotated_img, contents)
|
||||
if not results and "0" not in angles:
|
||||
angle = 0
|
||||
results = get_mask_layout(img["img"], content)
|
||||
results = get_mask_layout(img["img"], contents)
|
||||
|
||||
if results:
|
||||
is_masked = True
|
||||
@@ -367,7 +370,7 @@ if __name__ == '__main__':
|
||||
try:
|
||||
while 1:
|
||||
session = MysqlSession()
|
||||
phhds = session.query(ZxPhhd.pk_phhd, ZxPhhd.cXm).filter(
|
||||
phhds = session.query(ZxPhhd.pk_phhd, ZxPhhd.cXm, ZxPhhd.cSfzh).filter(
|
||||
ZxPhhd.paint_flag == "1"
|
||||
).limit(PHHD_BATCH_SIZE).all()
|
||||
# 将状态改为正在涂抹中
|
||||
@@ -380,7 +383,7 @@ if __name__ == '__main__':
|
||||
for phhd in phhds:
|
||||
pk_phhd = phhd.pk_phhd
|
||||
logging.info(f"开始涂抹:{pk_phhd}")
|
||||
photo_mask(pk_phhd, phhd.cXm)
|
||||
photo_mask(pk_phhd, [phhd.cXm, phhd.cSfzh])
|
||||
|
||||
# 识别完成更新标识
|
||||
session = MysqlSession()
|
||||
|
||||
Reference in New Issue
Block a user