Skip to content
Permalink
Browse files

Fixed a crash when attempting to fix the OCR error of a l in the front

of a string
Added support for PNG screenshots
  • Loading branch information...
BradfordBach committed May 25, 2019
1 parent 8156dbc commit b956d62eb6b8233fdb219d9f6594b41e22f450df
Showing with 6 additions and 3 deletions.
  1. +1 −1 NMS_Locator.py
  2. +3 −1 ocr.py
  3. +2 −1 screenshot_crop.py
@@ -58,7 +58,7 @@ def get_latest_screenshot():
for (dirpath, dirnames, filenames) in os.walk(config.get('SETTINGS', 'SCREENSHOT_DIRECTORY')):
dirnames[:] = [d for d in dirnames if d not in exclude]
for file in filenames:
if file[-4:] == ".jpg":
if file[-4:] == ".jpg" or file[-4:] == '.png':
all_screenshot_files.append(os.path.join(dirpath, file))

try:
4 ocr.py
@@ -72,7 +72,9 @@ def fix_common_ocr_issues(text):
if '|' in text:
text = text.replace('|', 'I')
if text[:1] == 'l':
text[:1] = 'I'
text = list(text)
text[0] = 'I'
text = ''.join(text)
if ' l ' in text:
text = text.replace(' l ', ' I ')

@@ -33,6 +33,8 @@ def crop_screenshot(file):
while line:
parts = line.split(':')
if str(width) + ',' + str(height) == parts[0]:
if os.path.splitext(file)[1].lower() == '.png':
img = img.convert('RGB')

pixels_to_crop = parts[1].split(',')
pixels_to_crop = [int(pixel) for pixel in pixels_to_crop]
@@ -52,4 +54,3 @@ def crop_screenshot(file):
invert_cropped_img = PIL.ImageOps.invert(cropped_img)
invert_cropped_img.save("cropped" + os.sep + os.path.splitext(os.path.basename(file))[0] + "_cropped.png", "PNG", quality=100)
return "cropped" + os.sep + os.path.splitext(os.path.basename(file))[0] + "_cropped.png"

0 comments on commit b956d62

Please sign in to comment.
You can’t perform that action at this time.