initialize recognizers in threads instead of camera init
This commit is contained in:
parent
f4d231cca8
commit
62aabdf480
1 changed files with 47 additions and 40 deletions
|
|
@ -62,10 +62,7 @@ if not encodings:
|
||||||
# Add the time needed to start the script
|
# Add the time needed to start the script
|
||||||
timings['st'] = time.time() - timings['st']
|
timings['st'] = time.time() - timings['st']
|
||||||
|
|
||||||
video_capture = None
|
timings['ic'] = time.time()
|
||||||
|
|
||||||
def initialize_cam():
|
|
||||||
global video_capture
|
|
||||||
|
|
||||||
# Start video capture on the IR camera
|
# Start video capture on the IR camera
|
||||||
video_capture = cv2.VideoCapture(config.get("video", "device_path"))
|
video_capture = cv2.VideoCapture(config.get("video", "device_path"))
|
||||||
|
|
@ -88,9 +85,8 @@ def initialize_cam():
|
||||||
# This will let the camera adjust its light levels while we're importing for faster scanning
|
# This will let the camera adjust its light levels while we're importing for faster scanning
|
||||||
video_capture.grab()
|
video_capture.grab()
|
||||||
|
|
||||||
timings['ic'] = time.time()
|
# Note the time it took to open the camera
|
||||||
init_thread = Thread(target=initialize_cam)
|
timings['ic'] = time.time() - timings['ic']
|
||||||
init_thread.start()
|
|
||||||
|
|
||||||
timings['ll'] = time.time()
|
timings['ll'] = time.time()
|
||||||
|
|
||||||
|
|
@ -98,6 +94,9 @@ timings['ll'] = time.time()
|
||||||
import dlib
|
import dlib
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
pose_predictor = None
|
||||||
|
face_encoder = None
|
||||||
|
|
||||||
use_cnn = config.getboolean('core', 'use_cnn', fallback=False)
|
use_cnn = config.getboolean('core', 'use_cnn', fallback=False)
|
||||||
if use_cnn:
|
if use_cnn:
|
||||||
face_detector = dlib.cnn_face_detection_model_v1(
|
face_detector = dlib.cnn_face_detection_model_v1(
|
||||||
|
|
@ -106,20 +105,28 @@ if use_cnn:
|
||||||
else:
|
else:
|
||||||
face_detector = dlib.get_frontal_face_detector()
|
face_detector = dlib.get_frontal_face_detector()
|
||||||
|
|
||||||
|
def init_predictor():
|
||||||
|
global pose_predictor
|
||||||
pose_predictor = dlib.shape_predictor(
|
pose_predictor = dlib.shape_predictor(
|
||||||
PATH + '/dlib-data/shape_predictor_5_face_landmarks.dat'
|
PATH + '/dlib-data/shape_predictor_5_face_landmarks.dat'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def init_encoder():
|
||||||
|
global face_encoder
|
||||||
face_encoder = dlib.face_recognition_model_v1(
|
face_encoder = dlib.face_recognition_model_v1(
|
||||||
PATH + '/dlib-data/dlib_face_recognition_resnet_model_v1.dat'
|
PATH + '/dlib-data/dlib_face_recognition_resnet_model_v1.dat'
|
||||||
)
|
)
|
||||||
|
|
||||||
timings['ll'] = time.time() - timings['ll']
|
|
||||||
|
|
||||||
# wait for camera initialization to finish
|
init_thread1 = Thread(target=init_encoder)
|
||||||
init_thread.join()
|
init_thread2 = Thread(target=init_predictor)
|
||||||
del init_thread
|
init_thread1.start()
|
||||||
# Note the time it took to open the camera
|
init_thread2.start()
|
||||||
timings['ic'] = time.time() - timings['ic']
|
|
||||||
|
init_thread2.join()
|
||||||
|
init_thread1.join()
|
||||||
|
del init_thread1, init_thread2
|
||||||
|
timings['ll'] = time.time() - timings['ll']
|
||||||
|
|
||||||
# Fetch the max frame height
|
# Fetch the max frame height
|
||||||
max_height = config.getfloat("video", "max_height", fallback=0.0)
|
max_height = config.getfloat("video", "max_height", fallback=0.0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue