src package¶
Submodules¶
src.face_detection module¶
-
class
src.face_detection.
FaceDetectionCvCas
[源代码]¶ 基类:
src.face_detection.FaceDetection
-
cascade_xml
= '/home/docs/checkouts/readthedocs.org/user_builds/face-detection-trace/checkouts/latest/model/haarcascade_frontalface_default.xml'¶
-
detection
(frame)[源代码]¶ 图片中所有的人脸矩形框坐标
参数: frame – 图片,h,w,s三维数组格式 返回: List[tuple],每个tuple都是(int,int,int,int)形式的opencv的矩形坐标
-
face_detector
= <CascadeClassifier 0x7fa51ba45470>¶
-
-
class
src.face_detection.
FaceDetectionDlibFro
[源代码]¶ 基类:
src.face_detection.FaceDetection
-
detection
(frame)[源代码]¶ 图片中所有的人脸矩形框坐标
参数: frame – 图片,h,w,s三维数组格式 返回: List[tuple],每个tuple都是(int,int,int,int)形式的opencv的矩形坐标
-
static
dlib_box_to_cv
(rectangle: Tuple[int, int, int, int]) → Tuple[int, int, int, int][源代码]¶ 坐标系转换
将dlib的rectangle坐标转为opencv坐标系坐标
参数: rectangle – dlib的rectangle坐标 :return:opencv中的坐标系
-
face_detector
= <_dlib_pybind11.fhog_object_detector object>¶
-
-
class
src.face_detection.
FaceDetectionFactory
[源代码]¶ 基类:
object
face detection 的工厂类
-
face_detection_construct
= {'CV_CAS': <class 'src.face_detection.FaceDetectionCvCas'>, 'DLIB_FRO': <class 'src.face_detection.FaceDetectionDlibFro'>, 'FR_FL': <class 'src.face_detection.FaceDetectionFrFoc'>}¶
-
-
class
src.face_detection.
FaceDetectionFrFoc
[源代码]¶
src.face_detection_trace module¶
-
class
src.face_detection_trace.
CapDetectionTrack
(ipc_info, is_realtime, face_detector, face_encoding, detection_freq, persons, face_decector_lock, face_encoding_lock)[源代码]¶ 基类:
threading.Thread
检测追踪类
集成人脸检测和追踪
变量: - is_start (bool) – 是否已经开启
- face_detector (object) – 人脸检测器
- face_encoding (object) – 人脸编码器
- __last_frame (object) – 视频流的最新帧
- frame_queue (queue) – 视频流的视频帧队列
- is_realtime (bool) – 是否是实时模式
- tracks (list) – 追踪器列表,一个视频会出现多个人,自然也有多个追踪器
- ipc_info (list) – 视频源配置信息
- persons (list) – 已保存的人员和对应的人脸信息
-
static
event_call_back
(type, ipc_name, track_id, img=None, box=None, person_name=None)[源代码]¶ 追踪的人消失后的回调函数
参数: - type – 事件类型
- ipc_name – 摄像头名称
- track_id – 追踪器id
- img – 图片帧
- box – 图片帧中的人脸位置
- person_name – 人名
-
is_save_stranger
¶
-
name
¶ A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.
-
path
¶
-
video_imgs
= None¶
-
class
src.face_detection_trace.
DetectionTracksCtl
(face_detector, face_encoding)[源代码]¶ 基类:
object
人脸检测,识别控制器
变量: - face_detector (object) – 人脸识别器
- face_encoding (object) – 人脸编码器
-
class
src.face_detection_trace.
Person
(person_name, img_files, ipc_name, is_new=False, new_face_frame_max=10)[源代码]¶ 基类:
object
人员,可能是员工或者陌生人
变量: - ipc_name (str) – 摄像头名称
- is_new (bool) – 是否是新人
- person_name (str) – 人员姓名
- frames_box_limit (list) – 如果是新人,建立list,保存新人头像
- __encodings (List) – frames_box_limit里头像对应的头像特征码信息
-
face_encoding
= None¶
-
static
get_camera_person_files
(cameras_dir)[源代码]¶ 加载某个摄像头下某人的所有头像图片信息
参数: cameras_dir – 图片目录 返回: dict,key:camera_name,摄像头名称,value:dict02,dict02:key:person_name,姓名,value:img_list,此人对应头像列表
-
img_dir
= ''¶
-
class
src.face_detection_trace.
Track
(ipc_name, tracker, img, box, encoding, persons, event_call_back, history=5)[源代码]¶ 基类:
object
跟踪器
内部包含了opencv追踪器,或者说对opencv追踪器的二次封装
变量: - ipc_name (str) – 摄像头名称
- __id (int) – 跟踪器id
- tracker (object) – 跟踪器,opencv追踪器实例
- face_img (list) – 图片里的头像小图信息
- img (list) – 图片
- encoding (list) – 人脸头像对应特征码
- __history (list) – 临近的各帧是否包含此人
- match_person (object) – 跟踪器匹配的人
- event_call_back (callable) – 追踪的人消失之后的回调函数,比如生成事件日志
-
find_person
(persons, tolerance=0.6)[源代码]¶ 从入参的persons中匹配track追踪器追踪的人(将track和person关联起来)
:param persons:所有人员列表 :param tolerance:人员匹配阈值,如果人员距离小于此阈值则认为是同一个人 :return:
-
id
¶
src.face_encoding module¶
-
class
src.face_encoding.
FaceEncoding
[源代码]¶ 基类:
object
人脸特征值提取face encoding抽象类
-
class
src.face_encoding.
FaceEncodingDlibReg
[源代码]¶ 基类:
src.face_encoding.FaceEncoding
-
static
encoding_frame_box
(frame_box)[源代码]¶ 获取frame_box中头像和对应box位置的特征码
参数: frame_box – frame_box,包含了图片和box信息
-
face_detector
= <_dlib_pybind11.fhog_object_detector object>¶
-
face_encoding
= <_dlib_pybind11.face_recognition_model_v1 object>¶
-
shape
= <_dlib_pybind11.shape_predictor object>¶
-
static
-
class
src.face_encoding.
FaceEncodingFactory
[源代码]¶ 基类:
object
face encoding 的工厂类
-
face_encoding_construct
= {'DLIB_REG': <class 'src.face_encoding.FaceEncodingDlibReg'>, 'FR_FE': <class 'src.face_encoding.FaceEncodingFrFe'>}¶
-
-
class
src.face_encoding.
FaceEncodingFrFe
[源代码]¶
src.util module¶
-
class
src.util.
FrameBox
(img=None, box=None)[源代码]¶ 基类:
object
自定义对象,包含图片帧和头像位置信息
变量: - img (list) – 图片,hws三维数组格式
- box (tuple) – 头像位置,长度为4的list
-
name
¶ 使用box的头像坐标生成图片文件名称
返回: 图片文件名称
-
class
src.util.
Util
[源代码]¶ 基类:
object
工具类
主要包括坐标系转换,画框,图片特定区域切割,以及文件夹遍历等工具类
坐标系转换:由于调用了不同的工具包,不同包的坐标标识方法是不同的,为了保持内部变量含义统一性,程序内部均采用opencv坐标系
-
static
cut_frame_box
(frame, box: Tuple[int, int, int, int])[源代码]¶ 从图片中截取出矩形区域
参数: - frame – 图片,h,w,s格式的3维数组
- box – 矩形框
返回: 矩形框内的图片,h,w,s格式的3维数组
-
static
cv_to_fl_box
(rect: Tuple[int, int, int, int]) → Tuple[int, int, int, int][源代码]¶ 坐标系转换
将opencv坐标转为face_recognition的face_locations坐标
参数: rect – opencv坐标 :return:face_recognition.face_locations中的坐标
-
static