Exemple #1
0
def draw_corners(times=10):
    window = Window()
    rx, ry, w, h = StartPointConfig.roi
    for i in range(times):
        # image = cv2.imread('assets/data/after_turn_around/' + str(i) + '.png')
        image = np.array(screenshot(window.rect))
        e = Extruder(image)
        roi = e.threshold(StartPointConfig)
        show_image(roi)
        roi = e.clear(roi)
        corners = e.corners(roi)

        # if corners is not None:
        #     #  search start point
        #     plain_corners = [c.ravel() for c in corners]
        #     plain_corners.sort(key = lambda x: x[0], reverse=True)
        #     right = plain_corners[0]
        #     plain_corners.sort(key = lambda x: x[1], reverse=True)
        #     bottom = plain_corners[0]

        #     print(right, bottom)
        #     # for c in corners:
        #     #     x,y = c.ravel()
        #     #     print(x,y)
        #     #     image = cv2.circle(image, (rx+x,ry+y), 3, 255, -1)
        #     cv2.circle(image, (window.x + rx + right[0], window.y + ry + right[1]), 3, 150, -1)
        from shapes.rect import Rect
        cx, cy = Rect(StartPointConfig.roi).center()
        Click(window.x + cx, window.y + cy).make_click()
Exemple #2
0
def filter_img_by_color(times=10, color_shcheme=None):
    for i in range(times):
        image = cv2.imread('assets/data/screens/' + str(i) + '.png')
        extruded = Extruder(image)
        extruded = extruded.filtredImgByColor(color_shcheme)
        # show_image(extruded)
        cv2.imwrite('assets/data/church/' + str(i) + '.png', extruded)
Exemple #3
0
def match_guild_by_template(times=10, imagepath="assets/data/screens/"):
    from utils.cv2_utils import draw_rect
    guild_template = cv2.imread(GUILD_TEMPLATE)
    for i in range(times):
        image = cv2.imread(imagepath + str(i) + '.png')
        extruder = Extruder(image)
        guild_roi = extruder.match_by_template(guild_template)
        print('guild_roi', guild_roi)
Exemple #4
0
def draw_matched(times, imagepath='assets/data/screens/', config=None):
    for i in range(times):
        print('[${i}]'.format(i=i))
        image = cv2.imread(imagepath + str(i) + '.png')
        e = Extruder(image)
        rect = e.get_template_rect(config)
        result = cv2.rectangle(e.image, rect[:2],
                               (rect[0] + rect[2], rect[1] + rect[3]), 255, 2)
        cv2.imwrite('assets/data/altar_matched/' + str(i) + '.png', result)
Exemple #5
0
def move_to_npc(times=10, imagepath='assets/data/npc_extruded_by_char_color/'):
    template = cv2.imread(TEMPLATE)
    window = Window()

    for i in range(times):
        image = u.screenshot(region=window.rect)
        extruded = Extruder(image)
        title_roi = extruded.match_by_template(
            template, image=extruded.filtredImgByColor(CharTitleConfig))
        print(title_roi)
        Navigator.move_to_npc(title_roi)
Exemple #6
0
    def select_menu(self, config, quality='minmax'):
        Wait(DELAY).delay()
        e = Extruder(screenshot(Window().rect))
        template = cv2.imread(config.path)
        menu = e.match_by_template(template, roi=config.roi, method=quality)
        if not menu:
            return None

        point = Rect(menu).center()
        x, y = Window().relative(point)
        Click(x, y).make_click()
        return x, y
Exemple #7
0
 def detect(self):
     # move method head to once detection method if could be needed
     frame = screenshot(self.window.rect)
     e = Extruder(frame)
     match = e.match_by_template(self.observable, method='threshold')
     while not match:
         image = screenshot(self.window.rect)
         image = np.array(image)
         image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
         match = e.match_by_template(self.observable,
                                     image=image,
                                     method='threshold')
         frame = image
     return match
Exemple #8
0
def get_tempalate_roi(config, image=None):
    rect = Window().rect
    if not image:
        image = screenshot(rect)

    extruder = Extruder(image)

    # roi = extruder.get_template_rect(config)
    # import cv2
    # from utils.cv2_utils import show_image
    # import numpy as np
    # rected = np.array(image)
    # rected = cv2.cvtColor(rected, cv2.COLOR_RGB2BGR)
    # rected = cv2.rectangle(rected, roi[:2], (roi[0] + roi[2], roi[1] + roi[3]), 255,2)
    # show_image(rected)

    return extruder.get_template_rect(config)
Exemple #9
0
def match_title_by_template(times=11, imagepath='assets/data/screens/'):
    template = cv2.imread(TEMPLATE)
    for i in range(times):
        image = cv2.imread(imagepath + str(i) + '.png')
        extruded = Extruder(image)

        @timerfunc
        def test_extrude():
            return extruded.match_by_template(template)

        template_roi = test_extrude()
        result = cv2.rectangle(extruded.image, template_roi[:2],
                               (template_roi[0] + template_roi[2],
                                template_roi[1] + template_roi[3]), 255, 2)
        cv2.imwrite('assets/data/altar_matched/' + str(i) + '.png', result)
Exemple #10
0
def draw_positon_features(times=50):
    for i in range(times):
        image = cv2.imread('assets/data/start_point_src/' + str(i) + '.png')
        e = Extruder(image)
        titleRoi, guildRoi = e.get_template_rect(
            CharTitleConfig), e.get_template_rect(GuildIconConfig)
        npcC = Rect(titleRoi).center()
        gC = Rect(guildRoi).center()
        cv2.circle(image, npcC, 5, [0, 200, 0], 2)
        cv2.circle(image, gC, 5, [200, 10, 0], 2)
        cv2.line(image, npcC, gC, [0, 0, 200], 2)  # connect gc n npc
        cv2.line(image, gC, (gC[0], npcC[1]), [100, 10, 10],
                 2)  # gc projection
        cv2.line(image, npcC, (gC[0], npcC[1]), [100, 100, 10],
                 2)  # npcc projection
        npcGuildDist = gC[1] - npcC[1]
        GN = abs(npcC[0] - gC[0])
        cv2.putText(image, str(npcGuildDist), (0, 10),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, [0, 0, 200], 2)
        cv2.putText(image, str(GN), (0, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                    [100, 50, 100], 2)

        cv2.imwrite('assets/data/start_position_features/' + str(i) + '.png',
                    image)
Exemple #11
0
class TestExtruder(unittest.TestCase):

    testimage = 'test/fixtures/testslice.png'

    def setUp(self):
        self.extruder = Extruder(get_image(self.testimage))

    def test_set_image(self):
        data = get_image(self.testimage)
        result = Extruder(data)
        self.assertIsInstance(result.image, np.ndarray)

    def test_filter_by_color(self):
        result = self.extruder.filterByColor(self.extruder.image,
                                             TestExtruderConfig)
        self.assertIsInstance(result, np.ndarray)

    def test_filter_img_by_color(self):
        data = TestExtruderConfig()
        result = self.extruder.filtredImgByColor(data)
        self.assertIsInstance(result, np.ndarray)

    def test_match_by_template_no_roi_minmax(self):
        template = get_image(TestExtruderConfig.template)
        data = self.extruder.match_by_template(template)
        self.assertEqual(data, (5, 46, 22, 19))

    def test_match_by_template_roi_minmax(self):
        template = get_image(TestExtruderConfig.template)
        data = self.extruder.match_by_template(template, roi=(0, 40, 30, 30))
        self.assertEqual(data, (5, 46, 22, 19))

    def test_match_by_template_threshold(self):
        template = get_image(TestExtruderConfig.template)
        data = self.extruder.match_by_template(template, method='threshold')
        self.assertEqual(data, (5, 46, 22, 19))
Exemple #12
0
def get_guild_npc_rect(times=10):
    for i in range(times):
        image = cv2.imread(SCREENS + str(i) + '.png')
        e = Extruder(image)
        e.threshold(StartPointConfig)
Exemple #13
0
 def test_set_image(self):
     data = get_image(self.testimage)
     result = Extruder(data)
     self.assertIsInstance(result.image, np.ndarray)
Exemple #14
0
 def setUp(self):
     self.extruder = Extruder(get_image(self.testimage))