Example #1
0
 def test_find_image_exact(self):
     haystack = Image.open('test/login2.png')
     needle = Image.open('test/login-slice.png')
     matches = find.image_exact(haystack, needle)
     if imgshow:
         for match in matches:
             haystack = match.draw(haystack)
         haystack = draw_text(haystack, "test_find_image_exact", (0, 0))
         haystack.show()
     self.assertEqual(len(matches), 1)
Example #2
0
 def test_find_image(self):  # test core/find.image
     haystack = Image.open('test/login.png')
     # screenshot of haystack
     needle = Image.open('test/login-slice.png')
     match = find.image(haystack, needle)
     if imgshow:
         haystack = draw_text(haystack, "test_find_image", (0, 0))
         haystack = match.draw(haystack)
         haystack.show()
     self.assertIsNotNone(match)
Example #3
0
 def test_find_images(self):  # test core/find.imagecv2
     haystack = Image.open('test/login2.png')
     needle = Image.open('test/login-slice.png')
     matches = find.images(haystack, needle, threshold=0.95)
     if imgshow:
         for match in matches:
             haystack = draw_text(haystack, "test_find_images", (0, 0))
             haystack = match.draw(haystack)
         haystack.show()
     self.assertEqual(len(matches), 1)
Example #4
0
 def test_find_image_masked(self):
     mmap = Image.open('test/minimap-border.png', alpha_mask=True)
     img = Image.open('test/test-mmap.png')
     # cv2.TM_CCORR_NORMED didnt work here...
     match = find.image(img, mmap, method=cv2.TM_SQDIFF)
     if imgshow:
         img = draw_text(img, "test_find_image_masked", (0, 0))
         img = match.draw(img)
         img.show()
     self.assertIsNotNone(match)
Example #5
0
 def test_find_image_exact_masked(self):
     img = Image.open('./scripts/scaperune/images/older.png')
     mmap = Image.open('./scripts/scaperune/images/minimap-border.png')
     mmap.mask = mmap == [0, 0, 0]  # mask transparent aka black values
     matches = find.image_exact(img, mmap)
     print(len(matches))
     for match in matches:
         img = match.draw(img)
     img = draw_text(img, "test_find_image_exact_masked", (0, 0))
     img.show()
Example #6
0
 def test_find_map_position(self):
     from pysrl.scripts.scaperune.interface import minimap
     map_img = Image.open('test/osrs-world-map.png')
     screen_img = Image.open('test/older2.png')
     mmap_img = minimap.get_image(screen_img)
     match = find.image(map_img, mmap_img, method=cv2.TM_SQDIFF)
     if imgshow:
         map_img = draw_text(map_img, "test_find_map_position", (0, 0))
         map_img = draw_text(map_img, str(match), (0, 15))
         match.draw(map_img).show()
     self.assertIsNotNone(match)
     self.assertEqual(match.top_left, Point(4520, 3184))
Example #7
0
 def test_find_colors(self):  # test core/color.py
     img = Image.open('test/test.jpeg')
     cts = CTS2([0, 0, 0], 10, 10, 10)
     pts = find.colors(img, cts)
     if imgshow:
         img = draw_text(img, "test_find_colors", (0, 0))
         pts.draw(img).show()
     self.assertEqual(len(pts), 2560)
Example #8
0
 def test_find_text(self):  # test core/find.text
     img = Image.open('test/login2.png')
     match = find.text(img, 'New User')
     if imgshow:
         img = draw_text(img, "test_find_text", (0, 0))
         img = match.draw(img)
         img.show()
     self.assertIsNotNone(match)
Example #9
0
 def test_pa_cluster(self):  # test core/types/point_array.py
     img = Image.open('test/test.jpeg')
     cts = CTS2([0, 0, 0], 10, 10, 10)
     pts = find.colors(img, cts)
     clusters = pts.cluster(2)
     if imgshow:
         img = draw_text(img, "test_pa_cluster", (0, 0))
         clusters.draw(img).show()
     self.assertGreaterEqual(len(clusters), 1)
Example #10
0
 def test_pa2d_filter(self):  # test core/types/point_array2d.py
     img = Image.open('test/test.jpeg')
     cts = CTS2([0, 0, 0], 10, 10, 10)
     pts = find.colors(img, cts)
     clusters = pts.cluster(2)
     filtered = clusters.filtersize(50, 3000)
     if imgshow:
         img = draw_text(img, "test_pa2d_filter", (0, 0))
         filtered.draw(img).show()
     self.assertEqual(len(filtered), 1)
Example #11
0
 def __init__(self, p1: Point, mask: str = './test/minimap-border.png'):
     masked_img = Image.open(mask, alpha_mask=True)
     self.mask = masked_img.mask  # we want the mask only
     h, w, _ = self.mask.shape
     p2 = Point(p1.x + w, p1.y + h)
     super().__init__(p1, p2)
Example #12
0
# row 5
inv_slots.append(Slot.from_array([563, 359, 594, 390]))
inv_slots.append(Slot.from_array([604, 359, 635, 391]))
inv_slots.append(Slot.from_array([644, 359, 680, 391]))
inv_slots.append(Slot.from_array([688, 361, 720, 389]))
# row 6
inv_slots.append(Slot.from_array([562, 398, 595, 426]))
inv_slots.append(Slot.from_array([606, 397, 635, 424]))
inv_slots.append(Slot.from_array([644, 394, 680, 426]))
inv_slots.append(Slot.from_array([687, 396, 723, 426]))
# row 7
inv_slots.append(Slot.from_array([561, 429, 597, 462]))
inv_slots.append(Slot.from_array([605, 431, 638, 459]))
inv_slots.append(Slot.from_array([646, 433, 680, 460]))
inv_slots.append(Slot.from_array([690, 431, 722, 460]))

# INVENTORY
interface_tabs_boxr = [552, 205, 733, 464]  # interface tab box raw
inv_button = Button.from_array([628, 170, 658, 201])
inventory = Inventory(interface_tabs_boxr, inv_button, inv_slots)

# MINIMAP/COMPASS
mmap_pos = Point(643, 83)  # center of mmap
comp_pos = Point(561, 20)  # center of compass
minimap = Minimap(Point(550, 4))
compass = Compass(comp_pos, 15)
testimg = Image.open(
    '/home/not-here/Projects/pysrl/scripts/scaperune/images/blah.png')
chatbox = Chatbox.from_array([4, 368, 517, 503])
mainscreen = Box.from_array([4, 4, 516, 338])