Python Forum
how to extract tiff images from the subfolder into. hocr format in another similar su
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to extract tiff images from the subfolder into. hocr format in another similar su
#1
HI,
I am working on a project to OCR text from tiff images, the below code works fine on individual images, but I am looking for a solution where I can extract the batch images from respective subfolders and OCR in .HOCR format.

Example :

There are several subfolders in the D drive with Tiff image, which needs to pass through OCR one by one and output in E drive with the similar DIR tree as the D drive.
D:\\subfolder\Subfolder1\tiff image to E:\subfolder\Subfolder1\Hocr image
Please suggest how to tweak the code to achieve the requirement

My code
from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract- OCR\tesseract.exe"

image = Image.open(r"C:\Users\multipage.tiff")

config = ("--oem 3 --psm 6")

txt = ''
for frame in range(image.n_frames):
    image.seek(frame)
    txt += pytesseract.image_to_string(image, config = config, lang='eng') + '\n'

print(txt)
with open(r"C:\Users\multipage_output.txt", mode = 'w') as f:
    f.write(txt)
Thanks!
Joe
buran write Feb-17-2022, 08:38 AM:
Please, use python tags, not inline
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 568 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  OCR-Python from Multi TIFF to HOCR getting only Data from 1st Page of multiple TIFF JOE 0 2,169 Feb-18-2022, 03:18 PM
Last Post: JOE
  Compressed multi page tiff wvanoeveren 2 2,676 Dec-28-2021, 11:40 AM
Last Post: Gribouillis
Photo Moving 2 photos from each subfolder to another folder Blacklonewolf 1 2,059 Oct-28-2021, 04:07 PM
Last Post: DeaD_EyE
  How to open/load image .tiff files > 2 GB ? hobbyist 1 2,472 Aug-19-2021, 12:50 AM
Last Post: Larz60+
  Sum similar items tester_V 3 1,986 Jun-29-2021, 06:58 AM
Last Post: tester_V
  Created zipfile without all the subfolder? korenron 3 3,789 Jun-23-2021, 12:44 PM
Last Post: korenron
  Unable to capture all images of a multipage TIFF file in a merge bendersbender 0 2,222 Nov-19-2020, 03:09 PM
Last Post: bendersbender
  Converting PNG to TIFF (pillow?) gw1500se 4 5,529 Mar-25-2020, 06:29 PM
Last Post: gw1500se
  Python: if 'X' in 'Y' but with two similar strings as 'X' DreamingInsanity 6 3,880 Feb-01-2019, 01:28 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020