2017-04-05 4 views

답변

0

나는 텍스트 파일로 OCR 출력을 저장하는 쉬운 방법을 발견

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)) 
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)) 
관련 문제