优化涂抹测试的图片显示
This commit is contained in:
@@ -3,8 +3,6 @@ import cv2
|
|||||||
from db import MysqlSession
|
from db import MysqlSession
|
||||||
from db.mysql import ZxIeOcrerror
|
from db.mysql import ZxIeOcrerror
|
||||||
from photo_mask_error_check import check_error
|
from photo_mask_error_check import check_error
|
||||||
from ucloud import ufile
|
|
||||||
from util import image_util
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
session = MysqlSession()
|
session = MysqlSession()
|
||||||
@@ -13,8 +11,5 @@ if __name__ == '__main__':
|
|||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
for ocr_error in ocr_errors:
|
for ocr_error in ocr_errors:
|
||||||
final_img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg100")
|
|
||||||
final_image = image_util.read(final_img_url)
|
|
||||||
cv2.imwrite(f"./mask_optimization_result/answer/{ocr_error.cfjaddress}.jpg", final_image)
|
|
||||||
image = check_error(ocr_error)
|
image = check_error(ocr_error)
|
||||||
cv2.imwrite(f"./mask_optimization_result/{ocr_error.cfjaddress}.jpg", image)
|
cv2.imwrite(f"./mask_optimization_result/{ocr_error.cfjaddress}.jpg", image)
|
||||||
@@ -17,7 +17,10 @@ def check_error(error_ocr):
|
|||||||
name = error_ocr.cXm
|
name = error_ocr.cXm
|
||||||
id_card_num = error_ocr.cSfzh
|
id_card_num = error_ocr.cSfzh
|
||||||
|
|
||||||
return mask_photo(img_url, name, id_card_num, (0, 0, 0))[1]
|
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)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -38,12 +41,8 @@ if __name__ == '__main__':
|
|||||||
# .filter(ZxIeOcrerror.pk_phrec == 0).one())
|
# .filter(ZxIeOcrerror.pk_phrec == 0).one())
|
||||||
# session.close()
|
# session.close()
|
||||||
|
|
||||||
final_img_url = ufile.get_private_url(ocr_error.cfjaddress, "drg100")
|
img = check_error(ocr_error)
|
||||||
final_image = image_util.read(final_img_url)
|
cv2.imwrite(f"./mask_error_check/{ocr_error.cfjaddress}.jpg", img)
|
||||||
cv2.imwrite(f"./mask_error_check/{ocr_error.cfjaddress}_final.jpg", final_image)
|
|
||||||
|
|
||||||
image = check_error(ocr_error)
|
|
||||||
cv2.imwrite(f"./mask_error_check/{ocr_error.cfjaddress}.jpg", image)
|
|
||||||
|
|
||||||
check_finish = input("是否完成(是/否):")
|
check_finish = input("是否完成(是/否):")
|
||||||
if check_finish == "是":
|
if check_finish == "是":
|
||||||
|
|||||||
@@ -203,3 +203,31 @@ def expand_to_a4_size(image, center=False):
|
|||||||
exp_img.fill(255)
|
exp_img.fill(255)
|
||||||
image = numpy.vstack([image, exp_img])
|
image = numpy.vstack([image, exp_img])
|
||||||
return image, offset_x, offset_y
|
return image, offset_x, offset_y
|
||||||
|
|
||||||
|
|
||||||
|
def combined(img1, img2):
|
||||||
|
# 获取两张图片的高度和宽度
|
||||||
|
height1, width1 = img1.shape[:2]
|
||||||
|
height2, width2 = img2.shape[:2]
|
||||||
|
|
||||||
|
# 确保两张图片的高度相同
|
||||||
|
if height1 != height2:
|
||||||
|
# 如果高度不同,调整较小高度的图片
|
||||||
|
if height1 < height2:
|
||||||
|
img1 = cv2.resize(img1, (int(width1 * height2 / height1), height2))
|
||||||
|
else:
|
||||||
|
img2 = cv2.resize(img2, (int(width2 * height1 / height2), height1))
|
||||||
|
|
||||||
|
# 再次获取调整后的图片尺寸
|
||||||
|
height1, width1 = img1.shape[:2]
|
||||||
|
height2, width2 = img2.shape[:2]
|
||||||
|
|
||||||
|
# 创建一个空白的图像,宽度等于两张图片的宽度之和,高度等于它们共同的高度
|
||||||
|
total_width = width1 + width2
|
||||||
|
max_height = max(height1, height2)
|
||||||
|
combined_img = numpy.zeros((max_height, total_width, 3), dtype=numpy.uint8)
|
||||||
|
|
||||||
|
# 将img1和img2复制到新的图像中
|
||||||
|
combined_img[:height1, :width1] = img1
|
||||||
|
combined_img[:height2, width1:width1 + width2] = img2
|
||||||
|
return combined_img
|
||||||
|
|||||||
Reference in New Issue
Block a user