Updated on December 20, 2018
-
Removed all content that does not affect tracking performance, including time-consuming initialization operations.
-
Added support for opencv3.
-
Now, tracking only takes about 3ms on my PC.
-
Deleted the init function, so the detNumToTack parameter is also useless and has been removed.
Introduction#
The built-in tracking algorithm in OpenCV is not very effective, so I found an open-source optical flow tracking algorithm on GitHub, which performs much better. Based on this algorithm, I further removed unnecessary content and adjusted some parameters to improve the algorithm's speed without affecting its effectiveness. On my PC (Intel® Xeon(R) CPU E5-2673 v3 @ 2.40GHz × 48), it takes 16ms (MTCNN, ncnn) for a 320*240 image, 30ms for initialization, and 10ms for optical flow tracking.
This algorithm has the following advantages:
-
It can track faces stably without excessive bounding box shaking. I have optimized the flashing bounding box issue in the examples folder on GitHub, so it will no longer occur.
-
It achieves fast face tracking without relying on deep learning.
-
It has no other dependencies and only uses ncnn and OpenCV (
required version: 2.4.x).
Main Content#
Let's discuss some logical matters in the void Impl::Detect()
function.
1. Regarding the significance of the detNumToTack
parameter: When there are objects repeatedly obstructing the face or in certain situations where the presence of a face is intermittent, without the detNumToTack
parameter, the algorithm would perform detection immediately after initialization. I think this is a waste of time, so I added the detNumToTack
parameter. After performing detection detNumToTack
times, it initializes and then starts tracking.
-
The purpose of RNet is to evaluate the results of each tracking and perform re-detection when the result is below a threshold. This is done to prevent tracking of other objects. Initially, without RNet, if a hand slowly moves in front of the face, the bounding box would follow the hand.
-
I have fixed the width and height of the tracking box to achieve stable results. After running the
processFrame
tracking function, the bounding box is reset to its initial width and height. -
The face detection part can be replaced as desired, and the RNet part can also be replaced with the PCN-2 network.
GitHub link: https://github.com/HansRen1024/Face-Tracking-Using-Optical-Flow-and-CNN