in broadcast-monitoring/src/team_detection/app/team_text_check.py [0:0]
def detect_team_from_text_in_image(team_info, detected_words):
"""
:param detected_text_response: see https://docs.aws.amazon.com/rekognition/latest/dg/API_DetectText.html
[
{
"Confidence": number,
"DetectedText": "string",
"Geometry": {
"BoundingBox": {
"Height": number,
"Left": number,
"Top": number,
"Width": number
},
"Polygon": [
{
"X": number,
"Y": number
}
]
},
"Id": number,
"ParentId": number,
"Type": "string"
},
...
]
:return: {
"team_id": [
{
"id": "string",
"name": "string",
"text_detected": "string",
"confidence": Decimal,
"bb": {
"Width": Decimal,
"Height": Decimal,
"Left": Decimal,
"Top": Decimal
}
}
],
...
}
"""
teams_found = defaultdict(list)
for result in [el for el in detected_words if el['Type'] == 'WORD']:
detected_text = result['DetectedText']
team_found = None
if team_info.abbr_exists(detected_text):
team_found = team_info.get_team_from_abbr(detected_text)
elif team_info.team_exists(detected_text.lower()):
team_found = team_info.get_team(detected_text.lower())
if team_found is not None:
logger.info(f'found team: {team_found.name} from text: {detected_text}')
teams_found[team_found.team_id].append({
'id': team_found.team_id,
'name': team_found.name,
'text_detected': detected_text,
'confidence': Decimal(str(result['Confidence'])),
'bb': convert_dict_float_to_dec(result['Geometry']['BoundingBox'])
})
logger.info(json.dumps(teams_found, indent=2, cls=DecimalEncoder))
return teams_found