fixed files overwriting each other

This commit is contained in:
Kabooshki 2024-04-30 09:30:27 -05:00
parent 9beebff9c6
commit be4808e0fe
2 changed files with 8 additions and 2 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -3,6 +3,7 @@ import pytesseract
import os import os
directory = 'images' directory = 'images'
k = 1
# iterate over files in # iterate over files in
# that directory # that directory
for filename in os.listdir(directory): for filename in os.listdir(directory):
@ -15,6 +16,11 @@ for filename in os.listdir(directory):
ROI1 = thresh[1383:1447,77:154] ROI1 = thresh[1383:1447,77:154]
ROI2 = thresh[1383:1447,950:1027] ROI2 = thresh[1383:1447,950:1027]
ROI = cv2.hconcat([ROI1, ROI2]) 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) print(data)
if os.path.isfile(f'images/{data}.jpg') == False:
os.rename(f'{f}', f'images/{data}.jpg') os.rename(f'{f}', f'images/{data}.jpg')
else:
os.rename(f'{f}', f'images/{data}.{k}.jpg')
k = k + 1
cv2.destroyAllWindows()