批量处理时加入 try catch

This commit is contained in:
William Jin 2024-10-13 21:13:55 +08:00
parent 4645c39bfb
commit dcba129694

View File

@ -237,9 +237,12 @@ def ocr_image(image):
def batch_ocr(files):
results = []
for file in files:
image = Image.open(file)
ocr_result = ocr_image(image)
results.append(f"\n\n{ocr_result}\n\n")
try:
image = Image.open(file)
ocr_result = ocr_image(image)
results.append(f"\n\n{ocr_result}\n\n")
except Exception as e:
print(e)
# 将结果写入 Markdown 文件
output_file = "ocr_results.txt"