Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
too many files open
#1
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:
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Messages In This Thread
too many files open - by DPaul - Jul-16-2023, 12:45 PM
RE: too many files open - by DPaul - Jul-17-2023, 01:31 PM
RE: too many files open - by Larz60+ - Jul-17-2023, 03:04 PM
RE: too many files open - by DPaul - Jul-17-2023, 05:16 PM
RE: too many files open - by perfringo - Jul-18-2023, 05:53 AM
RE: too many files open - by DPaul - Jul-18-2023, 06:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The Open Open Open Source Project GareBearH 1 2,752 May-14-2021, 10:48 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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