Reputation: 3046
I have found out how to make tesseract output the tif it uses for OCR. However, this tif is always called tessinput.tif
and if I have multiple documents in a folder, well, only the tessinput.tif
that was created last is shown. The same happens with a multilayer tif.
Is there a way to make tesseract output its input tif file for each document in a folder, e. g. by appending _1 to its name or something?
EDIT
Well, so far I have added the tessedit_write_images=1
config parameter. Which, lo and behold, outputs the tessinput.tif... but I cant figure out, if you can somehow change the name of that file
Upvotes: 0
Views: 1185
Reputation: 1001
I used Tesseract (4.0) to recognize multiple lines characters in a single image. Here I suggest a simplified approach to save all tessinput.tif files in an appropriate format, and double check output afterwards:
import os
import pytesseract
config = '-l eng --oem 3 --psm 7 --dpi 600 -c tessedit_write_images=true'
'''
in my use case, I extracted lines contours from the image, stored coordinates for
each line before reading the line with tesseract. Here I provide a simplified
solution with a list of 3 images, just for the example
'''
img = ['img1.png', 'img2.png', 'img3.png']
for i in range(len(image)):
pytesseract.image_to_string(img[i], config=config)
os.system('mv tessinput.tif tessinput_{:03d}.tif'.format(i))
Upvotes: 2
Reputation: 601
After it outputs the tessinput.tif, wait for the file to be written, then rename it and process the next image.
Upvotes: 2