Jul-16-2023, 12:45 PM
Hi,
I was given a large number of prayer cards, already scanned, ready for OCR, as usual.
Only this time the formats are different, imagine single cards, double (folded) cards and folded cards (recto & verso).
You cannot OCR them like that, you need to crop them (= cut them up) into 2 or 4 pieces, save those crops, and OCR those.
Works well,on a limited number, but with large numbers, i get:
Done, next image. Somehow it keeps file pointers open.
This is what the function looks like:
thx,
Paul
I was given a large number of prayer cards, already scanned, ready for OCR, as usual.
Only this time the formats are different, imagine single cards, double (folded) cards and folded cards (recto & verso).
You cannot OCR them like that, you need to crop them (= cut them up) into 2 or 4 pieces, save those crops, and OCR those.
Works well,on a limited number, but with large numbers, i get:
Output:Traceback (most recent call last):
File "C:\VVF\BP\BP-OCR-V5.py", line 236, in <module>
do_crop()
File "C:\VVF\BP\BP-OCR-V5.py", line 227, in do_crop
crop.save(dst)
File "C:\Users\Paul\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 2300, in save
save_handler(self, fp, filename)
File "C:\Users\Paul\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\TiffImagePlugin.py", line 1731, in _save
_fp = os.dup(fp.fileno())
OSError: [Errno 24] Too many open files
I've tried things unsuccessfully, the basic question is: I have an image, I crop it (in memory) into x parts, I save these parts to disk.Done, next image. Somehow it keeps file pointers open.
This is what the function looks like:
for BP in glob.glob(mappath + '\*.*'): img = Image.open(BP) w, h = img.size if w < 750: crops = crop_image(img) for idx,crop in enumerate(crops): dst = os.path.join(os.curdir,'data','scans-cropped',fil) # remark: filename is modified to make them all different crop.save(dst) crop.close()How can I save a few 100.000 like this ?
thx,
Paul