Skip to content

Commit

Permalink
1.1.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran314 committed Jan 1, 2021
1 parent 4a9da9a commit c646133
Show file tree
Hide file tree
Showing 44 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Now that you've customized the customizables, you're ready to run the script. Ju
After the script did its thing, it will give you a list of the problematic matches. The problematic matches are the matches that for some reason caused issues when trying to extrapolate the data (maybe had some issues when trying to find the anchor point for the scroll menu, or as with the Ice Climber case, the difference between the taken and given damage was too big and the script suspected that there was a mistake in reading the data). Do not worry as this could and will happen, as the script is not perfect. What will happen now is that you'll get prompts from the terminal to manually input the data yourself. For every problematic match you'll be shown the screenshots from the match and you'll be prompted to write the data manuall in the terminal. Just do what the terminal asks you to do and you'll be fine (this is not, in fact, a threat.)

### What now?
If everything went according to plans, you should now have your desired output! You can now Ctrl+C Ctrl+V the data from the output file to any spreadsheet you want. Here's a demo of the spreadsheet that I personally use to save and analyze the data. Feel free to customize it as needed!
If everything went according to plans, you should now have your desired output! You can now Ctrl+C Ctrl+V the data from the output file to any spreadsheet you want. [Here](https://docs.google.com/spreadsheets/d/1xbwun7a1vsP3P2eTPFk6MIKKevnX_Mfcridpy4F3Qms/edit?usp=sharing)'s a demo of the spreadsheet that I personally use to save and analyze the data. The demo spreadsheet currently has the data from the /data/demo folder that you'll find in the release. This data won't look like the data you'll collect yourself as those are only some quick matches that I played to show that the script works with every language, and not actual "competitive" matches. Feel free to customize the spreadsheet as needed!

## Restrictions
- **The script does not do skin recognition** (as in, you CAN use any skin you won't, but the script won't check which one you used, and will only check for which character you used). This means that any game with the same character played by two different players will give unreliable results, and would likely have to be manually added after the script ends. The problem is that instead of actually seeing that the match is unreadable and adding it to the problematic matches (to be manually added after the script), it might try to read it anyway and not flag it as problematic, giving unreliable results. I'm planning on adding a check that automatically adds the match to the problematic matches if the same character is used more than once, to avoid unreliable results. I am NOT planning on adding skin recognition as the only way to do it is having to make a third screenshot which would be actually pointless in most of the cases. The issue that I don't know how to solve is that for some characters, the skin used is mostly unrecogniseable from the first screenshot, which is the one used for character recognition.
Expand Down
15 changes: 12 additions & 3 deletions SmashDataCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@
times = []

#--- GET NUMBER OF PLAYERS ---#
players_colour = first_data[res.PLAYER_PIXEL]
players_amount = numpy.argmin([numpy.linalg.norm(players_colour - colour) for colour in res.PLAYER_COLOURS])+2
# players_colour = first_data[res.PLAYER_PIXEL]
# players_amount = numpy.argmin([numpy.linalg.norm(players_colour - colour) for colour in res.PLAYER_COLOURS])+2
players_amount = 0
for i in range(3):
if(all([numpy.linalg.norm(first_data[pixel]) < 20 for pixel in res.PLAYER_PIXELS[i]])):
players_amount = i+2
break
if(players_amount == 0):
error_message = f'unable to tell how many players'
raise fun.InvalidData


for curr_player_index in range(players_amount):
#--- GET PLAYER TYPE ---#
Expand Down Expand Up @@ -197,7 +206,7 @@
taken_given_dmg_difference = 0
for curr_player_index in range(players_amount):
taken_given_dmg_difference += taken_damages[curr_player_index] - given_damages[curr_player_index]
if(taken_given_dmg_difference < 0 or taken_given_dmg_difference >= custom.TAKEN_GIVEN_DMG_THRESHOLD):
if(taken_given_dmg_difference <= -custom.TAKEN_GIVEN_DMG_THRESHOLD or taken_given_dmg_difference >= custom.TAKEN_GIVEN_DMG_THRESHOLD):
error_message = f'too big of a difference between total taken damage and total given damage ({taken_given_dmg_difference})'
raise fun.InvalidData

Expand Down
6 changes: 3 additions & 3 deletions customizable.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
DATA_PATH = r'C:\Users\franc\Documents\VSCode\SmashDataCollector\data'
DATA_PATH = r'C:\Users\franc\Documents\VSCode\SmashDataCollector\data\demo-4'
RES_PATH = r'C:\Users\franc\Documents\VSCode\SmashDataCollector\res'
OUTPUT_PATH = r'C:\Users\franc\Documents\VSCode\SmashDataCollector\output.tsv'
OUTPUT_PATH = r'C:\Users\franc\Documents\VSCode\SmashDataCollector\output\output-4.tsv'

# Set the language variable to 0, 1 or 2 according to the following:
# 0 for Japanese or Korean
# 1 for English, Italian, Dutch or Russian
# 2 for French, Spanish or German
# 3 for Chinese (traditional or simplified)
LANGUAGE = 1
LIVES = 3
LIVES = 1


TAKEN_GIVEN_DMG_THRESHOLD = 30
Binary file added data/demo-0/2020123112040000_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112041500_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112050500_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112050900_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112070900_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112071800_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112080300_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112081100_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112220700_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-0/2020123112221100_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added data/demo-1/2020123112014300_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-1/2020123112015500_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-2/2020123112100700_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-2/2020123112101400_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-2/2020123112141000_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-2/2020123112141500_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-2/2020123112270300_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-2/2020123112270800_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-3/2020123112164100_c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/demo-3/2020123112164900_c.jpg
Binary file added data/demo-3/2020123112183500_c.jpg
Binary file added data/demo-3/2020123112184100_c.jpg
Binary file added data/demo-4/2020123112120400_c.jpg
Binary file added data/demo-4/2020123112120900_c.jpg
Binary file added data/demo-4/2020123112245800_c.jpg
Binary file added data/demo-4/2020123112250200_c.jpg
4 changes: 2 additions & 2 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ def convertMatchToString(file_name, characters, positions, times, falls, given_d
for i in range(players):
match_string += characters[i] + "\t"
match_string += str(positions[i]) + "\t"
match_string += time2string(times[i]) + "\t"
match_string += ','.join(map(str, falls[i])) + "\t"
match_string += str(given_damages[i]) + "\t"
match_string += str(taken_damages[i]) + "\t"
match_string += time2string(times[i])
match_string += str(taken_damages[i])
if(i < players - 1):
match_string += "\t"

Expand Down
3 changes: 0 additions & 3 deletions output.tsv

This file was deleted.

5 changes: 5 additions & 0 deletions output/output-0.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
31/12/2020 3 Toon Link 1 28 0 Sonic 2 3 1 0 13 Little Mac 3 1 1 0 14
31/12/2020 4 Toon Link 1 31 0 Marth 2 5 1 0 14 Ike 3 3 1 0 8 Shulk 3 3 1 0 8
31/12/2020 4 Toon Link 2 9 1 21 0 Mr. Game & Watch 4 0 1 0 13 Samus 1 0 0 Bayonetta 3 5 1 0 7
31/12/2020 2 Toon Link 1 10 0 Roy 2 2 1 0 10
31/12/2020 3 Toon Link 1 22 0 Richter 2 3 1 0 8 Zelda 3 1 1 0 13
4 changes: 4 additions & 0 deletions output/output-1.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
11/12/2020 2 Ganondorf 2 67 2,2,2 84 131 Kirby 1 1,1 130 88
11/12/2020 4 Palutena 3 99 2,2,2 147 87 Luigi 1 1,3 146 88 Inkling 2 130 1,2,2 41 73 Pac-Man 4 70 1,1,2 0 91
11/12/2020 3 Donkey Kong 2 83 3,2,2 69 69 Meta Knight 1 1,3 76 72 Young Link 3 77 1,2,2 57 63
31/12/2020 3 Toon Link 1 3 627 47 Duck Hunt 2 152 1,1,1 41 346 Cloud 3 119 1,1,1 18 297
3 changes: 3 additions & 0 deletions output/output-2.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
31/12/2020 3 Toon Link 1 22 0 Robin 2 4 1 0 8 R.O.B. 3 0 1 0 13
31/12/2020 3 Toon Link 1 22 0 Chrom 2 3 1 0 13 Meta Knight 3 1 1 0 8
31/12/2020 3 Toon Link 1 25 0 Roy 3 2 1 0 13 Zero Suit Samus 2 4 1 0 11
2 changes: 2 additions & 0 deletions output/output-3.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
31/12/2020 3 Toon Link 1 17 0 Captain Falcon 3 2 1 0 9 Cloud 2 5 1 0 8
31/12/2020 3 Toon Link 1 23 0 Donkey Kong 2 5 1 0 14 Peach 3 1 1 0 8
2 changes: 2 additions & 0 deletions output/output-4.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
31/12/2020 3 Toon Link 1 23 0 Lucario 3 3 1 0 14 Dark Samus 2 6 1 0 8
31/12/2020 3 Toon Link 1 23 0 Dark Pit 3 2 1 0 8 Ice Climbers 2 6 1 0 7
4 changes: 4 additions & 0 deletions resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
# "Player pixel" = the pixel sampled used to determine the number of players based on its colour
PLAYER_PIXEL = (657, 972)

PLAYER_PIXELS = [[(409, 179), (409, 705)],
[(409, 23), (409, 442), (409, 861)],
[(397, 4), (397, 324), (397, 644), (397, 964)]]

# PLAYERS_COLS[i] = The colour of the player pixel if there are [i+2] players
PLAYER_COLOURS = [numpy.array([150, 61, 0]),
numpy.array([0, 114, 144]),
Expand Down
52 changes: 27 additions & 25 deletions useful_code/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,32 @@
# [0, 125, 166],
# [22, 131, 22]]

RIGHT_EDGE = [423, 842, 1261]
LEFT_EDGE = [19, 438, 857]
print(numpy.linalg.norm([0, 4, 0]))

screenshots = os.listdir(r'C:\Users\franc\Desktop\aptest')
template_source = cv2.imread(r'C:\Users\franc\Documents\VSCode\SmashDataCollector\res\temp\template.png')
templates = [template_source[:, 0:8].copy(), template_source[:, 8:16].copy(), template_source[:, 16:24].copy()]
height = templates[0].shape[0]
span_range = int(height * 3.0 / 4.0)
# RIGHT_EDGE = [423, 842, 1261]
# LEFT_EDGE = [19, 438, 857]

for screenshot_file in screenshots:
screenshot_image = cv2.imread(os.path.join(r'C:\Users\franc\Desktop\aptest', screenshot_file))
for i in range(3):
subimage = screenshot_image[172 : 443, RIGHT_EDGE[i] - 19 : RIGHT_EDGE[i] - 11].copy()
distances = cv2.matchTemplate(subimage, templates[i], cv2.TM_CCOEFF_NORMED)
found = False
for j in range(distances.shape[0]):
upper_span = min(j, span_range)
lower_span = min(distances.shape[0] - j - 1, span_range)
region = distances[j - upper_span : j + lower_span]
if(numpy.argmax(region) == upper_span and
numpy.sum(fun.polarizeImage(screenshot_image[174 + j : 172 + j + height - 2, RIGHT_EDGE[i] - 19 - 20 : RIGHT_EDGE[i] - 19], 100)) == 0 and
numpy.sum(fun.polarizeImage(screenshot_image[174 + j + 74 : 172 + j + height - 2 + 74, RIGHT_EDGE[i] - 19 - 20 : RIGHT_EDGE[i] - 19], 100)) > 0):
fun.showImage(screenshot_image[172 + j : 172 + j + height, LEFT_EDGE[i] : RIGHT_EDGE[i]])
found = True
break
if(found == False):
print('Errr... couldn\'t find it...')
# screenshots = os.listdir(r'C:\Users\franc\Desktop\aptest')
# template_source = cv2.imread(r'C:\Users\franc\Documents\VSCode\SmashDataCollector\res\temp\template.png')
# templates = [template_source[:, 0:8].copy(), template_source[:, 8:16].copy(), template_source[:, 16:24].copy()]
# height = templates[0].shape[0]
# span_range = int(height * 3.0 / 4.0)

# for screenshot_file in screenshots:
# screenshot_image = cv2.imread(os.path.join(r'C:\Users\franc\Desktop\aptest', screenshot_file))
# for i in range(3):
# subimage = screenshot_image[172 : 443, RIGHT_EDGE[i] - 19 : RIGHT_EDGE[i] - 11].copy()
# distances = cv2.matchTemplate(subimage, templates[i], cv2.TM_CCOEFF_NORMED)
# found = False
# for j in range(distances.shape[0]):
# upper_span = min(j, span_range)
# lower_span = min(distances.shape[0] - j - 1, span_range)
# region = distances[j - upper_span : j + lower_span]
# if(numpy.argmax(region) == upper_span and
# numpy.sum(fun.polarizeImage(screenshot_image[174 + j : 172 + j + height - 2, RIGHT_EDGE[i] - 19 - 20 : RIGHT_EDGE[i] - 19], 100)) == 0 and
# numpy.sum(fun.polarizeImage(screenshot_image[174 + j + 74 : 172 + j + height - 2 + 74, RIGHT_EDGE[i] - 19 - 20 : RIGHT_EDGE[i] - 19], 100)) > 0):
# fun.showImage(screenshot_image[172 + j : 172 + j + height, LEFT_EDGE[i] : RIGHT_EDGE[i]])
# found = True
# break
# if(found == False):
# print('Errr... couldn\'t find it...')

0 comments on commit c646133

Please sign in to comment.