Compare commits

...

6 Commits
main ... naming

4 changed files with 18 additions and 15 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ test.py
test-files.tbkpf
".DS_Store"
.DS_Store
compile*

View File

@ -1 +1,3 @@
THIS BRANCH IS OBSOLETE, IGNORE
a tool to look for page numbers in images and rename them accordingly

View File

@ -22,9 +22,9 @@ for files in os.listdir(directory):
cv2.imshow('Review', ROI)
cv2.waitKey(1)
manpage = input("please input the page number")
if os.path.isfile(f'images/{manpage}.jpg') == True:
if os.path.isfile(f'images/{manpage}-') == True:
rng = numpy.random.default_rng().random()
os.rename (f'images/{manpage}.jpg', f'images/{manpage}.review-{rng}.jpg')
os.rename(f'{f}', f'images/{manpage}.jpg')
elif os.path.isfile(f'images/{manpage}.jpg') == False:
os.rename(f'{f}', f'images/{manpage}.jpg')
os.rename (f'images/{manpage}-', f'images/{manpage}-.review-{rng}')
os.rename(f'{f}', f'images/{manpage}-')
elif os.path.isfile(f'images/{manpage}-') == False:
os.rename(f'{f}', f'images/{manpage}-')

20
main.py
View File

@ -18,23 +18,23 @@ for filename in os.listdir(directory):
ROI = cv2.hconcat([ROI1, ROI2])
data = pytesseract.image_to_string(ROI, lang='eng',config='--psm 7 -c tessedit_char_whitelist=0123456789i' )
print(data)
if os.path.isfile(f'images/{data}.jpg') == False:
os.rename(f'{f}', f'images/{data}.jpg')
elif os.path.isfile(f'images/{data}.jpg') == True:
if os.path.isfile(f'images/{data}-') == False:
os.rename(f'{f}', f'images/{data}-')
elif os.path.isfile(f'images/{data}-') == True:
cv2.imshow(data, ROI)
cv2.waitKey(1)
manpage = input("please input the number on the page (if the title is correct, enter nothing)")
#check if the new name already exists
if manpage == "\n":
rng = numpy.random.default_rng().random()
os.rename (f'images/{data}.jpg', f'images/{data}.review-{rng}.jpg')
os.rename(f'{f}', f'images/{data}.jpg')
os.rename (f'images/{data}-', f'images/{data}-.review-{rng}')
os.rename(f'{f}', f'images/{data}-')
elif manpage != "\n":
if os.path.isfile(f'images/{manpage}.jpg') == True:
if os.path.isfile(f'images/{manpage}-') == True:
rng = numpy.random.default_rng().random()
os.rename (f'images/{manpage}.jpg', f'images/{manpage}.review-{rng}.jpg')
os.rename(f'{f}', f'images/{manpage}.jpg')
elif os.path.isfile(f'images/{manpage}.jpg') == False:
os.rename(f'{f}', f'images/{manpage}.jpg')
os.rename (f'images/{manpage}-', f'images/{manpage}-.review-{rng}')
os.rename(f'{f}', f'images/{manpage}-')
elif os.path.isfile(f'images/{manpage}-') == False:
os.rename(f'{f}', f'images/{manpage}-')
cv2.destroyAllWindows()
cv2.destroyAllWindows()