-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrekognition-process.py
93 lines (81 loc) · 3.21 KB
/
rekognition-process.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import boto3
import json
import argparse
import sys
parser = argparse.ArgumentParser(description='video stream processor helper for face recognition')
parser.add_argument('-c', '--create', action='store_true', help='create vidoe stream processor')
parser.add_argument('-s', '--start', action='store_true', help='start vidoe stream processor')
parser.add_argument('-q', '--stop', action='store_true', help='stop vidoe stream processor')
parser.add_argument('-d', '--delete', action='store_true', help='delete vidoe stream processor')
# inital
def createStreamProcessorHelper(streamProcessor, kinesisVideoStreamName, kinesisDataStream, collectionId, iamRole):
# aws accountID
stsClient = session.client('sts')
accountID = stsClient.get_caller_identity()["Account"]
# Get KinesisVideoStream Arn
kvClient = session.client('kinesisvideo')
kinesisVideoStreamArn = kvClient.describe_stream(StreamName=kinesisVideoStreamName)['StreamInfo']['StreamARN']
kinesisDataStreamArn = 'arn:aws:kinesis:' + region + ':' + accountID + ':stream/' + kinesisDataStream
roleArn = 'arn:aws:iam::' + accountID + ':role/' + iamRole
createStreamProcessor(streamProcessor, kinesisVideoStreamArn, kinesisDataStreamArn, collectionId, roleArn)
def createStreamProcessor(streamProcessor, kinesisVideoStreamArn, kinesisDataStreamArn, collectionId, roleArn):
response = rekClient.create_stream_processor(
Input={
'KinesisVideoStream': {
'Arn': kinesisVideoStreamArn
}
},
Output={
'KinesisDataStream': {
'Arn': kinesisDataStreamArn
}
},
Name=streamProcessor,
Settings={
'FaceSearch': {
'CollectionId': collectionId,
'FaceMatchThreshold': 70.0
}
},
RoleArn=roleArn
)
print(response)
def startStreamProcessor(streamProcessor):
response = rekClient.start_stream_processor(
Name=streamProcessor
)
print(response)
def stopStreamProcess(streamProcessor):
response = rekClient.stop_stream_processor(
Name=streamProcessor
)
print(response)
def delStreamProcess(streamProcessor):
response = rekClient.delete_stream_processor(
Name=streamProcessor
)
print(response)
if __name__ == '__main__':
if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
with open('config.json') as json_data_file:
config = json.load(json_data_file)
# configuration global variable
region = config['region']
kinesisVideoStreamName = config['kinesisVideoStreamName']
kinesisDataStream = config['kinesisDataStreamName']
streamProcessor = config['streamProcessor']
collectionId = config['collectionId']
iamRole = config['iamRole']
session = boto3.Session()
rekClient = session.client('rekognition')
if (args.create):
createStreamProcessorHelper(streamProcessor, kinesisVideoStreamName, kinesisDataStream, collectionId, iamRole)
elif (args.start):
startStreamProcessor(streamProcessor)
elif (args.stop):
stopStreamProcess(streamProcessor)
elif (args.delete):
delStreamProcess(streamProcessor)