How to use PyScreeze - 10 common examples

To help you get started, we’ve selected a few PyScreeze examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locate_im(self):
        slashFp = open('slash.png' ,'rb')
        haystack1Fp = open('haystack1.png' ,'rb')
        haystack2Fp = open('haystack2.png' ,'rb')
        colorNoiseFp = open('colornoise.png' ,'rb')
        slashIm = Image.open(slashFp)
        haystack1Im = Image.open(haystack1Fp)
        haystack2Im = Image.open(haystack2Fp)
        colorNoiseIm = Image.open(colorNoiseFp)

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im)))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im, grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im, grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm)
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True), None)

        slashFp.close()
        haystack1Fp.close()
        haystack2Fp.close()
        colorNoiseFp.close()
github asweigart / pyscreeze / tests / benchmarks.py View on Github external
def locateTest():
    largeNoiseFp = open('largenoise.png' ,'rb')
    largeNoiseIm = Image.open(largeNoiseFp)

    imageWidth, imageHeight = largeNoiseIm.size
    bottomRightCorner100x100 = largeNoiseIm.crop((imageWidth - 100, imageHeight - 100, imageWidth, imageHeight))

    for step in (1, 2, 4, 8, 16, 32):
        startTime = time.time()
        result = pyscreeze.locate(bottomRightCorner100x100, largeNoiseIm, step=step)
        print('bottomRightCorner100x100 (step %s) located at %s in: %s seconds' % (step, result, round(time.time() - startTime, 2)))

    largeNoiseFp.close()
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locate_filename(self):
        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png')))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png')))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png', grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png', grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png')
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png'), None)
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True), None)
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
slashIm = Image.open(slashFp)
        haystack1Im = Image.open(haystack1Fp)
        haystack2Im = Image.open(haystack2Fp)
        colorNoiseIm = Image.open(colorNoiseFp)

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im)))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im, grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im, grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm)
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True), None)

        slashFp.close()
        haystack1Fp.close()
        haystack2Fp.close()
        colorNoiseFp.close()
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locate_filename(self):
        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png')))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png')))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png', grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png', grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png')
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png'), None)
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True), None)
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locate_filename(self):
        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png')))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png')))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png', grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png', grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png')
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png'), None)
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True), None)
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locate_filename(self):
        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png')))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png')))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png', grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png', grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png')
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png'), None)
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True), None)
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_imageNotFound(self):
        colorNoiseFp = open('colornoise.png' ,'rb')
        colorNoiseIm = Image.open(colorNoiseFp)
        slashFp = open('slash.png' ,'rb')
        slashIm = Image.open(slashFp)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)

        colorNoiseFp.close()
        slashFp.close()
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locateAll_filename(self):
        self.assertEqual(((94, 94, 4, 4),), tuple(pyscreeze.locateAll('slash.png', 'haystack1.png')))
        self.assertEqual(((93, 93, 4, 4), (94, 94, 4, 4), (95, 95, 4, 4)), tuple(pyscreeze.locateAll('slash.png', 'haystack2.png')))

        self.assertEqual(((94, 94, 4, 4),), tuple(pyscreeze.locateAll('slash.png', 'haystack1.png', grayscale=True)))
        self.assertEqual(((93, 93, 4, 4), (94, 94, 4, 4), (95, 95, 4, 4)), tuple(pyscreeze.locateAll('slash.png', 'haystack2.png', grayscale=True)))

        self.assertEqual((), tuple(pyscreeze.locateAll('slash.png', 'colornoise.png')))
        self.assertEqual((), tuple(pyscreeze.locateAll('slash.png', 'colornoise.png', grayscale=True)))
github asweigart / pyscreeze / tests / benchmarks.py View on Github external
imageWidth, imageHeight = largeNoiseIm.size
    needle10x10   = largeNoiseIm.crop((imageWidth - 10,  imageHeight - 10,  imageWidth, imageHeight))
    needle100x100 = largeNoiseIm.crop((imageWidth - 100, imageHeight - 100, imageWidth, imageHeight))
    needle500x500 = largeNoiseIm.crop((imageWidth - 500, imageHeight - 500, imageWidth, imageHeight))

    profiler = cProfile.Profile()
    profiler.enable()
    list(pyscreeze.locateAll(needle10x10, largeNoiseIm))
    profiler.disable()
    print('10x10 needle:')
    pstats.Stats(profiler).sort_stats('cumulative').print_stats(1)

    profiler = cProfile.Profile()
    profiler.enable()
    list(pyscreeze.locateAll(needle100x100, largeNoiseIm))
    profiler.disable()
    print('100x100 needle:')
    pstats.Stats(profiler).sort_stats('cumulative').print_stats(1)

    profiler = cProfile.Profile()
    profiler.enable()
    list(pyscreeze.locateAll(needle500x500, largeNoiseIm))
    profiler.disable()
    print('500x500 needle:')
    pstats.Stats(profiler).sort_stats('cumulative').print_stats(1)