只对涂抹的图片进行备份和更新
This commit is contained in:
@@ -230,12 +230,11 @@ def photo_mask(pk_phhd, content):
|
|||||||
.all()
|
.all()
|
||||||
session.close()
|
session.close()
|
||||||
for phrec in phrecs:
|
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)
|
img_url = ucloud.get_private_url(phrec.cfjaddress)
|
||||||
if not img_url:
|
if not img_url:
|
||||||
continue
|
continue
|
||||||
|
# 是否有涂抹
|
||||||
|
is_masked = False
|
||||||
# 打开图片
|
# 打开图片
|
||||||
image = open_image(img_url)
|
image = open_image(img_url)
|
||||||
split_result = split_image(image)
|
split_result = split_image(image)
|
||||||
@@ -249,6 +248,9 @@ def photo_mask(pk_phhd, content):
|
|||||||
rotated_img = rotate_image(img["img"], angle)
|
rotated_img = rotate_image(img["img"], angle)
|
||||||
results = get_mask_layout(rotated_img, content)
|
results = get_mask_layout(rotated_img, content)
|
||||||
|
|
||||||
|
if results:
|
||||||
|
is_masked = True
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
height, width = img["img"].shape[:2]
|
height, width = img["img"].shape[:2]
|
||||||
center = (width / 2, height / 2)
|
center = (width / 2, height / 2)
|
||||||
@@ -261,21 +263,29 @@ def photo_mask(pk_phhd, content):
|
|||||||
)
|
)
|
||||||
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])),
|
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])),
|
||||||
(255, 255, 255), -1, 0)
|
(255, 255, 255), -1, 0)
|
||||||
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)
|
if is_masked:
|
||||||
try:
|
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
is_upload_success = ucloud.upload_file(phrec.cfjaddress, temp_file.name)
|
is_copy_success = ucloud.copy_file(BUCKET, phrec.cfjaddress, "drg2015", phrec.cfjaddress)
|
||||||
if is_upload_success:
|
if is_copy_success:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
|
||||||
logging.error("上传图片出错", exc_info=e)
|
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
||||||
finally:
|
cv2.imwrite(temp_file.name, image)
|
||||||
|
cv2.imwrite(f"./mask_test2/{phrec.cfjaddress}.jpg", image)
|
||||||
try:
|
try:
|
||||||
os.remove(temp_file.name)
|
for i in range(3):
|
||||||
|
is_upload_success = ucloud.upload_file(phrec.cfjaddress, temp_file.name)
|
||||||
|
if is_upload_success:
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info(f"删除临时文件 {temp_file.name} 时出错", exc_info=e)
|
logging.error("上传图片出错", exc_info=e)
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
os.remove(temp_file.name)
|
||||||
|
except Exception as e:
|
||||||
|
logging.info(f"删除临时文件 {temp_file.name} 时出错", exc_info=e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user