i cant take output for every image in a separate .txt file pls write this code again with saving the text for every imag

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

i cant take output for every image in a separate .txt file pls write this code again with saving the text for every imag

Post by answerhappygod »

i cant take output for every image in a separate .txt filepls write this code again with saving the text for every image in a separate .txt file from PIL import Imageimport pytesseractimport ospytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'def main(): path = "Desktop/Python/Image" Outputpath = "Desktop/Python/Txt" Extracted_text = "" for imageName in os.listdir(path): inputPath = os.path.join(path,imageName) if(inputPath.endswith(".png")): img = Image.open(inputPath) txt = pytesseract.image_to_string(img, lang='eng') print(txt) Extracted_text += txt FullTempPath = os.path.join(Outputpath,imageName+".txt") sample = open(FullTempPath,"w") sample.write(Extracted_text) sample.close() if __name__== "__main__": main()
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply