Skip to content

Commit

Permalink
#120 :: Added tests for bat images and fixed bug in creation of Numbe…
Browse files Browse the repository at this point in the history
…r objects
  • Loading branch information
JackBuck committed Mar 23, 2017
1 parent 87c2291 commit 347ff6f
Show file tree
Hide file tree
Showing 42 changed files with 32 additions and 17 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion roboplot/dottodot/number_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def process_image(self) -> Number:
self._rotate_centre_spot_to_bottom_right()
self._recognise_number_text()
self._extract_number_from_recognised_text()
return Number(self.recognised_numeric_value, self.centre_spot.pt)
return Number(numeric_value=self.recognised_numeric_value,
dot_location_yx=(self.centre_spot.pt[1], self.centre_spot.pt[0]))

def _clean_image(self):
self._img = cv2.medianBlur(self._img, ksize=3)
Expand Down
46 changes: 30 additions & 16 deletions testing/test_number_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,48 @@

import context
import roboplot.config as config
from roboplot.dottodot.number_recognition import DotToDotImage
import roboplot.dottodot.number_recognition as number_recognition


class NumberRecognitionRegressionTests(unittest.TestCase):
test_data_directory = os.path.join(config.test_data_dir, 'number_recognition')

def test_on_selection_of_sizes(self):
"""Regression test number recognition on potentially rotated images."""
file_glob = os.path.join(self.test_data_directory, '*.jpg')
file_glob = os.path.join(self.test_data_directory, 'various_sizes', '*.jpg')
for img_file in glob.glob(file_glob):
filename = os.path.basename(img_file)
file_name_match = re.match(
r'(?P<numeric_value>\d+)_(?P<fontsize>\d+)pt_(?P<angle>\d+)deg_y(?P<spot_y>\d+)_x(?P<spot_x>\d+)',
filename)
with self.subTest(filename = filename):
# Perform the number recognition
img = DotToDotImage.load_image_from_file(img_file)
number = img.process_image()

# Extract expected results
expected_number = int(file_name_match.group('numeric_value'))
expected_spot_location = (int(file_name_match.group('spot_y')),
int(file_name_match.group('spot_x')))

# Compare
self.assertEqual(number.numeric_value, expected_number)
self.assertAlmostEqual(number.dot_location_yx[0], expected_spot_location[0], delta=2)
self.assertAlmostEqual(number.dot_location_yx[1], expected_spot_location[1], delta=2)

expected_number = number_recognition.Number(numeric_value=int(file_name_match.group('numeric_value')),
dot_location_yx=(int(file_name_match.group('spot_y')),
int(file_name_match.group('spot_x'))))
self._test_on_file(img_file, expected_number)

def test_on_bat_images(self):
"""Regression test number recognition on images for the bat dot-to-dot"""
file_glob = os.path.join(self.test_data_directory, 'bat_size_20', '*.jpg')
for img_file in glob.glob(file_glob):
filename = os.path.basename(img_file)
file_name_match = re.match(r'(?P<numeric_value>\d+)_y(?P<spot_y>\d+)_x(?P<spot_x>\d+)', filename)

expected_number = number_recognition.Number(numeric_value=int(file_name_match.group('numeric_value')),
dot_location_yx=(int(file_name_match.group('spot_y')),
int(file_name_match.group('spot_x'))))
self._test_on_file(img_file, expected_number)

def _test_on_file(self, file_path, expected_number):
with self.subTest(filename=os.path.basename(file_path)):
# Perform the number recognition
img = number_recognition.DotToDotImage.load_image_from_file(file_path)
number = img.process_image()

# Compare
self.assertEqual(number.numeric_value, expected_number.numeric_value)
self.assertAlmostEqual(number.dot_location_yx[0], expected_number.dot_location_yx[0], delta=2)
self.assertAlmostEqual(number.dot_location_yx[1], expected_number.dot_location_yx[1], delta=2)


if __name__ == '__main__':
Expand Down

0 comments on commit 347ff6f

Please sign in to comment.