要保存和重新加载 Abbyy FineReader 的 OCR 结果,可以使用以下代码示例:
保存 OCR 结果:
import pytesseract
# 运行 OCR 并保存结果
def run_ocr_and_save(image_path, output_path):
result = pytesseract.image_to_string(image_path, lang='eng')
with open(output_path, 'w') as file:
file.write(result)
重新加载 OCR 结果:
# 加载保存的 OCR 结果
def load_ocr_result(file_path):
with open(file_path, 'r') as file:
result = file.read()
return result
使用示例:
# 运行 OCR 并保存结果
image_path = 'path/to/image.jpg'
output_path = 'path/to/ocr_result.txt'
run_ocr_and_save(image_path, output_path)
# 重新加载 OCR 结果
loaded_result = load_ocr_result(output_path)
print(loaded_result)
请注意,此示例使用 pytesseract 库进行 OCR,您需要先安装 pytesseract 并配置相关的 OCR 引擎。此外,您需要将 image_path
替换为您要进行 OCR 的图像路径,将 output_path
替换为您要保存 OCR 结果的文件路径。