Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2020 04:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Use Amazon Rekognition to detect world strength from captured images of Smash Bros SPECIAL. DETAIL:
import boto3
import sys
reko = boto3.client('rekognition')
target_area = {
'A': {'X': 0.785039062, 'Y': 0.639347222},
'B': {'X': 0.950203125, 'Y': 0.639347222},
'C': {'X': 0.950203125, 'Y': 0.737263889},
'D': {'X': 0.785039062, 'Y': 0.737263889},
def get_bytes_of_image(image_path):
with open(image_path, mode='rb') as img:
image_bytes =
return image_bytes
def detect_text(image_path):
image_bytes = get_bytes_of_image(image_path)
return reko.detect_text(
'Bytes': image_bytes
def get_smash_power(image_path):
smash_power = '0'
detect_res = detect_text(image_path)
for detected in detect_res['TextDetections']:
polygon = detected['Geometry']['Polygon']
if polygon[0]['X'] > target_area['A']['X'] and polygon[0]['Y'] > target_area['A']['Y'] \
and polygon[1]['X'] < target_area['B']['X'] and polygon[1]['Y'] > target_area['B']['Y'] \
and polygon[2]['X'] < target_area['C']['X'] and polygon[2]['Y'] < target_area['C']['Y'] \
and polygon[3]['X'] > target_area['D']['X'] and polygon[3]['Y'] < target_area['D']['Y']:
smash_power = detected['DetectedText']
return smash_power
if __name__ == '__main__':
image_path = sys.argv[1]
smash_power = get_smash_power(image_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment