Pyd
Pyd

Reputation: 6159

Archive the Images after conversion of Image to string in python

I am doing Tesseract-OCR for Image ('test.jpg'). After ran the below code (OCR) part i am saving the Extracted string into "OUTPUT.txt". Now i want to Archive the Image ("test.jpg") can you please help me?

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)

Upvotes: 2

Views: 89

Answers (1)

mohammad
mohammad

Reputation: 2208

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)

Upvotes: 1

Related Questions