因pillow在linux中有问题难以解决,更换图片处理库为openCV

This commit is contained in:
2024-06-21 13:34:25 +08:00
parent b17104d7cb
commit 641964bda9
3 changed files with 36 additions and 32 deletions

View File

@@ -6,6 +6,8 @@ import tempfile
import time
from pprint import pprint
import cv2
from photo_review.photo_review import split_image
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -48,7 +50,7 @@ def visual_model_test(model_type, test_img, task_path, schema):
doc_parser = DocParser(layout_analysis=False)
for img in imgs:
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
img["img"].save(temp_file.name)
cv2.imwrite(temp_file.name, img["img"])
temp_files_paths.append(temp_file.name)
parsed_doc = doc_parser.parse({"doc": temp_file.name}, expand_to_a4_size=True)
if img["x_offset"] or img["y_offset"]:
@@ -67,7 +69,7 @@ def visual_model_test(model_type, test_img, task_path, schema):
temp_files_paths = []
for img in split_result:
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
img["img"].save(temp_file.name)
cv2.imwrite(temp_file.name, img["img"])
temp_files_paths.append(temp_file.name)
docs.append({"doc": temp_file.name})