diff --git a/README.md b/README.md index 305eca9..71afafe 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/SmashDataCollector.py b/SmashDataCollector.py index 7880c72..b3e788f 100644 --- a/SmashDataCollector.py +++ b/SmashDataCollector.py @@ -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 ---# @@ -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 diff --git a/customizable.py b/customizable.py index 789e31d..ade08a0 100644 --- a/customizable.py +++ b/customizable.py @@ -1,6 +1,6 @@ -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 @@ -8,7 +8,7 @@ # 2 for French, Spanish or German # 3 for Chinese (traditional or simplified) LANGUAGE = 1 -LIVES = 3 +LIVES = 1 TAKEN_GIVEN_DMG_THRESHOLD = 30 \ No newline at end of file diff --git a/data/demo-0/2020123112040000_c.jpg b/data/demo-0/2020123112040000_c.jpg new file mode 100644 index 0000000..8802b94 Binary files /dev/null and b/data/demo-0/2020123112040000_c.jpg differ diff --git a/data/demo-0/2020123112041500_c.jpg b/data/demo-0/2020123112041500_c.jpg new file mode 100644 index 0000000..a07bba9 Binary files /dev/null and b/data/demo-0/2020123112041500_c.jpg differ diff --git a/data/demo-0/2020123112050500_c.jpg b/data/demo-0/2020123112050500_c.jpg new file mode 100644 index 0000000..13db9fd Binary files /dev/null and b/data/demo-0/2020123112050500_c.jpg differ diff --git a/data/demo-0/2020123112050900_c.jpg b/data/demo-0/2020123112050900_c.jpg new file mode 100644 index 0000000..e5f96a8 Binary files /dev/null and b/data/demo-0/2020123112050900_c.jpg differ diff --git a/data/demo-0/2020123112070900_c.jpg b/data/demo-0/2020123112070900_c.jpg new file mode 100644 index 0000000..9effffc Binary files /dev/null and b/data/demo-0/2020123112070900_c.jpg differ diff --git a/data/demo-0/2020123112071800_c.jpg b/data/demo-0/2020123112071800_c.jpg new file mode 100644 index 0000000..6aed12e Binary files /dev/null and b/data/demo-0/2020123112071800_c.jpg differ diff --git a/data/demo-0/2020123112080300_c.jpg b/data/demo-0/2020123112080300_c.jpg new file mode 100644 index 0000000..0a35db7 Binary files /dev/null and b/data/demo-0/2020123112080300_c.jpg differ diff --git a/data/demo-0/2020123112081100_c.jpg b/data/demo-0/2020123112081100_c.jpg new file mode 100644 index 0000000..ba1ce9b Binary files /dev/null and b/data/demo-0/2020123112081100_c.jpg differ diff --git a/data/demo-0/2020123112220700_c.jpg b/data/demo-0/2020123112220700_c.jpg new file mode 100644 index 0000000..4974142 Binary files /dev/null and b/data/demo-0/2020123112220700_c.jpg differ diff --git a/data/demo-0/2020123112221100_c.jpg b/data/demo-0/2020123112221100_c.jpg new file mode 100644 index 0000000..0d2a990 Binary files /dev/null and b/data/demo-0/2020123112221100_c.jpg differ diff --git a/data/2020121110511900_c.jpg b/data/demo-1/2020121110511900_c.jpg similarity index 100% rename from data/2020121110511900_c.jpg rename to data/demo-1/2020121110511900_c.jpg diff --git a/data/2020121110513400_c.jpg b/data/demo-1/2020121110513400_c.jpg similarity index 100% rename from data/2020121110513400_c.jpg rename to data/demo-1/2020121110513400_c.jpg diff --git a/data/2020121110552100_c.jpg b/data/demo-1/2020121110552100_c.jpg similarity index 100% rename from data/2020121110552100_c.jpg rename to data/demo-1/2020121110552100_c.jpg diff --git a/data/2020121110554800_c.jpg b/data/demo-1/2020121110554800_c.jpg similarity index 100% rename from data/2020121110554800_c.jpg rename to data/demo-1/2020121110554800_c.jpg diff --git a/data/2020121115520500_c.jpg b/data/demo-1/2020121115520500_c.jpg similarity index 100% rename from data/2020121115520500_c.jpg rename to data/demo-1/2020121115520500_c.jpg diff --git a/data/2020121115522000_c.jpg b/data/demo-1/2020121115522000_c.jpg similarity index 100% rename from data/2020121115522000_c.jpg rename to data/demo-1/2020121115522000_c.jpg diff --git a/data/demo-1/2020123112014300_c.jpg b/data/demo-1/2020123112014300_c.jpg new file mode 100644 index 0000000..279a61c Binary files /dev/null and b/data/demo-1/2020123112014300_c.jpg differ diff --git a/data/demo-1/2020123112015500_c.jpg b/data/demo-1/2020123112015500_c.jpg new file mode 100644 index 0000000..c6b78c8 Binary files /dev/null and b/data/demo-1/2020123112015500_c.jpg differ diff --git a/data/demo-2/2020123112100700_c.jpg b/data/demo-2/2020123112100700_c.jpg new file mode 100644 index 0000000..172fb81 Binary files /dev/null and b/data/demo-2/2020123112100700_c.jpg differ diff --git a/data/demo-2/2020123112101400_c.jpg b/data/demo-2/2020123112101400_c.jpg new file mode 100644 index 0000000..6c8b61a Binary files /dev/null and b/data/demo-2/2020123112101400_c.jpg differ diff --git a/data/demo-2/2020123112141000_c.jpg b/data/demo-2/2020123112141000_c.jpg new file mode 100644 index 0000000..957ccee Binary files /dev/null and b/data/demo-2/2020123112141000_c.jpg differ diff --git a/data/demo-2/2020123112141500_c.jpg b/data/demo-2/2020123112141500_c.jpg new file mode 100644 index 0000000..00c6acb Binary files /dev/null and b/data/demo-2/2020123112141500_c.jpg differ diff --git a/data/demo-2/2020123112270300_c.jpg b/data/demo-2/2020123112270300_c.jpg new file mode 100644 index 0000000..1d7bbab Binary files /dev/null and b/data/demo-2/2020123112270300_c.jpg differ diff --git a/data/demo-2/2020123112270800_c.jpg b/data/demo-2/2020123112270800_c.jpg new file mode 100644 index 0000000..e854323 Binary files /dev/null and b/data/demo-2/2020123112270800_c.jpg differ diff --git a/data/demo-3/2020123112164100_c.jpg b/data/demo-3/2020123112164100_c.jpg new file mode 100644 index 0000000..aa18a28 Binary files /dev/null and b/data/demo-3/2020123112164100_c.jpg differ diff --git a/data/demo-3/2020123112164900_c.jpg b/data/demo-3/2020123112164900_c.jpg new file mode 100644 index 0000000..d468b69 Binary files /dev/null and b/data/demo-3/2020123112164900_c.jpg differ diff --git a/data/demo-3/2020123112183500_c.jpg b/data/demo-3/2020123112183500_c.jpg new file mode 100644 index 0000000..8aad195 Binary files /dev/null and b/data/demo-3/2020123112183500_c.jpg differ diff --git a/data/demo-3/2020123112184100_c.jpg b/data/demo-3/2020123112184100_c.jpg new file mode 100644 index 0000000..7caa072 Binary files /dev/null and b/data/demo-3/2020123112184100_c.jpg differ diff --git a/data/demo-4/2020123112120400_c.jpg b/data/demo-4/2020123112120400_c.jpg new file mode 100644 index 0000000..d2699e7 Binary files /dev/null and b/data/demo-4/2020123112120400_c.jpg differ diff --git a/data/demo-4/2020123112120900_c.jpg b/data/demo-4/2020123112120900_c.jpg new file mode 100644 index 0000000..e3968e2 Binary files /dev/null and b/data/demo-4/2020123112120900_c.jpg differ diff --git a/data/demo-4/2020123112245800_c.jpg b/data/demo-4/2020123112245800_c.jpg new file mode 100644 index 0000000..605eda5 Binary files /dev/null and b/data/demo-4/2020123112245800_c.jpg differ diff --git a/data/demo-4/2020123112250200_c.jpg b/data/demo-4/2020123112250200_c.jpg new file mode 100644 index 0000000..7289248 Binary files /dev/null and b/data/demo-4/2020123112250200_c.jpg differ diff --git a/functions.py b/functions.py index 7000655..93ad5cb 100644 --- a/functions.py +++ b/functions.py @@ -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" diff --git a/output.tsv b/output.tsv deleted file mode 100644 index 872070a..0000000 --- a/output.tsv +++ /dev/null @@ -1,3 +0,0 @@ - - -11/12/2020 3 Donkey Kong 2 3,2,2 69 69 83 Meta Knight 1 1,3 76 72 Young Link 3 1,2,2 57 63 77 \ No newline at end of file diff --git a/output/output-0.tsv b/output/output-0.tsv new file mode 100644 index 0000000..05dcd6c --- /dev/null +++ b/output/output-0.tsv @@ -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 \ No newline at end of file diff --git a/output/output-1.tsv b/output/output-1.tsv new file mode 100644 index 0000000..32baf88 --- /dev/null +++ b/output/output-1.tsv @@ -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 \ No newline at end of file diff --git a/output/output-2.tsv b/output/output-2.tsv new file mode 100644 index 0000000..092722d --- /dev/null +++ b/output/output-2.tsv @@ -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 \ No newline at end of file diff --git a/output/output-3.tsv b/output/output-3.tsv new file mode 100644 index 0000000..63c2810 --- /dev/null +++ b/output/output-3.tsv @@ -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 \ No newline at end of file diff --git a/output/output-4.tsv b/output/output-4.tsv new file mode 100644 index 0000000..1f981e3 --- /dev/null +++ b/output/output-4.tsv @@ -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 \ No newline at end of file diff --git a/resources.py b/resources.py index 81cf47d..4ff1c2b 100644 --- a/resources.py +++ b/resources.py @@ -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]), diff --git a/useful_code/test.py b/useful_code/test.py index b21dc47..eb587c4 100644 --- a/useful_code/test.py +++ b/useful_code/test.py @@ -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...') \ No newline at end of file +# 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...') \ No newline at end of file