InferenceProxy 与最大人脸策略
class InferenceProxy:
"""FaceSystem-shaped proxy used by the camera thread."""
def __init__(self, worker: NpuWorker):
self._worker = worker
def detect(self, image, threshold=0.5):
return self._worker.call("detect", image, threshold=threshold)
def get_embedding(self, face_image):
return self._worker.call("get_embedding", face_image)
def _largest_face(faces, image):
if not faces:
return image
best = max(faces, key=lambda box: (box[2] - box[0]) * (box[3] - box[1]))
x1, y1, x2, y2 = map(int, best)
height, width = image.shape[:2]
x1, y1 = max(0, x1), max(0, y1)
x2, y2 = min(width, x2), min(height, y2)
if x2 <= x1 or y2 <= y1:
return image
return image[y1:y2, x1:x2]
解释:摄像头线程通过 InferenceProxy 向硬件工作线程提交任务,不直接操作 PyACL。检测出多张人脸时选择面积最大者,是单人考勤演示的确定性简化策略。