1010from PIL import Image
1111from io import BytesIO
1212
13+ import json
14+
1315class FaceImageServicer (aws_rekognition_pb2_grpc .FaceImageServicer ):
1416 def RequestFaceCoordinate (self , request , context ):
1517 print ('we got something' )
1618 response = aws_rekognition_pb2 .FaceCoordinateResponse ()
1719 stream = BytesIO (request .faceImage )
1820 image = Image .open (stream ).convert ("RGBA" )
1921 stream .close ()
20-
21- # image.show()
22- # print("show image")
2322
2423 imagesize = [image .size [0 ],image .size [1 ]]
2524
26- bucket = "rkfaceimage"
27- region = "us-east-2"
25+ print ("Reading configs" )
26+
27+ with open ("../../client/config/config.json" ) as f :
28+ AWSKEY = json .load (f )['AWSRekognition' ]
2829
29- s3Client = boto3 .client ("s3" , region )
30+ bucket = AWSKEY ['BUCKET' ]
31+ region = AWSKEY ['REGION' ]
32+ accessid = AWSKEY ['AWSACCESSKEYID' ]
33+ secretkey = AWSKEY ['AWSSECRETKEY' ]
34+
35+ print ("Creating clients" )
36+
37+ s3Client = boto3 .client (
38+ "s3" ,
39+ aws_access_key_id = accessid ,
40+ aws_secret_access_key = secretkey ,
41+ region_name = region
42+ )
43+ rekognitionClient = boto3 .client (
44+ "rekognition" ,
45+ aws_access_key_id = accessid ,
46+ aws_secret_access_key = secretkey ,
47+ region_name = region
48+ )
49+
50+ print ("Going to do stuff with client" )
3051 imgnames = get_image_names (s3Client , bucket )
3152 print (imgnames )
32- faces = get_face_coordinates (request .faceImage , imgnames , bucket , region )
53+ faces = get_face_coordinates (rekognitionClient , request .faceImage , imgnames , bucket , region )
3354 print (faces )
3455 for facename , faceBB in faces :
3556 face = response .faces .add ()
@@ -39,9 +60,11 @@ def RequestFaceCoordinate(self, request, context):
3960
4061
4162def get_image_names (client , bucket ):
63+ # print("In image names")
4264 response = client .list_objects_v2 (
4365 Bucket = bucket
4466 )
67+ # print(response)
4568 contents = response ['Contents' ]
4669 imgnames = [obj ["Key" ] for obj in contents ]
4770 return imgnames
@@ -55,9 +78,7 @@ def get_bounding_box(name, bb, iz):
5578 return [name ,lx ,ly ,rx ,ry ]
5679
5780
58- def get_face_coordinates (target , source , bucket , region ):
59- client = boto3 .client ('rekognition' , region )
60-
81+ def get_face_coordinates (client , target , source , bucket , region ):
6182 cid = "faces"
6283 client .create_collection (
6384 CollectionId = cid
@@ -103,6 +124,21 @@ def get_face_coordinates(target, source, bucket, region):
103124
104125
105126def main ():
127+ # with open("../../client/config/config.json") as f:
128+ # AWSKEY = json.load(f)['AWSRekognition']
129+ # bucket = AWSKEY['BUCKET']
130+ # region = AWSKEY['REGION']
131+ # accessid = AWSKEY['AWSACCESSKEYID']
132+ # secretkey = AWSKEY['AWSSECRETKEY']
133+ # s3Client = boto3.client(
134+ # "s3",
135+ # aws_access_key_id=accessid,
136+ # aws_secret_access_key=secretkey,
137+ # region_name=region
138+ # )
139+ # get_image_names(s3Client, bucket)
140+
141+
106142 server = grpc .server (futures .ThreadPoolExecutor (max_workers = 10 ))
107143 aws_rekognition_pb2_grpc .add_FaceImageServicer_to_server (FaceImageServicer (), server )
108144 print ("server started" )
0 commit comments