in code_examples/python_examples/stored_video/python-rek-video.py [0:0]
def main(self):
jobFound = False
sqs = boto3.client('sqs')
# Change active start function for the desired analysis. Also change the GetResults function later in this code.
#=====================================
response = self.rek.start_label_detection(Video={'S3Object': {'Bucket': self.bucket, 'Name': self.video}},
NotificationChannel={'RoleArn': self.roleArn, 'SNSTopicArn': self.topicArn})
#response = self.rek.start_face_detection(Video={'S3Object':{'Bucket':self.bucket,'Name':self.video}},
# NotificationChannel={'RoleArn':self.roleArn, 'SNSTopicArn':self.topicArn})
#response = self.rek.start_face_search(Video={'S3Object':{'Bucket':self.bucket,'Name':self.video}},
# CollectionId='CollectionId',
# NotificationChannel={'RoleArn':self.roleArn, 'SNSTopicArn':self.topicArn})
#response = self.rek.start_person_tracking(Video={'S3Object':{'Bucket':self.bucket,'Name':self.video}},
# NotificationChannel={'RoleArn':self.roleArn, 'SNSTopicArn':self.topicArn})
#response = self.rek.start_celebrity_recognition(Video={'S3Object':{'Bucket':self.bucket,'Name':self.video}},
# NotificationChannel={'RoleArn':self.roleArn, 'SNSTopicArn':self.topicArn})
#response = self.rek.start_content_moderation(Video={'S3Object':{'Bucket':self.bucket,'Name':self.video}},
# NotificationChannel={'RoleArn':self.roleArn, 'SNSTopicArn':self.topicArn})
#=====================================
print('Start Job Id: ' + response['JobId'])
dotLine=0
while jobFound == False:
sqsResponse = sqs.receive_message(QueueUrl=self.queueUrl, MessageAttributeNames=['ALL'],
MaxNumberOfMessages=10)
if sqsResponse:
if 'Messages' not in sqsResponse:
if dotLine<20:
print('.', end='')
dotLine=dotLine+1
else:
print()
dotLine=0
sys.stdout.flush()
continue
for message in sqsResponse['Messages']:
notification = json.loads(message['Body'])
rekMessage = json.loads(notification['Message'])
print(rekMessage['JobId'])
print(rekMessage['Status'])
if str(rekMessage['JobId']) == response['JobId']:
print('Matching Job Found:' + rekMessage['JobId'])
jobFound = True
#Change to match the start function earlier in this code.
#=============================================
self.GetResultsLabels(rekMessage['JobId'])
#self.GetResultsFaces(rekMessage['JobId'])
#self.GetResultsFaceSearchCollection(rekMessage['JobId'])
#self.GetResultsPersons(rekMessage['JobId'])
#self.GetResultsCelebrities(rekMessage['JobId'])
#self.GetResultsModerationLabels(rekMessage['JobId'])
#=============================================
sqs.delete_message(QueueUrl=self.queueUrl,
ReceiptHandle=message['ReceiptHandle'])
else:
print("Job didn't match:" +
str(rekMessage['JobId']) + ' : ' + str(response['JobId']))
# Delete the unknown message. Consider sending to dead letter queue
sqs.delete_message(QueueUrl=self.queueUrl,
ReceiptHandle=message['ReceiptHandle'])
print('done')