-
Notifications
You must be signed in to change notification settings - Fork 0
/
resultsDetect.py
64 lines (49 loc) · 2.28 KB
/
resultsDetect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'''
Given an image from the results screen, this script is used to determine each player's rankings
and other stats, given the list of players in the game (determined by selectDetect.py) as input
and modifies each player's 'rank' field with the proper position
Authors: Thomas Richards and Nick Konz
Date Modified: 12/26/2019
'''
import os
import numpy as np
from collections import OrderedDict
import textRecognition.googleText as goog
from textRecognition.game import Game
from textRecognition.player import Player
import objectRecognition.objDetModelHelper as objDetect
from objectRecognition.rankDetector.rankGame import rankGame
curDir = os.path.dirname(__file__)
resultsScreenDir = os.path.join(curDir,'objectRecognition', 'rankDetector', 'inputFolder')
resultsImagePath = os.path.join(resultsScreenDir, 'realResults0.png')
# Assigns the ranks depicted in the screenshot of the provided results screen to the input game
def assignRanks(imagePath, game, printing=False, showing=False):
if printing:
print('Analyzing Results Screen')
sortedRanks = rankGame(imagePath, draw_output=showing) # IMPORTANT: Ranks must be pre-sorted in ascending player order
# TODO: Make this work for a CPU
def playerOrder(player):
if player.playerNum == 'CPU':
return -1
return int(player.playerNum[1]) # Returns only the 1 in the playerNum 'P1'
sortedPlayers = sorted(game.players, key=playerOrder)
for i, player in enumerate(sortedPlayers):
player.rank = sortedRanks[i]
#
# for playerNum, rank in enumerate(sortedRanks, 1): # Search through playerNumbers starting at 1
# for player in game.players:
# if player.playerNum == 'P{}'.format(playerNum):
# player.rank = rank
# break # Breaks out of the inner loop -> next rank
return game
if __name__ == '__main__':
BEEF = Player('BEEF', 'HERO', 'P1', None)
BIRD = Player('BIRD', 'Ike', 'P2', None)
LONG = Player('LONG', 'Villager', 'P3', None)
THOMATO = Player('THOMATO', 'Marth', 'P4', None)
sampleGame = Game([THOMATO, BEEF, LONG, BIRD])
print('Before analysis')
sampleGame.printOut()
assignRanks(resultsImagePath, sampleGame, showing=True)
print('\nAfter analysis')
sampleGame.printOut()