Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use Amazon Rekognition to detect world strength from captured images of Smash Bros SPECIAL. DETAIL: https://michimani.net/post/aws-extract-value-of-smash-blos-sp-power-by-rekognition/
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 = img.read()
return image_bytes
def detect_text(image_path):
image_bytes = get_bytes_of_image(image_path)
return reko.detect_text(
Image={
'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)
print(smash_power)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.