@@ -59,12 +59,14 @@ def get_objects_summary(predictions: List[Dict]):
59
59
}
60
60
61
61
62
- def post_image (url : str , image : bytes , api_key : str , timeout : int , data : dict = {}):
62
+ def post_image (
63
+ url : str , image_bytes : bytes , api_key : str , timeout : int , data : dict = {}
64
+ ):
63
65
"""Post an image to Deepstack."""
64
66
try :
65
67
data ["api_key" ] = api_key
66
68
response = requests .post (
67
- url , files = {"image" : image }, data = data , timeout = timeout
69
+ url , files = {"image" : image_bytes }, data = data , timeout = timeout
68
70
)
69
71
return response
70
72
except requests .exceptions .Timeout :
@@ -96,13 +98,8 @@ def __init__(
96
98
self ._timeout = timeout
97
99
self ._predictions = []
98
100
99
- def process_file (self , file_path : str ):
100
- """Process an image file."""
101
- with open (file_path , "rb" ) as image_bytes :
102
- self .process_image_bytes (image_bytes )
103
-
104
- def process_image_bytes (self , image_bytes : bytes ):
105
- """Process an image, performing detection."""
101
+ def detect (self , image_bytes : bytes ):
102
+ """Process image_bytes, performing detection."""
106
103
self ._predictions = []
107
104
url = self ._url_detection .format (self ._ip_address , self ._port )
108
105
@@ -150,19 +147,18 @@ def __init__(
150
147
ip_address , port , api_key , timeout , url_detection = URL_FACE_DETECTION
151
148
)
152
149
153
- def register_face (self , name : str , file_path : str ):
150
+ def register_face (self , name : str , image_bytes : bytes ):
154
151
"""
155
152
Register a face name to a file.
156
153
"""
157
154
158
- with open (file_path , "rb" ) as image :
159
- response = post_image (
160
- url = URL_FACE_REGISTRATION .format (self ._ip_address , self ._port ),
161
- image = image ,
162
- api_key = self ._api_key ,
163
- timeout = self ._timeout ,
164
- data = {"userid" : name },
165
- )
155
+ response = post_image (
156
+ url = URL_FACE_REGISTRATION .format (self ._ip_address , self ._port ),
157
+ image_bytes = image_bytes ,
158
+ api_key = self ._api_key ,
159
+ timeout = self ._timeout ,
160
+ data = {"userid" : name },
161
+ )
166
162
167
163
if response .status_code == 200 and response .json ()["success" ] == True :
168
164
print ("Taught face {} using file {}" .format (name , file_path ))
0 commit comments