只对涂抹的图片进行备份和更新

This commit is contained in:
2024-07-10 13:10:50 +08:00
parent 534bf4b4b9
commit 93f7b2a734

View File

@@ -230,12 +230,11 @@ def photo_mask(pk_phhd, content):
.all()
session.close()
for phrec in phrecs:
is_copy_success = ucloud.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
if not is_copy_success:
continue
img_url = ucloud.get_private_url(phrec.cfjaddress)
if not img_url:
continue
# 是否有涂抹
is_masked = False
# 打开图片
image = open_image(img_url)
split_result = split_image(image)
@@ -249,6 +248,9 @@ def photo_mask(pk_phhd, content):
rotated_img = rotate_image(img["img"], angle)
results = get_mask_layout(rotated_img, content)
if results:
is_masked = True
for result in results:
height, width = img["img"].shape[:2]
center = (width / 2, height / 2)
@@ -261,6 +263,14 @@ def photo_mask(pk_phhd, content):
)
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])),
(255, 255, 255), -1, 0)
# 如果涂抹了要备份以及更新
if is_masked:
for i in range(3):
is_copy_success = ucloud.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
if is_copy_success:
break
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
cv2.imwrite(temp_file.name, image)
cv2.imwrite(f"./mask_test2/{phrec.cfjaddress}.jpg", image)