From be4808e0fea64c6b641dbd00640aafc16890cd0f Mon Sep 17 00:00:00 2001 From: Kabooshki Date: Tue, 30 Apr 2024 09:30:27 -0500 Subject: [PATCH] fixed files overwriting each other --- .DS_Store | Bin 6148 -> 6148 bytes main.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index d9a693e8267df8994eeb5376a4f39ec3e03a56e5..063ceb44d4efc837bbf87d7b0bcc8d850832a460 100644 GIT binary patch delta 20 bcmZoMXffDe&b--?`54Q@2CmKQ9Dn%%O7jN& delta 22 dcmZoMXffDe&dkWT*^&7e%ftrG&Fmb1`2kO`2L1p5 diff --git a/main.py b/main.py index 046a304..a38512d 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import pytesseract import os directory = 'images' +k = 1 # iterate over files in # that directory for filename in os.listdir(directory): @@ -15,6 +16,11 @@ for filename in os.listdir(directory): ROI1 = thresh[1383:1447,77:154] ROI2 = thresh[1383:1447,950:1027] ROI = cv2.hconcat([ROI1, ROI2]) - data = pytesseract.image_to_string(ROI, lang='eng',config='--psm 7 -c tessedit_char_whitelist=0123456789' ) + data = pytesseract.image_to_string(ROI, lang='eng',config='--psm 7 -c tessedit_char_whitelist=0123456789i' ) print(data) - os.rename(f'{f}', f'images/{data}.jpg') + if os.path.isfile(f'images/{data}.jpg') == False: + os.rename(f'{f}', f'images/{data}.jpg') + else: + os.rename(f'{f}', f'images/{data}.{k}.jpg') + k = k + 1 + cv2.destroyAllWindows()