-
Notifications
You must be signed in to change notification settings - Fork 58
/
host_mode_enroll_image.py
78 lines (63 loc) · 2.34 KB
/
host_mode_enroll_image.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
License: Apache 2.0. See LICENSE file in root directory.
Copyright(c) 2020-2021 Intel Corporation. All Rights Reserved.
"""
"""
Example of extracting from image its faceprints for enrollment purposes
1. Set device config algo to all and high confidence and security levels
2. Sends resized image to device (120 width or height)
3. Prints the extracted features response from the device
"""
import sys
import cv2
import rsid_py
PORT = "/dev/ttyACM0"
def resize_to_120(cv_image):
height, width, channels = cv_image.shape
if width <= 120 and height <= 120:
return cv_image
if width > height:
new_width = 120
scale_h = new_width / width
new_height = int(height * scale_h)
else:
new_height = 120
scale_w = new_height / height
new_width = int(width * scale_w)
print(f"Resize to {new_width}x{new_height}")
return cv2.resize(cv_image, (new_width, new_height), interpolation=cv2.INTER_CUBIC)
def set_device_config(authenticator):
"""
Set device config algo to all and high confidence and security levels
After setting it, query the config and print it
"""
config = rsid_py.DeviceConfig()
config.algo_flow = rsid_py.AlgoFlow.All
config.security_level = rsid_py.SecurityLevel.High
config.matcher_confidence_level = rsid_py.MatcherConfidenceLevel.High
authenticator.set_device_config(config)
config = authenticator.query_device_config()
print('=' * 40)
print("Device config is:")
print(config)
print('=' * 40)
def extract_image_faceprints_for_enroll(filename):
im_cv = cv2.imread(filename)
im_cv = resize_to_120(im_cv)
height, width, channels = im_cv.shape
with rsid_py.FaceAuthenticator(PORT) as authenticator:
set_device_config(authenticator)
try:
features = authenticator.extract_image_faceprints_for_enroll(buffer=im_cv.flatten(), width=width,
height=height)
print(features)
except Exception as ex:
print('Failed to extract:', ex)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f"Usage: python {sys.argv[0]} <image-filename>")
sys.exit(1)
try:
extract_image_faceprints_for_enroll(filename=sys.argv[1])
except Exception as ex:
print("Error", ex)