-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
executable file
·48 lines (38 loc) · 1.42 KB
/
client.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
import asyncio
from io import BytesIO
import grpc
from PIL import Image
import cv2
from ms_faceRecognition_pb2 import FaceRecognitionRequest, FaceRecognitionInferenceReply, FaceRecognitionWithRectListRequest
from ms_faceRecognition_pb2_grpc import FaceRecognitionServiceStub
import logging
from pprint import pformat
import numpy as np
import json
async def main():
async with grpc.aio.insecure_channel("[::]:50054") as channel:
stub = FaceRecognitionServiceStub(channel)
# QRCode Decode
'''
img = Image.open("test_images/qrCode_multiple.png")
img_byte_arr = BytesIO()
img.save(img_byte_arr, format='PNG', subsampling=0, quality=100)
img_byte_arr = img_byte_arr.getvalue()
res: QRCodeContent = await stub.QRCodeDecode(
InferenceRequest(image=img_byte_arr)
)
print(res.content)
json_res = json.loads(res.content)
print(json_res)
'''
img = Image.open("double.jpg")
img_byte_arr = BytesIO()
img.save(img_byte_arr, format='PNG', subsampling=0, quality=100)
img_byte_arr = img_byte_arr.getvalue()
npimg = cv2.imdecode(np.frombuffer(img_byte_arr, np.uint8), -1)
res: FaceRecognitionInferenceReply = await stub.FastInferenceWithDetection(
FaceRecognitionRequest(image=img_byte_arr)
)
print(res)
if __name__ == "__main__":
asyncio.run(main())