Пример #1
0
 def test_locate_returns_None_if_no_internal_templates_found_in_scene(self):
     # setup a template and scene that should be guaranteed not to be matched
     black_template = _generic_image(height=5, width=10)
     black_template.fill(0)
     white_scene = _generic_image(height=20, width=20)
     white_scene.fill(255)
     tf = TemplateFinder(black_template)
     p = tf.locate_in(white_scene)
     self.assertIsNone(p)
Пример #2
0
 def test_locate_multiple_returns_empty_sequence_if_nothing_found(self):
     # setup a template and scene that should be guaranteed not to be matched
     black_template = _generic_image(height=5, width=10)
     black_template.fill(0)
     white_scene = _generic_image(height=20, width=20)
     white_scene.fill(255)
     tf = TemplateFinder(black_template)
     p = tf.locate_multiple_in(white_scene)
     empty_sequence = tuple()
     self.assertSequenceEqual(p, empty_sequence)
Пример #3
0
 def test_locate_multiple_returns_all_matches_better_than_acceptable(self):
     # put a set of black "images" on a white background to be searched for
     tlbr_specs = [(2, 2, 4, 4),
                   (5, 5, 7, 7),
                   (8, 8, 10, 10)]
     white_scene = _generic_image(height=20, width=20)
     white_scene.fill(255)
     black_template = _generic_image(height=2, width=2)
     black_template.fill(0)
     # setup thresholds to exercise the spec
     tf = TemplateFinder(black_template,
                         acceptable_threshold=1,
                         immediate_threshold=1)
     # set black squares to match the template
     for t, l, b, r in tlbr_specs:
         white_scene[t:b, l:r] = 0
     borders = tf.locate_multiple_in(white_scene)
     self.assertItemsEqual(borders, tlbr_specs)
Пример #4
0
 def test_locate_returns_result_immediately_when_immediate_passes(self):
     top_spec, left_spec, bottom_spec, right_spec = 2, 3, 22, 33
     height_spec = bottom_spec - top_spec
     width_spec = right_spec - left_spec
     black_template = _generic_image(height=height_spec,
                                     width=width_spec)
     black_template.fill(0)
     white_scene = _generic_image(height=height_spec * 3,
                                  width=width_spec * 3)
     white_scene.fill(255)
     # set a black square to match the template
     white_scene[top_spec:bottom_spec, left_spec:right_spec] = 0
     # setup thresholds to exercise the spec
     impossible = -1
     always = 2
     tf = TemplateFinder(black_template, acceptable_threshold=impossible,
                         immediate_threshold=always)
     # confirm the result
     borders = tf.locate_in(white_scene)
     self.assertEqual(borders,
                      (top_spec, left_spec, bottom_spec, right_spec))