i cant take output for every image in a separate .txt file pls write this code again with saving the text for every imag
-
- 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
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()