Skip to main content
 首页 » 编程设计

python之在 python 中将图像转换为字符串后存档图像

2025年02月15日25mq0036

我正在为图像 ('test.jpg') 做 Tesseract-OCR。运行下面的代码 (OCR) 部分后,我将提取的字符串保存到 "OUTPUT.txt" 中。 现在我想存档图像 ("test.jpg") 你能帮帮我吗?

file='test.jpg' 
def ocr(file): 
    foo = Image.open(file) 
    print(foo.size) 
    foo = foo.resize((2000,3000),Image.ANTIALIAS) 
    pytes=pytesseract.image_to_string(foo) 
    with open("OUTPUT.txt","w") as file: 
            file.write(str(pytes)) 
    print(pytes) 
 
ocr(file) 

请您参考如下方法:

import os 
from shutil import copyfile 
 
archive_path = "path to your archive folder" 
if not os.path.exists(archive_path): 
    os.makedirs(arichive_path) 
 
copyfile("test.jpg", archive_path)