2017-04-05 4 views

答えて

0

私は、テキストファイルに

def ocr(file_to_ocr): 
    im = Image.open(file_to_ocr) 
    txt=pytesseract.image_to_string(im) 
    return txt 

directory = os.path.join("Your_path") 
for root,dirs,files in os.walk(directory): 
for file in files: 
    if file.endswith(".jpg"): 
     pre_fix=file[:-4] 
     txt=ocr(file) 
     with open(directory+"\\"+pre_fix+".txt",'w') as f: f.write(str(txt)) 
をOCR出力を保存する簡単な方法を発見した
1

あなたはuuidを使用して独自のフォルダ名を作成し、そのようにそれにoutput.txtと書くことができる?:

from uuid import uuid4 
import os 

folder_name = str(uuid4()) 
os.makedirs(folder_name) 
with open('./{fn}/output.txt'.format(fn=folder_name),'wb') as f: 
    f.write(image_to_string(img1)) 
関連する問題