https://github.com/kylemcdonald/FaceTracker
https://github.com/qaz734913414/MNN_FaceTrack
这是一个移动端快速视频多人脸跟踪的开源项目,这个项目是基于mtcnn人脸检测加上最简单的模板匹配进行人脸跟踪的,算法简单但效果显著,移动端速度可以达到250帧以上,该项目的特点是可实现多人脸跟踪。
速度挺快,但是很容易跟丢。
代码算法解析
HyperFT项目的多人脸跟踪算法分三大部分:
第一部分是初始化,通过mtcnn的人脸检测找出第一帧的人脸位置然后将其结果对人脸跟踪进行初始化;
第二部分是更新,利用模板匹配进行人脸目标位置的初步预判,再结合mtcnn中的onet来对人脸位置进行更加精细的定位,最后通过mtcnn中的rnet的置信度来判断跟踪是否为人脸,防止当有手从面前慢慢挥过去的话,框会跟着手走而无法跟踪到真正的人脸;
第三部分是定时检测,通过在更新的部分中加入一个定时器来做定时人脸检测,从而判断中途是否有新人脸的加入,本项目在定时人脸检测中使用了一个trick就是将已跟踪的人脸所在位置利用蒙版遮蔽起来,避免了人脸检测的重复检测,减少其计算量,从而提高了检测速度。
这个也可以试试:需要自己安装ncnn
https://blog.csdn.net/renhanchi/article/details/85089265
https://github.com/HandsomeHans/Face-Tracking-Based-on-OpenTLD-and-RNet
python panda
https://github.com/Linzaer/Face-Track-Detect-Extract
改完可以运行,检测不到就会跟丢,偶尔也会跟丢
原来匈牙利指派算法:
def associate_detections_to_trackers(detections, trackers, iou_threshold=0.25):
"""
Assigns detections to tracked object (both represented as bounding boxes)
Returns 3 lists of matches, unmatched_detections and unmatched_trackers
"""
if len(trackers) == 0:
return np.empty((0, 2), dtype=int), np.arange(len(detections)), np.empty((0, 5), dtype=int)
iou_matrix = np.zeros((len(detections), len(trackers)), dtype=np.float32)
for d, det in enumerate(detections):
for t, trk in enumerate(trackers):
iou_matrix[d, t] = iou(det, trk)
'''The linear assignment module tries to minimise the total assignment cost.
In our case we pass -iou_matrix as we want to maximise the total IOU between track predictions and the frame detection.'''
matched_indices = linear_assignment(-iou_matrix)
unmatched_detections = []
for d, det in enumerate(detections):
if d not in matched_indices[:, 0]:
unmatched_detections.append(d)
unmatched_trackers = []
for t, trk in enumerate(trackers):
if t not in matched_indices[:, 1]:
unmatched_trackers.append(t)
# filter out matched with low IOU
matches = []
for m in matched_indices:
if iou_matrix[m[0], m[1]] < iou_threshold:
unmatched_detections.append(m[0])
unmatched_trackers.append(m[1])
else:
matches.append(m.reshape(1, 2))
if len(matches) == 0:
matches = np.empty((0, 2), dtype=int)
else:
matches = np.concatenate(matches, axis=0)
return matches, np.array(unmatched_detections), np.array(unmatched_trackers)
一般情况挺好的,KalmanFilter 滤波
效果可能不好