Skip to content

Commit

Permalink
#120 :: Save intermediate images in debug folder
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBuck committed Mar 23, 2017
1 parent d7fcde7 commit db5b878
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions roboplot/dottodot/number_recognition.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import PIL.Image as Image
import os
import re
import threading

import cv2
import numpy as np
import pytesseract

import roboplot.config as config


class Number:
"""Represents a number on the dot-to-dot picture."""
Expand Down Expand Up @@ -209,6 +213,23 @@ def display_intermediate_images(self):
cv2.imshow(winname=img.name, mat=img.image)
cv2.waitKey(0)

def save_intermediate_images(self, save_path_prefix: str = os.path.join(config.debug_output_folder, 'numrec_')):
counter = -1
for img in self.intermediate_images:
counter += 1

save_dir = os.path.dirname(save_path_prefix)

save_name = os.path.basename(save_path_prefix + str(counter) + '_' + img.name)
save_name = re.sub(r'\s+', '_', save_name) # Replace whitespace with underscores
save_name = re.sub(r'[^\w\s-]', '', save_name) # Remove all weird characters
save_name += '.jpg'

save_path = os.path.join(save_dir, save_name)

image = img.image.copy()
threading.Thread(target=lambda: cv2.imwrite(save_path, image)).start()


def read_image(file_path: str) -> np.ndarray:
"""
Expand Down
4 changes: 3 additions & 1 deletion scripts/recognise_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
print("Recognised number: {!r}".format(recognised_number.numeric_value))
print("Probable spot location: {!r}".format(recognised_number.dot_location_yx))

# Display images
# Save and display images
img.save_intermediate_images()

if args.display_images:
img.display_intermediate_images()

0 comments on commit db5b878

Please sign in to comment.