forked from raysandeep/FMIYC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawsFuncs.py
38 lines (37 loc) · 1.41 KB
/
awsFuncs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import boto3
"""
framePath: path to frame image
return: list of 3-tuples of the form (celebrity Name, Confidence, URL)
obtain list of all the celebrities in the frame with the confidence level
"""
def getCelebsFromFrame(frame):
client=boto3.client('rekognition')
with open(frame, 'rb') as image:
response = client.recognize_celebrities(Image={'Bytes': image.read()})
celebs=[]
for celebrity in response['CelebrityFaces']:
if len(celebrity['Urls']) > 0 and 'imdb' in celebrity['Urls'][0]:
url = celebrity['Urls'][0]
else:
url = None
celebs.append( (celebrity['Name'], celebrity['MatchConfidence'], url) )
print(celebs)
return celebs
"""
frame: path to jpg or png screencap
return: string of text in the image (or a list if necessary)
analyze frame and retrieve all relevant text from it
"""
def getTextFromFrame(frame):
client=boto3.client('rekognition')
with open(frame, 'rb') as image:
response = client.detect_text(Image={'Bytes': image.read()})
textDetections=response['TextDetections']
combinedText = []
for text in textDetections:
#print ('Detected text:' + text['DetectedText'])
#print ('Confidence: ', text['Confidence'])
#print ('Type:' + text['Type'])
if text['Confidence'] > 85 and text['Type'] == 'WORD':
combinedText.append(text['DetectedText'])
return ' '.join(combinedText)