示例#1
0
 def test_how_full_returns_approximatelly_correct_fill_level(self):
     tank_image = cv2.imread(path.join(this_path, 'health bar 77%.png'))
     self.assertIsNotNone(tank_image)  # to avoid confusing errors
     fill = (5, 5, 200)
     empty = (40, 40, 50)
     ignore = (20, 20, 20)
     tl = self._generic_TankLevel(fill=fill, empty=empty, ignore=ignore)
     fill_level = tl.how_full(tank_image)
     fill_level_spec = 0.77
     tolerance = 0.2  # allow +/- 20%
     self.assertAlmostEqual(fill_level, fill_level_spec, delta=tolerance)
示例#2
0
 def test_gridify_generates_correct_sequence_of_borders(self):
     # get the test image which is constructed as follows:
     grid_image_path = path.join(this_path,
                                 'grid (tlbr padding - 1, 2, 3, 4).png')
     grid_image = cv2.imread(grid_image_path)
     self.assertIsNotNone(grid_image)  # just confirm file loaded
     # 4 rows, 2 columns
     dimensions = (4, 2)
     # (top, left, bottom, right) padding:
     #   = (1px, 2px, 3px, 4px)
     #   = (1/5, 2/10, 3/5, 4/10)
     #   = (0.2, 0.2, 0.6, 0.4)
     cell_padding = 0.2, 0.2, 0.6, 0.4
     #   ==> remaining cell image shape is 1 row, 4 columns (3 channels)
     channels = 3
     cell_shape_spec = (1, 4, channels)  # 1 row, 4 columns, 3 channels
     # ==> content of each cell image should be exactly the colored parts
     #     in the image as follows:
     red = (0, 0, 255)
     green = (0, 255, 0)
     blue = (255, 0, 0)
     white = (255, 255, 255)
     colors_spec = [[red, white],
                    [green, red],
                    [blue, green],
                    [white, blue]]
     colors_spec = numpy.asarray(colors_spec)
     # gridify the image and confirm all sub images match the above specs
     grid = Grid(dimensions, cell_padding)
     for grid_position, borders in grid.borders_by_grid_position(grid_image):
         top, left, bottom, right = borders
         # confirm the size
         cell_shape = (bottom - top, right - left, channels)
         self.assertEqual(cell_shape, cell_shape_spec)
         spec_pixel = colors_spec[grid_position]
         # confirm the color for each pixel in the cell
         for pixel_row in range(top, bottom):
             for pixel_col in range(left, right):
                 p = pixel_row, pixel_col
                 image_pixel = grid_image[p]
                 self.assertTrue(numpy.all(image_pixel == spec_pixel),
                                 'Pixel in grid cell:'
                                 '\n{}: {}'
                                 '\nunexpectedly not equal to specification:'
                                 '\n{}'.format(grid_position, image_pixel,
                                               spec_pixel))
示例#3
0
from os import path

from investigators.visuals import cv2

_base = path.abspath(path.split(__file__)[0])

capture_template = cv2.imread(path.join(_base, 'capture template 1280x960.png'))
versus_template = cv2.imread(path.join(_base, 'versus template 1280x960.png'))
extra_action_template = cv2.imread(path.join(_base,
                                             'extra action template.png'))

tile_templates = {'.': cv2.imread(path.join(_base, '_.png')),
                  'r': cv2.imread(path.join(_base, 'r.png')),
                  'g': cv2.imread(path.join(_base, 'g.png')),
                  'b': cv2.imread(path.join(_base, 'b.png')),
                  'y': cv2.imread(path.join(_base, 'y.png')),
                  'x': cv2.imread(path.join(_base, 'x.png')),
                  'm': cv2.imread(path.join(_base, 'm.png')),
                  's': cv2.imread(path.join(_base, 's.png')),
                  '*': cv2.imread(path.join(_base, '@.png')),
                  'c': cv2.imread(path.join(_base, 'c.png')),
                  'h': cv2.imread(path.join(_base, 'h.png')),
                  '2': cv2.imread(path.join(_base, '2.png')),
                  '3': cv2.imread(path.join(_base, '3.png')),
                  '4': cv2.imread(path.join(_base, '4.png')),
                  '5': cv2.imread(path.join(_base, '5.png')),
                  '6': cv2.imread(path.join(_base, '6.png')),
                  '7': cv2.imread(path.join(_base, '7.png')),
                  '8': cv2.imread(path.join(_base, '8.png'))}