@@ -59,12 +59,14 @@ def get_objects_summary(predictions: List[Dict]):
5959 }
6060
6161
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+ ):
6365 """Post an image to Deepstack."""
6466 try :
6567 data ["api_key" ] = api_key
6668 response = requests .post (
67- url , files = {"image" : image }, data = data , timeout = timeout
69+ url , files = {"image" : image_bytes }, data = data , timeout = timeout
6870 )
6971 return response
7072 except requests .exceptions .Timeout :
@@ -96,13 +98,8 @@ def __init__(
9698 self ._timeout = timeout
9799 self ._predictions = []
98100
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."""
106103 self ._predictions = []
107104 url = self ._url_detection .format (self ._ip_address , self ._port )
108105
@@ -150,19 +147,18 @@ def __init__(
150147 ip_address , port , api_key , timeout , url_detection = URL_FACE_DETECTION
151148 )
152149
153- def register_face (self , name : str , file_path : str ):
150+ def register_face (self , name : str , image_bytes : bytes ):
154151 """
155152 Register a face name to a file.
156153 """
157154
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+ )
166162
167163 if response .status_code == 200 and response .json ()["success" ] == True :
168164 print ("Taught face {} using file {}" .format (name , file_path ))
0 commit comments