-
Notifications
You must be signed in to change notification settings - Fork 0
/
recognition.py
45 lines (39 loc) · 1.83 KB
/
recognition.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
from PyQt5.QtCore import QThread
from PyQt5.QtCore import pyqtSignal
from datetime import datetime
from jetsonface import FaceStatus
from loguru import logger
class FaceRecognitionThread(QThread):
face_recognition_signal = pyqtSignal(dict)
def __init__(self, face_obj):
super(FaceRecognitionThread, self).__init__()
self._face_obj = face_obj
self._frame = None
self._face = None
self._threshold = 6.0
def init_param(self, frame, face, threshold):
self._frame = frame
self._face = face
self._threshold = threshold
def run(self):
box = [self._face.x, self._face.y, self._face.width, self._face.height]
points = self._face_obj.face_marker(self._frame, box)
point_py = [[point.x, point.y] for point in points]
# 人脸活体检测
status = self._face_obj.face_anti_spoofing(self._frame, box, point_py)
# status = 0
if status != FaceStatus.REAL:
logger.critical("可能的攻击人脸")
self.face_recognition_signal.emit(
{'code': -1, "time": datetime.now().time().strftime("%H:%M:%S"), "message": "攻击人脸"})
else:
# 人脸识别
ret = self._face_obj.face_recognition(self._frame, point_py)
if ret.confidence < self._threshold:
self.face_recognition_signal.emit(
{"code": 0, "time": datetime.now().time().strftime("%H:%M:%S"), "message": "未知人脸"})
logger.warning(f"未知人脸,confidence:{ret.confidence:.2f}")
else:
logger.info(f"打卡成功--name:【{ret.face_info}】--score:【{ret.confidence:.2f}】")
self.face_recognition_signal.emit(
{"code": 1, "time": datetime.now().time().strftime("%H:%M:%S"), "message": ret})