Skip to content

Commit

Permalink
Fixed a crash when attempting to fix the OCR error of a l in the front
Browse files Browse the repository at this point in the history
of a string
Added support for PNG screenshots
  • Loading branch information
BradfordBach committed May 25, 2019
1 parent 8156dbc commit b956d62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NMS_Locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ')

Expand Down
3 changes: 2 additions & 1 deletion screenshot_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.