2024-09-18 16:02:38 +00:00
|
|
|
import cv2
|
|
|
|
import pytesseract
|
|
|
|
import os
|
|
|
|
import numpy
|
|
|
|
directory = 'images'
|
|
|
|
|
|
|
|
# iterate over files in
|
|
|
|
# that directory
|
|
|
|
pattern = 'review' # Replace with your target substring
|
|
|
|
matching_files = [f for f in os.listdir(directory) if pattern in f]
|
|
|
|
|
|
|
|
for files in os.listdir(directory):
|
|
|
|
if files.__contains__(pattern):
|
|
|
|
f = os.path.join(directory, files)
|
|
|
|
print(f)
|
|
|
|
image = cv2.imread(f, 0)
|
|
|
|
thresh = 255 - cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
|
|
|
|
#bottom 2 locations
|
|
|
|
ROI1 = thresh[1383:1447,77:154]
|
|
|
|
ROI2 = thresh[1383:1447,950:1027]
|
|
|
|
ROI = cv2.hconcat([ROI1, ROI2])
|
|
|
|
cv2.imshow('Review', ROI)
|
|
|
|
cv2.waitKey(1)
|
|
|
|
manpage = input("please input the page number")
|
2024-09-18 17:22:33 +00:00
|
|
|
if os.path.isfile(f'images/{manpage}') == True:
|
2024-09-18 16:02:38 +00:00
|
|
|
rng = numpy.random.default_rng().random()
|
2024-09-18 17:22:33 +00:00
|
|
|
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}')
|