Skip to content

Commit 6da5217

Browse files
authored
Merge pull request #4 from exadel-inc/detect_service_and_testing
Detect service and testing
2 parents cfae156 + 2a6f7fe commit 6da5217

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1414
-156
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ Thumbs.db
9292
.history
9393
.ionide
9494

95+
96+
.vscode

Diff for: README.md

+424-102
Large diffs are not rendered by default.

Diff for: compreface/__pycache__/__init__.cpython-38.pyc

-213 Bytes
Binary file not shown.

Diff for: compreface/client/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3-
from .verify_face_from_image import VerifyFaceFromImageClient
3+
from .compare_face_from_image import CompareFaceFromImageClient
44
from .add_example_of_subject import AddExampleOfSubjectClient
55
from .delete_example_by_id import DeleteExampleByIdClient
66
from .recognize_face_from_image import RecognizeFaceFromImageClient
7+
from .detect_face_from_image import DetectFaceFromImageClient
8+
from .verify_face_from_image import VerifyFaceFromImageClient
-471 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Diff for: compreface/client/add_example_of_subject.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
from compreface.common.typed_dict import DetProbOptionsDict, check_fields_by_name
34
from compreface.config.api_list import RECOGNIZE_CRUD_API
45
import os
56
import requests
@@ -16,24 +17,59 @@ def __init__(self, api_key: str, domain: str, port: str):
1617
self.api_key: str = api_key
1718
self.url: str = domain + ':' + port + self.client_url
1819

20+
"""
21+
GET request for get all subjects.
22+
23+
:return: json with subjects from server.
24+
"""
25+
1926
def get(self) -> dict:
2027
url: str = self.url
2128
result = requests.get(url, headers={'x-api-key': self.api_key})
2229
return result.json()
2330

24-
def post(self, image_path: str = '', subject: str = '') -> dict:
31+
"""
32+
POST request for add subject from his face in image.
33+
34+
:param image_path: path to image in file system.
35+
:param subject: fullname
36+
:param options: dictionary with options for server.
37+
38+
:return: json with this subject from server.
39+
"""
40+
41+
def post(self, image_path: str = '', subject: str = '', options: DetProbOptionsDict = {}) -> dict:
2542
url: str = self.url + '?subject=' + subject
2643
name_img: str = os.path.basename(image_path)
44+
45+
# Validation loop and adding fields to the url.
46+
for key in options.keys():
47+
# Checks fields with necessary rules.
48+
# key - key field by options.
49+
check_fields_by_name(key, options[key])
50+
url += '&' + key + "=" + str(options[key])
51+
52+
# Encoding image from path and encode in multipart for sending to the server.
2753
m = MultipartEncoder(
2854
fields={'file': (name_img, open(image_path, 'rb'))}
2955
)
56+
57+
# Sending encode image for add subject.
3058
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
3159
'x-api-key': self.api_key})
3260
return result.json()
3361

3462
def put(self):
3563
pass
3664

65+
"""
66+
Delete request to CompreFace server.
67+
68+
:param subject: fullname
69+
70+
:return: json from server.
71+
"""
72+
3773
def delete(self, subject: str = ''):
3874
url: str = self.url + '?subject=' + subject
3975
result = requests.delete(url, headers={'x-api-key': self.api_key})

Diff for: compreface/client/compare_face_from_image.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
import requests
4+
from compreface.common.typed_dict import ExpandedOptionsDict, check_fields_by_name
5+
from compreface.config.api_list import RECOGNIZE_CRUD_API
6+
from requests_toolbelt.multipart.encoder import MultipartEncoder
7+
from ..common import ClientRequest
8+
9+
10+
class CompareFaceFromImageClient(ClientRequest):
11+
"""
12+
Compare face in image. It uses image path for encode and send to CompreFace
13+
server with validation by image id.
14+
"""
15+
16+
def __init__(self, api_key: str, domain: str, port: str):
17+
super().__init__()
18+
self.client_url: str = RECOGNIZE_CRUD_API
19+
self.api_key: str = api_key
20+
self.url: str = domain + ':' + port + self.client_url
21+
22+
def get(self):
23+
pass
24+
25+
"""
26+
POST request for compare face in image using image id.
27+
28+
:param image_path: Path to image in file system.
29+
:param image_id: subject id from previously added image.
30+
:param options: dictionary with options for server.
31+
32+
:return: json from server.
33+
"""
34+
35+
def post(self,
36+
image_path: str = '',
37+
image_id: str = '',
38+
options: ExpandedOptionsDict = {}) -> dict:
39+
40+
url: str = self.url + '/' + image_id + '/verify?'
41+
name_img: str = os.path.basename(image_path)
42+
# Validation loop and adding fields to the url.
43+
for key in options.keys():
44+
# Checks fields with necessary rules.
45+
# key - key field by options.
46+
check_fields_by_name(key, options[key])
47+
url += '&' + key + "=" + str(options[key])
48+
49+
# Encoding image from path and encode in multipart for sending to the server.
50+
m = MultipartEncoder(
51+
fields={'file': (name_img, open(image_path, 'rb'))}
52+
)
53+
54+
# Sending encode image for verify face.
55+
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
56+
'x-api-key': self.api_key})
57+
return result.json()
58+
59+
def put(self):
60+
pass
61+
62+
def delete(self):
63+
pass

Diff for: compreface/client/delete_example_by_id.py

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
class DeleteExampleByIdClient(ClientRequest):
1010

11+
"""
12+
Delete example by id from image_id.
13+
"""
14+
1115
def __init__(self, api_key: str, domain: str, port: str):
1216
super().__init__()
1317
self.client_url: str = RECOGNIZE_CRUD_API
@@ -23,6 +27,14 @@ def post(self):
2327
def put(self):
2428
pass
2529

30+
"""
31+
DELETE request to CompreFace server. Delete example by id from image_id.
32+
33+
:param image_id:
34+
35+
:return: json from server.
36+
"""
37+
2638
def delete(self, image_id: str = ''):
2739
url: str = self.url + '/' + image_id
2840
result = requests.delete(url, headers={'x-api-key': self.api_key})

Diff for: compreface/client/detect_face_from_image.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
import requests
3+
from compreface.common.typed_dict import AllOptionsDict, check_fields_by_name
4+
from ..common import ClientRequest
5+
from compreface.config.api_list import DETECTION_API
6+
from requests_toolbelt.multipart.encoder import MultipartEncoder
7+
8+
9+
class DetectFaceFromImageClient(ClientRequest):
10+
"""
11+
Detection faces in image. It uses image path for encode and send to CompreFace server.
12+
"""
13+
14+
def __init__(self, api_key: str, domain: str, port: str):
15+
super().__init__()
16+
self.client_url: str = DETECTION_API
17+
self.api_key: str = api_key
18+
self.url: str = domain + ':' + port + self.client_url
19+
20+
def get(self):
21+
pass
22+
23+
"""
24+
POST request for detection faces in image.
25+
26+
:param image_path: Path to image in file system.
27+
:param options: dictionary with options for server.
28+
29+
:return: json from server.
30+
"""
31+
32+
def post(self, image_path: str = '', options: AllOptionsDict = {}):
33+
url: str = self.url + '?'
34+
name_img: str = os.path.basename(image_path)
35+
36+
# Validation loop and adding fields to the url.
37+
for key in options.keys():
38+
# Checks fields with necessary rules.
39+
# key - key field by options.
40+
check_fields_by_name(key, options[key])
41+
url += '&' + key + "=" + str(options[key])
42+
43+
# Encoding image from path and encode in multipart for sending to the server.
44+
m = MultipartEncoder(
45+
fields={'file': (name_img, open(image_path, 'rb'))}
46+
)
47+
48+
# Sending encode image for detection faces.
49+
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
50+
'x-api-key': self.api_key})
51+
return result.json()
52+
53+
def put(self):
54+
pass
55+
56+
def delete(self):
57+
pass

Diff for: compreface/client/recognize_face_from_image.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
from compreface.common.typed_dict import ExpandedOptionsDict, check_fields_by_name
34
from compreface.config.api_list import RECOGNIZE_API
45
import os
56
import requests
@@ -9,6 +10,9 @@
910

1011

1112
class RecognizeFaceFromImageClient(ClientRequest):
13+
"""
14+
Recognize faces in image. It uses image path for encode and send to CompreFace server.
15+
"""
1216

1317
def __init__(self, api_key: str, domain: str, port: str):
1418
super().__init__()
@@ -19,12 +23,32 @@ def __init__(self, api_key: str, domain: str, port: str):
1923
def get(self):
2024
pass
2125

22-
def post(self, image_path: str = ''):
23-
url: str = self.url
26+
"""
27+
POST request for recognize faces in image.
28+
29+
:param image_path: Path to image in file system.
30+
:param options: dictionary with options for server.
31+
32+
:return: json from server.
33+
"""
34+
35+
def post(self, image_path: str = '', options: ExpandedOptionsDict = {}):
36+
url: str = self.url + "?"
2437
name_img: str = os.path.basename(image_path)
38+
39+
# Validation loop and adding fields to the url.
40+
for key in options.keys():
41+
# Checks fields with necessary rules.
42+
# key - key field by options.
43+
check_fields_by_name(key, options[key])
44+
url += '&' + key + "=" + str(options[key])
45+
46+
# Encoding image from path and encode in multipart for sending to the server.
2547
m = MultipartEncoder(
2648
fields={'file': (name_img, open(image_path, 'rb'))}
2749
)
50+
51+
# Sending encode image for recognize faces.
2852
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
2953
'x-api-key': self.api_key})
3054
return result.json()

Diff for: compreface/client/verify_face_from_image.py

+43-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,62 @@
1-
# -*- coding: utf-8 -*-
2-
3-
from compreface.config.api_list import RECOGNIZE_CRUD_API
4-
import os
51
import requests
6-
from requests_toolbelt.multipart.encoder import MultipartEncoder
2+
from compreface.config.api_list import VERIFICATION_API
3+
import os
74

8-
from ..common import ClientRequest
5+
from requests_toolbelt.multipart.encoder import MultipartEncoder
6+
from compreface.common.typed_dict import AllOptionsDict, check_fields_by_name
7+
from compreface.common.client import ClientRequest
98

109

1110
class VerifyFaceFromImageClient(ClientRequest):
11+
"""
12+
Verify face in image. It uses source and target images for encode and send to CompreFace
13+
server with validation by image id.
14+
"""
15+
1216
def __init__(self, api_key: str, domain: str, port: str):
1317
super().__init__()
14-
self.client_url: str = RECOGNIZE_CRUD_API
18+
self.client_url: str = VERIFICATION_API
1519
self.api_key: str = api_key
1620
self.url: str = domain + ':' + port + self.client_url
1721

1822
def get(self):
1923
pass
2024

25+
"""
26+
POST request for verify face in image using source and target images.
27+
28+
:param source_image_path: Path to source image in file system.
29+
:param target_image_path: Path to target image in file system.
30+
:param image_id: subject id from previously added image.
31+
:param options: dictionary with options for server.
32+
33+
:return: json from server.
34+
"""
35+
2136
def post(self,
22-
image_path: str = '',
23-
image_id: str = ''):
24-
url: str = self.url + '/' + image_id + '/verify'
25-
name_img: str = os.path.basename(image_path)
37+
source_image_path: str = '',
38+
target_image_path: str = '',
39+
options: AllOptionsDict = {}) -> dict:
40+
41+
url: str = self.url + '/verify?'
42+
source_name_img: str = os.path.basename(source_image_path)
43+
target_name_img: str = os.path.basename(target_image_path)
44+
# Validation loop and adding fields to the url.
45+
for key in options.keys():
46+
# Checks fields with necessary rules.
47+
# key - key field by options.
48+
check_fields_by_name(key, options[key])
49+
url += '&' + key + "=" + str(options[key])
50+
51+
# Encoding image from path and encode in multipart for sending to the server.
2652
m = MultipartEncoder(
27-
fields={'file': (name_img, open(image_path, 'rb'))}
53+
fields={'source_image': (source_name_img, open(
54+
source_image_path, 'rb')), 'target_image': (target_name_img, open(
55+
target_image_path, 'rb'))}
56+
2857
)
58+
59+
# Sending encode image for verify face.
2960
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
3061
'x-api-key': self.api_key})
3162
return result.json()

0 commit comments

Comments
 (0)