コード例 #1
0
ファイル: gold.py プロジェクト: anchalghale/sultan
def get_gold(img, knearest):
    '''Finds gold value'''
    img = crop(img, (629, 752, 35, 9))
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    gold = ''
    for i in range(5):
        cropped = crop(img, (i * 7, 0, 7, 9))
        gold += str(knearest['gold'].predict(cropped))
    try:
        return int(gold)
    except ValueError:
        return -1
コード例 #2
0
def get_game_time(img, models):
    '''Finds game minutes'''
    img = crop(img, (981, 6, 27, 8))
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    minutes = ''
    seconds = ''
    for i in range(2):
        min_crop = crop(img, (i * 6, 0, 6, 8))
        min_crop = cv2.resize(min_crop, (7, 9))

        sec_crop = crop(img, (15 + i * 6, 0, 6, 8))
        sec_crop = cv2.resize(sec_crop, (7, 9))

        minutes += str(models['gold'].predict(min_crop, threshold=False))
        seconds += str(models['gold'].predict(sec_crop, threshold=False))
    return int(minutes) + int(seconds) / 100
コード例 #3
0
ファイル: minimap.py プロジェクト: anchalghale/sultan
def get_minimap_coor(analytics, img):
    ''' Finds the position of character in the minimap '''
    analytics.start_timer('get_minimap_coor', 'Finding minimap coordiantes')
    map_ = crop(img, (834, 577, 183, 183))
    img = cv2.inRange(map_, (255, 255, 255), (255, 255, 255))
    kernel = numpy.ones((2, 2), numpy.uint8)
    img = cv2.erode(img, kernel, iterations=1)
    img = cv2.dilate(img, kernel, iterations=1)
    contours, _ = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    if contours == []:
        raise NoCharacterInMinimap
    box = sorted(contours, key=cv2.contourArea, reverse=True)[0]
    rect = list(cv2.boundingRect(box))
    h, w = img.shape[:2]
    left_gap = rect[0]
    top_gap = rect[1]
    bot_gap = h - rect[1] - rect[3]
    right_gap = w - rect[0] - rect[2]
    if rect[2] < 40:
        if left_gap > right_gap:
            rect[2] = 40
        else:
            rect[0] -= 40 - rect[2]
            rect[2] = 40
    if rect[3] < 31:
        if top_gap > bot_gap:
            rect[3] = 31
        else:
            rect[1] -= 31 - rect[3]
            rect[3] = 31
    coor = find_center(rect)
    analytics.end_timer('get_minimap_coor')
    return coor
コード例 #4
0
def identify_object(img, contour, area):
    ''' Indentify an object from the coordiate '''
    if area != 0:
        return None
    size = img.shape[:2]
    coor = tuple(contour[0][0])
    output = {'coor': coor}
    colors = (0, 255, 0), (255, 0, 0), (255, 255, 0), (0, 0, 255), (0, 0, 134)
    mappings = dict(
        zip(colors,
            ('champion', 'structure', 'monster', 'minion', 'small_monster')))
    nearest_color = get_nearest(img[coor_offset(coor, (0, -1), size)], colors,
                                25)
    if nearest_color is None:
        return None
    if mappings[nearest_color] == 'champion':
        color = img[coor_offset(coor, (1, 0), size)]
        output['name'] = get_nearest_value(
            color, ((0, 255, 0), (255, 0, 0), (0, 0, 255)),
            ('player_champion', 'enemy_champion', 'ally_champion'))
        output['center'] = coor[0] + 40, coor[1] + 100
        hp_bar = img[coor[1]:coor[1] + 1, coor[0] + 1:coor[0] + 106]
        output['health'] = get_hp_value(hp_bar)
        output['level'] = get_summoner_level(
            crop(img, (coor[0] - 22, coor[1] - 12, 19, 21)), LEVEL_OCR)
        output['is_turret'] = tuple(img[coor_offset(coor, (-2, 0),
                                                    size)]) == (0, 36, 21)
    elif mappings[nearest_color] == 'structure':
        output['name'] = 'structure'
        output['center'] = coor[0] + 75, coor[1] + 150
    elif mappings[nearest_color] == 'monster':
        output['name'] = 'monster'
    elif mappings[nearest_color] == 'small_monster':
        output['name'] = 'small_monster'
    elif mappings[nearest_color] == 'minion':
        color = img[coor_offset(coor, (1, 0), size)]
        colors = (98, 167, 231), (224, 114, 112), (219, 170, 130)
        mappings = dict(zip(colors, ('ally_minion', 'enemy_minion', 'plant')))
        output['name'] = mappings[get_nearest(color, colors)]
        hp_bar = img[coor[1]:coor[1] + 1, coor[0] + 1:coor[0] + 61]
        output['health'] = get_small_hp_value(hp_bar)
        output['center'] = coor[0] + 30, coor[1] + 35
        if output['name'] == 'enemy_minion':
            output['aggro'] = get_color_diff(
                img[coor_offset(coor, (28, -16), size)], (255, 0, 0)) < 50
        output['is_order_side'] = output['center'][1] / \
            output['center'][0] > img.shape[0]/img.shape[1]
        try:
            output['is_turret'] = (
                tuple(img[coor_offset(coor, (-1, 0), size)]) == (0, 36, 21)
                or tuple(img[output['center'][::-1]]) == (0, 36, 21))
        except IndexError:
            output['is_turret'] = False
    return output
コード例 #5
0
def get_minimap_coor(analytics, img):
    ''' Finds the position of character in the minimap '''
    analytics.start_timer('get_minimap_coor', 'Finding minimap coordiantes')
    map_ = crop(img, (834, 577, 183, 183))
    img = cv2.inRange(map_, (200, 200, 200), (255, 255, 255))
    contours, _ = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    if contours == []:
        raise NoCharacterInMinimap
    box = sorted(contours, key=cv2.contourArea, reverse=True)[0]
    coor = find_center(cv2.boundingRect(box))
    analytics.end_timer('get_minimap_coor')
    return coor
コード例 #6
0
ファイル: training_data.py プロジェクト: anchalghale/sultan
def export_data(label_input, change_img, img, rect):
    ''' Asks for label value and writes to file '''
    img = crop(img, rect)
    img_rgb = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    tk_img = ImageTk.PhotoImage(image=Image.fromarray(img_rgb))
    change_img(tk_img)
    label = label_input()
    if label == 'exit':
        raise Exception
    if label in ['', None]:
        return
    cv2.imwrite(name(label), img)
コード例 #7
0
def get_attack_speed(image, models):
    '''Finds attack speed'''
    img = crop(image, (244, 740, 5, 6))
    img = cv2.resize(img, (7, 9))
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    hundred = models['gold'].predict(img)

    img = crop(image, (251, 740, 5, 6))
    img = cv2.resize(img, (7, 9))
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    tens = models['gold'].predict(img)

    img = crop(image, (256, 740, 5, 6))
    img = cv2.resize(img, (7, 9))
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

    ones = models['gold'].predict(img)
    try:
        return int(str(hundred) + str(tens) + str(ones)) / 100
    except ValueError:
        return -1
コード例 #8
0
ファイル: champion.py プロジェクト: anchalghale/sultan
def get_champion(img, models):
    '''Finds the selected champion'''
    img = crop(img, (330, 720, 20, 20))
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    return CHAMPIONS_MAPPING[models['champion'].predict(img)]
コード例 #9
0
ファイル: items.py プロジェクト: anchalghale/sultan
 def prepare(image, rect):
     img = crop(image, rect)
     img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
     return img
コード例 #10
0
ファイル: sums.py プロジェクト: anchalghale/sultan
 def predict(img, rect, key):
     nonlocal spells
     img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
     img = crop(img, rect)
     spell = MAPPING[models['summoner_spell'].predict(img)]
     spells[spell] = {'spell': spell, 'key': key}