Пример #1
0
 def setUp(self):
     self.repo = DirectoryRepo('test_repo')
     self.gui = GUI(
         GeistFakeBackend(image=np.array(
             [[[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
              [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
              [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
              [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]]])))
     self.V = Viewer(self.gui, self.repo)
     self.screen = self.gui.capture_locations()[0]
     self.red = np.array([[[255, 0, 0]]])
     self.more_reds = np.array([[[255, 0, 0], [240, 10, 10]]])
Пример #2
0
 def setUp(self):
     self.repo = DirectoryRepo('test_repo')
     self.gui = GUI(GeistFakeBackend(image=np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]])))
     self.V = Viewer(self.gui, self.repo)
     self.screen = self.gui.capture_locations()[0]
     self.red = np.array([[[255,0,0]]])
     self.more_reds = np.array([[[255,0,0],[240,10,10]]])
Пример #3
0
class TestViewer(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(GeistFakeBackend(image=np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]])))
        self.V = Viewer(self.gui, self.repo)
        self.screen = self.gui.capture_locations()[0]
        self.red = np.array([[[255,0,0]]])
        self.more_reds = np.array([[[255,0,0],[240,10,10]]])


    def test_get_colour(self):
        red = self.V._get_colour(self.red)
        result = self.gui.find_all(BinaryRegionFinder(red))
        expected = [Location(0,0, w=1, h=1, parent=self.screen)]
        self.assertListEqual(result, expected)


    def test_get_colour_range(self):
        reds = self.V._get_colour(self.more_reds)
        result = self.gui.find_all(BinaryRegionFinder(reds))
        expected = [Location(0,0, w=2, h=1, parent=self.screen)]
        self.assertListEqual(result, expected)


    def test_save(self):
        self.V._save('test_file', Location(0,0, w=1, h=1).image)
        self.assertIn('test_file', self.repo.entries)


    def test_save_overwrite(self):
        self.V._save('test_file', Location(0,0, w=1, h=1).image)
        with self.assertRaises(KeyError):
            self.V._save('test_file', Location(0,0, w=1, h=1).image)


    def test_save_force(self):
        self.V._save('test_file', Location(0,0, w=1, h=1).image, force=True)
        self.assertIn('test_file', self.repo.entries)


    def tearDown(self):
        if 'test_file' in self.repo.entries:
            del self.repo['test_file']
Пример #4
0
 def setUp(self):
     self.repo = DirectoryRepo('test_repo')
     self.gui = GUI(GeistFakeBackend())
     self.V = Viewer(self.gui, self.repo)
     # first need to save some images to repo
     self.image = np.array([[0, 0, 0, 0, 0],
                       [0, 0, 0, 1, 0],
                       [0, 0, 1, 0, 0],
                       [0, 1, 0, 0, 0],
                       [0, 0, 0, 0, 0]])
     self.image2 = np.array([[0, 0, 0, 0, 0, 0, 0],
                       [0, 0, 0, 1, 0, 0, 0],
                       [0, 0, 1, 0, 0, 0, 0],
                       [0, 1, 0, 0, 0, 0, 0],
                       [0, 0, 0, 0, 0, 0, 0]])
     self.image3 = np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]], dtype=np.int32)
     self.V._save('test_file_1', self.image, force=True)
     self.V._save('test_file_2', self.image2, force=True)
     self.V._save('test_file_3', self.image3, force=True)
Пример #5
0
class TestViewer(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(GeistFakeBackend(image=np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]])))
        self.V = Viewer(self.gui, self.repo)
        self.screen = self.gui.capture_locations()[0]
        self.red = np.array([[[255,0,0]]])
        self.more_reds = np.array([[[255,0,0],[240,10,10]]])
    
    
    def test_get_colour(self):
        red = self.V._get_colour(self.red)
        result = self.gui.find_all(BinaryRegionFinder(red))
        expected = [Location(0,0, w=1, h=1, parent=self.screen)]
        self.assertListEqual(result, expected)
    
    
    def test_get_colour_range(self):
        reds = self.V._get_colour(self.more_reds)
        result = self.gui.find_all(BinaryRegionFinder(reds))
        expected = [Location(0,0, w=2, h=1, parent=self.screen)]
        self.assertListEqual(result, expected)
Пример #6
0
class TestViewer(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(
            GeistFakeBackend(image=np.array(
                [[[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
                 [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
                 [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
                 [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]]])))
        self.V = Viewer(self.gui, self.repo)
        self.screen = self.gui.capture_locations()[0]
        self.red = np.array([[[255, 0, 0]]])
        self.more_reds = np.array([[[255, 0, 0], [240, 10, 10]]])

    def test_get_colour(self):
        red = self.V._get_colour(self.red)
        result = self.gui.find_all(BinaryRegionFinder(red))
        expected = [Location(0, 0, w=1, h=4, parent=self.screen)]
        self.assertListEqual(result, expected)

    def test_get_colour_range(self):
        reds = self.V._get_colour(self.more_reds)
        result = self.gui.find_all(BinaryRegionFinder(reds))
        expected = [Location(0, 0, w=2, h=4, parent=self.screen)]
        self.assertListEqual(result, expected)

    def test_save(self):
        self.V._save('test_file', np.array([0]))
        self.assertIn('test_file', self.repo.entries)

    def test_save_overwrite(self):
        self.V._save('test_file', np.array([0]))
        with self.assertRaises(KeyError):
            self.V._save('test_file', np.array([1]))

    def test_save_force(self):
        self.V._save('test_file', np.array([0]))
        self.V._save('test_file', np.array([1]), force=True)
        self.assertEqual(self.repo['test_file'].image, np.array([1]))

    def tearDown(self):
        if 'test_file' in self.repo.entries:
            del self.repo['test_file']
Пример #7
0
Use the viewer object to capture images and test finders in an interactive ipython
"""

try:
    get_ipython().magic('pylab')
except (NameError, ):
    pass

from geist.backends import get_platform_backend

from geist import (
    GUI,
    DirectoryRepo,
)

from geist.pyplot import Viewer

# Mark the directory listed as the current image repository
repo = DirectoryRepo(
    "C:\some_filepath")  # <--------------- EDIT ME!!!!!!!!!!!!!!!

# Start a Geist backend, takes an optional screen number to capture.
backend = get_platform_backend()

# Start a Geist GUI
gui = GUI(backend)

# Viewer  object can be used to display results in image form
viewer = Viewer(gui, repo)
Пример #8
0
class TestSimilarity(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(GeistFakeBackend())
        self.V = Viewer(self.gui, self.repo)
        # first need to save some images to repo
        self.image = np.array([[0, 0, 0, 0, 0],
                          [0, 0, 0, 1, 0],
                          [0, 0, 1, 0, 0],
                          [0, 1, 0, 0, 0],
                          [0, 0, 0, 0, 0]])
        self.image2 = np.array([[0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 1, 0, 0, 0],
                          [0, 0, 1, 0, 0, 0, 0],
                          [0, 1, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0]])
        self.image3 = np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]], dtype=np.int32)
        self.V._save('test_file_1', self.image, force=True)
        self.V._save('test_file_2', self.image2, force=True)
        self.V._save('test_file_3', self.image3, force=True)
            
    def test_no_match(self):
        blank = np.zeros((100, 100))
        template = np.array([[0, 1], [1, 0]])

        expected = []
        result = is_similar(template, blank)
        self.assertFalse(result)

    def test_match(self):
        image = np.array([[0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 1, 0],
                          [0, 0, 0, 0, 0, 1, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 1, 0, 0, 0, 0, 0],
                          [0, 1, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0]])
        template = np.array([[0, 1], [1, 0]])
        result = is_similar(template, image)
        self.assertEqual(result, "matches exist- size different")
        
    def test_similar_size(self):
        template = np.array([[0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 1, 0, 0],
                          [0, 0, 1, 0, 0, 0],
                          [0, 1, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0]])
        result = is_similar(template, self.image, size_tolerance=0.2)
        self.assertTrue(result)
        
    def test_colour(self):
        result = is_similar(self.image3, self.image3)
        self.assertTrue(result)
                
    def test_colour_size_different(self):
        template = np.array([[[255,0,0],[240,10,10]]], dtype=np.int32)
        result = is_similar(template, self.image3)
        self.assertEqual(result, "matches exist- size different")
        
    def test_find_similar_in_repo_similar(self):
        similar, different_size, no_match = find_similar_in_repo(self.image, self.repo, size_tolerance=0.2)
        self.assertListEqual(similar, ['test_file_1'])

        
    def test_find_similar_in_repo_different_size(self):
        similar, different_size, no_match = find_similar_in_repo(self.image, self.repo, size_tolerance=0.2)
        self.assertListEqual(different_size, ['test_file_2'])
        
    def test_find_similar_in_repo_similar_no_match(self):
        similar, different_size, no_match = find_similar_in_repo(self.image, self.repo, size_tolerance=0.2)
        self.assertListEqual(no_match, ['test_file_3'])
        
    def test_find_similar_in_repo_similar_no_match_2(self):
        image = np.array([[1,1],[1,1]])
        similar, different_size, no_match = find_similar_in_repo(image, self.repo, size_tolerance=0.2)
        self.assertListEqual(sorted(no_match), sorted(['test_file_1', 'test_file_2', 'test_file_3']))

    def tearDown(self):
        if 'test_file_1' in self.repo.entries:
            del self.repo['test_file_1']  
        if 'test_file_2' in self.repo.entries:
            del self.repo['test_file_2'] 
        if 'test_file_3' in self.repo.entries:
            del self.repo['test_file_3']